Page 1 of 1

SQLite : how to read / write the int64 field?

Posted: 11.06.2007, 12:54
by starofrainnight
Hi, everybody!

I create a SQLite database like this:

CREATE TABLE [test] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[MyValue] INTEGER NULL,
[MyString] TEXT NULL
)

then, i put a TZTable (named to "tblSQLite") on a new TForm, set it to the correct database.

drop a TButton on the TForm, set it event like this:

tblSQLite.Append;
TLargeintField( tblSQLite.FieldByName('MyValue') ).Value := 9069649169573862877;
// TLargeintField( tblSQLite.FieldByName('MyValue') ).Value := 9069649169; // use a small Integer also throw exceptions
tblSQLite.Post;

but, when i run it, it told me that :
"9.06964916957386E018 is not a valid value for field 'MyValue'. The allowed range is 9.22337203470729E018 to 0."

as everyone know, sqlite treat INTEGER as int64, but why here become a DOUBLE (seem like a double)?

also, when i use the fields editor to add all fields, ID and MyValue be treat as TIntegerField,

if ID and MyValue larger than Integer, how to read and write them?


Excuse for my poor english :P

Posted: 20.06.2007, 08:00
by starofrainnight
Yeah!

I know how to do that when i traveled around the ZeosLib's sources!

I found that ZeosLib treat SQLite as a common Database and recognize all standard SQL field types!

we know, SQLite only recognize four types of fields : INTEGER(could be 64Bits), FLOAT(8-byte IEEE floating point number), TEXT(a string), BLOB(a blob of data).

But, int the ZeosLib, when you use SQLite, it will explain all standard SQL field types just like BIGINT, BOOLEAN, TIMESTAMP, etc. ZeosLib done it !

so, we must creat a database like this:

CREATE TABLE [test] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[MyValue] BIGINT NULL,
[MyString] CHAR(20) NULL // Because ZeosLib see TEXT as MEMO, so we set it to chars for store short messages.
)

then we could see that the Field [MyValue] in the Fields Editor it changed to TLargeintField !

that means that, we have better use standard SQL types to build our database ...

here has only last problem : the Primary Key seem must be INTEGER, but it is Int64, could it change to BIGINT? I will try it later, hope it runs ...

great job! ZeosLib!! :lol: