Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » GUID column in DB and SqlArray (how to use GUID column in database app)
GUID column in DB and SqlArray [message #46124] Sat, 12 March 2016 15:03 Go to next message
LamerDrv is currently offline  LamerDrv
Messages: 3
Registered: March 2016
Junior Member
Hi.

I try create simple one-form database app with two master-detail grids. I take SqlArray example as base.
But in my case the DBMS is MSSQL. And PK field in my master table and detail table is uniqueidentifier type (i.e. guid). And foreign key in detail table is uniqueidentifier.
I needn't show guid columns in SqlArray - I will show only human-readable fields.

As much as I understand, I can't provide guid field definition in sch-file. Is that right?
Is any benefits from use sch-file in project if that file providing non-full definition for my tables?
Need I use SqlArray.AddKey(ID) for primary key guid column?
What about SqlArray.Join?

Please, can you to provide small sample how to use master-detail SqlArrays whit db tables that contains guid columns?
Thanks.
Re: GUID column in DB and SqlArray [message #46202 is a reply to message #46124] Fri, 25 March 2016 19:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
At thid moment, uniquieidentifier is not supported. But I guess it would be easy to add to uppsrc\MSSQL\MSSQLSchema.h

It seems to behave like String for all practical purposes.... If I remember well, types not known in MSSQL are always converted to String, so it should work. You might even be able to in fact use .sch and just use STRING for GUID columns.

You do not need to "display" neither primary key nor foreign key. Just use AddKey for primary.

SqlArray.Join should work just fine.

Mirek

[Updated on: Fri, 25 March 2016 19:07]

Report message to a moderator

Re: GUID column in DB and SqlArray [message #46217 is a reply to message #46124] Sun, 27 March 2016 11:48 Go to previous messageGo to next message
LamerDrv is currently offline  LamerDrv
Messages: 3
Registered: March 2016
Junior Member
Thank you for answer.
Unfortunately, it is appears that handling with GUID, SQL on Upp exceeds my knowledge Confused

First I try direct use the COLUMN_ macros
TABLE_(Customer)
COLUMN_ ("uniqueidentifier", GUID, ID, 0, 0)
...
END_TABLE
and get
error C2664: 'Upp::FieldOperator &Upp::FieldOperator::operator ()(const char *,Upp::Ref)': cannot convert argument 2 from 'GUID' to 'bool &'
when compiling sch-file.
As far as I understanding the data types for db-fields must support Ref.
Then I try to use the Uuid type but get same error.

Then I try to make UGLY fix Smile) for make the Uuid be Ref-compatible:
struct Uuid2 : Uuid
{
	operator Ref() const {return Ref((Value)*this);}
	Uuid2& operator=(const Nuller&){SetNull(); return *this; }
};


After this the compiler passed sch-file
TABLE_(Customer)
COLUMN_ ("uniqueidentifier", Uuid2, ID, 0, 0)
...
END_TABLE

But when I call SqlArray.Query() I get error:
"[Microsoft][SQL Server Native Client 11.0]Numeric value out if range"

Eventually ... I made "simple" call
SQL.Execute("select ID from Customer");
and got same error.

This error is generated by ODBC-function SQLGetData (inside "default" branch of switch in ODBCConnection::Fetch0, ODBC.cpp):
if(!IsOk(SQLGetData(session->hstmt, i + 1, ct, &tm, 0, &li)))
  break;

It is appears, Upp can't execute select query on uniquieidentifier field.
On this point I get stuck.

[Updated on: Sun, 27 March 2016 11:56]

Report message to a moderator

Re: GUID column in DB and SqlArray [message #46219 is a reply to message #46124] Sun, 27 March 2016 14:00 Go to previous message
LamerDrv is currently offline  LamerDrv
Messages: 3
Registered: March 2016
Junior Member
I look at MS ODBC sample app (https://code.msdn.microsoft.com/ODBC-sample-191624ae)

This sample app using SQL_WCHAR datatype constant. This works (and SQL_CHAR works too) - MSSQL converts GUID to string properly. (Sample using SQLBindCol approach instead SQLGetData)

It is strange that SQLGetData(..., ..., SQL_CHAR,...) inside Upp returns error.
I think I miss something obviously.
Previous Topic: How to close a sqlite session
Next Topic: I am trying to have two sqls one to read another to write
Goto Forum:
  


Current Time: Tue Apr 16 12:57:24 CEST 2024

Total time taken to generate the page: 0.02341 seconds