BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GUIDtoStr Function
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
server
Guest





PostPosted: Fri Jan 27, 2006 10:01 pm    Post subject: GUIDtoStr Function Reply with quote



message unavailable
Back to top
Mark Moss
Guest





PostPosted: Fri Jan 27, 2006 10:01 pm    Post subject: Re: GUIDtoStr Function Reply with quote



John

I Tried your suggestion but it did not work, so I did a little
digging and found out that even though the GUID Field is defined in MS SQL:
as a 16 byte Binary Field. It is coming thru ADO as a 16 Byte TByteField.

Any Ideas.

Mark Moss


"John Herbster" <herb-sci1_at_sbcglobal.net> wrote in message
news:43da3da6$1 (AT) newsgroups (DOT) borland.com...
Quote:
The field is defined as a Binary field of 16 bytes

Well then, I suggest that you code a readout the field's
data to a variable of type TGUID (which just happens
to be 16 bytes<g>) and use that as your parameter to
GUIDtoString.

"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote
And how would I do that ?

I am temped to say "Hire a computer programmer!",
but I take that back.

If I were doing it, I would look in Delphi IDE's Help for the
methods available for the binary field in question for a
method that can read binary data from the dataset field
into a block of memory (i.e. a TGUID variable). On
doing so I would find the "GetData" method. While looking
in the help file I would check for the parameters and
return values for the method and also for any Delphi
examples referenced.

Then I would try something like the following code.
I do not know if it will work, but the compiler error
messages and stepping it through at runtime it can be
fixed to work.

This is what I think that computer programming is all about.

Regards, JohnH

var GUID: TGUID; s: string; Field: TBinaryField;

Field := DM.DataModule.ADOQuery2.FieldByName(CustomerID);.
Assert(SizeOf(GUID) = Field .DataSize);
If Field.GetData(@GUID)
then s := GUIDtoString(GUID)
then s := 'No data available';


Back to top
John Herbster
Guest





PostPosted: Fri Jan 27, 2006 10:31 pm    Post subject: Re: GUIDtoStr Function Reply with quote



"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote
Quote:
[...] I did a little digging and found out that even though the
GUID Field is defined in MS SQL:as a 16 byte Binary Field,
It is coming thru ADO as a 16 Byte TByteField.

Mark, I think that these fields are essentially the same.
So you use TBytesField instead of TBinaryField.
What did you try and how did it not work? Rgds, JohnH
Back to top
Mark Moss
Guest





PostPosted: Fri Jan 27, 2006 10:41 pm    Post subject: Re: GUIDtoStr Function Reply with quote

Hold_Bytes :=
DM.DataModule1.ADOQuery2.FieldByName('CustomerID');

Assert(SizeOf(Hold_GUID) = Hold_Bytes.DataSize);

If Hold_Bytes.GetData(@Hold_GUID) then
Hold_Customer_CustomerID := GUIDtoString(HOLD_GUID);

[Error] EditCustomer.pas(240): Incompatible types: 'TBytesField' and
'TField'



"John Herbster" <herb-sci1_at_sbcglobal.net> wrote in message
news:43da583a (AT) newsgroups (DOT) borland.com...
Quote:

"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote
[...] I did a little digging and found out that even though the
GUID Field is defined in MS SQL:as a 16 byte Binary Field,
It is coming thru ADO as a 16 Byte TByteField.

Mark, I think that these fields are essentially the same.
So you use TBytesField instead of TBinaryField.
What did you try and how did it not work? Rgds, JohnH

Back to top
John Herbster
Guest





PostPosted: Fri Jan 27, 2006 11:55 pm    Post subject: Re: GUIDtoStr Function Reply with quote

"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote
Quote:
Hold_Bytes :=
DM.DataModule1.ADOQuery2.FieldByName('CustomerID');

Mark,
I am assuming that Hold_Bytes is of type TBytesField.
FieldByName is going to return an object with visible properties
of a TField object, even though the object being passed is a
pointer to a TBytesField object. So we need to do a "type cast"
to get to the real object so use the "as" operator:
Hold_Bytes :=
DM.DataModule1.ADOQuery2.FieldByName('CustomerID')
as TBytesField;
It will check the type and cast it so that it can be assigned to Hold_Bytes.
By the way, "Hold_Bytes" seems like a strange name for a field alias.

Let us know what happens. Rgds, JohnH

Quote:
Assert(SizeOf(Hold_GUID) = Hold_Bytes.DataSize);
If Hold_Bytes.GetData(@Hold_GUID) then
Hold_Customer_CustomerID := GUIDtoString(HOLD_GUID);

[Error] EditCustomer.pas(240): Incompatible types: 'TBytesField' and
'TField'
Back to top
Mark Moss
Guest





PostPosted: Sat Jan 28, 2006 12:13 am    Post subject: Re: GUIDtoStr Function Reply with quote

John

It Works - Thank you very very much for your help --- here is the
final code.

I will convert this code snippet to a procedure and post it back to
the forumn.

Mark Moss

{---------------------------------------------------------------------------
--------------------------------}

var
Hold_Bytes : TBytesField;
Hold_GUID : TGUID;
Hold_Customer_CustomerID : String;

begin

Hold_Bytes := DM.DataModule1.ADOQuery2.FieldByName('CustomerID');

Assert(SizeOf(Hold_GUID) = Hold_Bytes.DataSize);

If Hold_Bytes.GetData(@Hold_GUID) then
Hold_Customer_CustomerID := GUIDtoString(HOLD_GUID)
Else
Hold_Customer_CustomerID := '';

end;

{---------------------------------------------------------------------------
--------------------------------}

"John Herbster" <herb-sci1_at_sbcglobal.net> wrote in message
news:43da6be5 (AT) newsgroups (DOT) borland.com...
Quote:

"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote
Hold_Bytes :=
DM.DataModule1.ADOQuery2.FieldByName('CustomerID');

Mark,
I am assuming that Hold_Bytes is of type TBytesField.
FieldByName is going to return an object with visible properties
of a TField object, even though the object being passed is a
pointer to a TBytesField object. So we need to do a "type cast"
to get to the real object so use the "as" operator:
Hold_Bytes :=
DM.DataModule1.ADOQuery2.FieldByName('CustomerID')
as TBytesField;
It will check the type and cast it so that it can be assigned to
Hold_Bytes.
By the way, "Hold_Bytes" seems like a strange name for a field alias.

Let us know what happens. Rgds, JohnH

Assert(SizeOf(Hold_GUID) = Hold_Bytes.DataSize);
If Hold_Bytes.GetData(@Hold_GUID) then
Hold_Customer_CustomerID := GUIDtoString(HOLD_GUID);

[Error] EditCustomer.pas(240): Incompatible types: 'TBytesField' and
'TField'

Back to top
Mark Moss
Guest





PostPosted: Sat Jan 28, 2006 1:02 am    Post subject: Re: GUIDtoStr Function Reply with quote

Ladies / Gentlemen

Below is a Function that takes a 16byte TBytesField converts it to a
TGUID and converts that to the final String.

Thanks for everyones help in getting this to work.

Mark Moss


var
Hold_Bytes : TBytesField;
Hold_GUIDString : String;

begin

Hold_Bytes := DM.DataModule1.ADOQuery2.FieldByName('CustomerID') As
TBytesField;

Hold_GUIDString := FGUIDtoStr(Hold_Bytes);

end;

{---------------------------------------------------------------------------
---}
function FGUIDtoStr(b: TBytesField):String;


{---------------------------------------------------------------------------
---}

function FGUIDtoStr(b: TBytesField):String;
var
Hold_GUID : TGUID;

begin

Assert(SizeOf(Hold_GUID) = b.DataSize);

If b.GetData(@Hold_GUID) then
FGUIDtoStr := GUIDtoString(HOLD_GUID)
else
FGUIDtoStr := '';

end;

{---------------------------------------------------------------------------
---}


"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote in message
news:43d7c7c4 (AT) newsgroups (DOT) borland.com...
Quote:
Gentlemen / Ladies


I am using ADO to retrieve the Data from an MS SQL Database. I
use
the following statement to get the data

DM.DataModule.ADOQuery2.FieldByName(CustomerID).AsVariant or
AsText
or AsString, but I cannot get the GUIDtoStr function to work as the data
types do
not match TGUID.

Var
Hold_GUID : String;

begin
GUIDtoStr(
DM.DataModule.ADOQuery2.FieldByName(CustomerID) );
end;

How should I get this data?


Mark Moss

Back to top
Riki Wiki
Guest





PostPosted: Sat Jan 28, 2006 4:45 pm    Post subject: Re: TOracleDataset advanced question Reply with quote

On 25 Jan 2006 12:01:40 -0800, Guy wrote:

Quote:
Any ideas of other options would be appreciated.

Hoi Guy

You need to repost your question on the Borland news server, because the
way you have posted now, it is invisibel to most people.

Take a look here:
<http://tinyurl.com/8m5nw>
which links to
<http://delphi.wikicities.com/wiki/Delphi_Newsgroups>
Back to top
Arthur Hoornweg
Guest





PostPosted: Sat Jan 28, 2006 7:16 pm    Post subject: Re: Upgrading a D7 ADO project to D2006 benefit in anyway? Reply with quote

Sarah wrote:

Quote:
I looked at the TBetterADO help file and it appears it fixes a lot of
bugs in the Delphi ADO components up to Delphi 7.

Beware: there is a bug in tBetterado that only occurs under D2006
and widestring fields (it causes a gpf).





--
Arthur Hoornweg

(In order to reply per e-mail, please just remove the ".net"
from my e-mail address. Leave the rest of the address intact
including the "antispam" part. I had to take this measure to
counteract unsollicited mail.)
Back to top
Arthur Hoornweg
Guest





PostPosted: Sat Jan 28, 2006 7:17 pm    Post subject: Re: Upgrading a D7 ADO project to D2006 benefit in anyway? Reply with quote

Sarah wrote:

Quote:
Also the SQLNCLI is backward compatible with SQL Server 7 and above.

Doesn't it require .NET 2.0?



--
Arthur Hoornweg

(In order to reply per e-mail, please just remove the ".net"
from my e-mail address. Leave the rest of the address intact
including the "antispam" part. I had to take this measure to
counteract unsollicited mail.)
Back to top
Man Utd
Guest





PostPosted: Sun Jan 29, 2006 6:12 pm    Post subject: Re: Primary key Reply with quote

How long the GUID is if represented as string?
Does it include the '{', '}', and the '-' ?

"Martijn Tonies" <m.tonies (AT) upscene (DOT) removethis.com> wrote in message
news:43d5df66$1 (AT) newsgroups (DOT) borland.com...
Quote:

Oops, I just noticed Firebird only have BIGINT that is 64 bit integer.
If I store the GUID as string, does it affect any sorting or searching ?
Since I will use this GUID as primary key, there will quite frequent in
JOIN
and in WHERE clause.

Yes, this affects Firebird quite a lot.

Because of the index structure in Firebird, GUIDs are rather
slowish. This might have improved in Firebird 2.0 due to the
new index structure - feel free to ask about this in the Firebird
mailinglist at Yahoogroups (see the Firebird website).

Either way, there is a set of external functions available for
Firebird that allows you to create reversed GUIDs, which
are just as unique, but can be used faster by the database
engine itself due to the index structure.

Scroll down to the bottom of this page for a link:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_udf_libs


--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL
Server
Upscene Productions
http://www.upscene.com
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

Back to top
Bill Todd
Guest





PostPosted: Sun Jan 29, 2006 7:26 pm    Post subject: Re: Primary key Reply with quote

Man Utd wrote:

Quote:
How long the GUID is if represented as string?
Does it include the '{', '}', and the '-' ?

Open the Delphi IDE, go into a file in the editor, press Ctrl+Shift+G
and count. :)

--
Bill Todd (TeamB)
Back to top
Guy
Guest





PostPosted: Sun Jan 29, 2006 7:42 pm    Post subject: Re: TOracleDataset advanced question Reply with quote

Ok Thanks. I posted it thru google new groups interface?
Back to top
Jojo
Guest





PostPosted: Mon Jan 30, 2006 7:57 am    Post subject: Re: GUIDtoStr Function Reply with quote

you may try this

TGuidField(ADOQuery1.FieldByName('CustomerID')).AsGuid

Jojo

"Mike Shkolnik" <mshkolnik2002 (AT) ukr (DOT) net> wrote in message
news:43d7f86b (AT) newsgroups (DOT) borland.com...
Quote:
If your field have the ftGUID type, you may use the .AsGUID:

GUIDtoStr( DM.DataModule.ADOQuery2.FieldByName(CustomerID).AsGUID);

--
With best regards, Mike Shkolnik
E-mail: mshkolnik (AT) scalabium (DOT) com
WEB: http://www.scalabium.com

"Mark Moss" <markmoss (AT) adelphia (DOT) net> wrote in message
news:43d7c7c4 (AT) newsgroups (DOT) borland.com...
Gentlemen / Ladies


I am using ADO to retrieve the Data from an MS SQL Database. I
use
the following statement to get the data

DM.DataModule.ADOQuery2.FieldByName(CustomerID).AsVariant or
AsText
or AsString, but I cannot get the GUIDtoStr function to work as the data
types do
not match TGUID.

Var
Hold_GUID : String;

begin
GUIDtoStr(
DM.DataModule.ADOQuery2.FieldByName(CustomerID) );
end;

How should I get this data?


Mark Moss



Back to top
Arthur Hoornweg
Guest





PostPosted: Mon Jan 30, 2006 3:06 pm    Post subject: Re: Primary key Reply with quote

Man Utd wrote:
Quote:
Oops, I just noticed Firebird only have BIGINT that is 64 bit integer.
If I store the GUID as string, does it affect any sorting or searching ?


Store it as CHAR(3Cool, make sure it has a proper index.


Function NewGuid:String;
VAR g:tguid;
begin
Createguid(g);
result:=GuidToString (G);
end;







--
Arthur Hoornweg

(In order to reply per e-mail, please just remove the ".net"
from my e-mail address. Leave the rest of the address intact
including the "antispam" part. I had to take this measure to
counteract unsollicited mail.)
Back to top
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
 


Powered by phpBB © 2001, 2006 phpBB Group
.