Geregistreerd: di mrt 09 2004, 01:51 berichten: 29
hi,
I just downloaded your components and tried them but I don't bring them to work in my application. Can you just give me an example program how to create tables, how to insert/select/update/delete entries.
here is a part of the code I tried. the function CreateTable() doesn't exist.
procedure TForm1.Button1Click(Sender: TObject); var db: TASQLiteDB; tab: TASQLiteTable; q: TASQLiteQuery; begin db := TASQLiteDB.Create(nil); tab := TASQLiteTable.Create(nil); q := TASQLiteQuery.Create(nil);
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
The best way is to put the components on a form and link them correctly. You can create dynamically, but don't forget to add the database component to the query or table.
To create tables; best way is to use a TASQLiteQuery component. You can apply sql to create tables:
create table mytable( field fieldtype, field fieldtype etc. , primary key (myprimarykey1, myprimarykey2)
Will be something like this:
with ASQliteQuery1 do begin close; sql.clear; sql.add('create table ..... you fill in'); sql.add(' more lines if necessary'); execsql; end;
To insert records you have to choose: use the Query component; Use the Query component with the updatesql if you want to work with live queries(there is a sample in the download). More easy is to use the tasqlitetable component. You can use the standard Delphi methods of TTable.
With Query component: with ASQliteQuery1 do begin close; sql.clear; sql.add('insert into mytable ('myfield') values (:m)'); sql.add(' more lines if necessary'); Params.AsString := myfield; execsql; end;
to work through a result set
With Query component: with ASQliteQuery1 do begin close; sql.clear; sql.add('select * from mytable where myarg=:m'); sql.add(' more lines if necessary'); Params.AsString := myarg; open; while not eof do begin MyField := FieldBYName('MyField').AsString; next; end;
All is very basically. Don't load the driver yourself, it is automatically loaded and unloaded. Not all functionality is derived from the Delphi component so far. As far as I see it, you use the hard way to create tables. I suggest to use the sql way, this will work on all database drivers and you will be more easily be able to port if necessary.
procedure TForm1.Button1Click(Sender: TObject); var db: TASQLiteDB; q: TASQLiteQuery; begin db := TASQLiteDB.Create(nil); q := TASQLiteQuery.Create(nil);
with q do begin close; sql.clear; sql.add('create table x (id index primary key, directory text, filename text)'; execsql; end;
About the autoincrement, look into the sqlite documentation on link. It works differently than you expect. If you use the ttable component, set the autoinc property to true.
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
Hi,
There is no specific documentation so far. This is partly due to the fact that things are published on this website (see main page for description of properties and methods), second that it is a source distribution with a lot of comment in it; that it is a look-alike to the standard delphi components (although not all features are fully implemented yet) and last but not least, we simply did not have had the time to do so, but will in the near future. In fact there is an example comming up showing all features and it will be a sqlite explorer (a look-alike of the delphi sql explorer). For now, we are concentrating on the stability program, and porting it to other delphi releases (including Kylix if possible). To look at the amount of downloads (not registrations unfortunately) it seems that things are comming together
sql.Add('INSERT INTO F (ID, Directory, Filename) VALUES (:ID, :Directory, :Filename);'); Params.ParamByName('ID').AsInteger := Strtoint(Edit1.Text); Params.ParamByName('Directory').AsString := Edit2.Text; Params.ParamByName('Filename').AsString := Edit3.Text;
ExecSQL; end;
But when i want to select some things, an error message appears when i call q.Open() - see following:
db.Open;
with q do begin Close; sql.Clear;
sql.Add('SELECT * FROM F'); showmessage(sql.Text); q.Open; end;
And - yes, the database and the table exist
The Error that appears is one of the type EListError (List index is higher than max (0)" (bad tranlation from german message). Delphi points to the ASGSQLite.pas in the function TASQLiteDB.SQLite_XExec(..) in the third line (SQLite_XExec := SQLite_Exec...).
I use D7Ent + ASQLite version 1.2 A
Debug says nothing like
2004 Mrz 09 (23:54:15) PRAGMA show_datatypes = ON 2004 Mrz 09 (23:54:15) PRAGMA empty_result_callbacks = ON; 2004 Mrz 09 (23:54:15) SELECT *, rowid FROM F
2004 Mrz 09 (23:55:47) PRAGMA show_datatypes = ON 2004 Mrz 09 (23:55:47) PRAGMA empty_result_callbacks = ON; 2004 Mrz 09 (23:55:47) SELECT * FROM F
Did i make a mistake? I hope so Thanks for every help.
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
So far I don't see anything wrong. Except I always use Params.AsSomeType in stead of param by name. You could try it this way, but yours should work too. If you demo app is not so big, please zip the stuff and mail it to email (don't forget the database, but exclude exe's otherwize your mail will be 'dumped' unseen). I'll take a look.
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
Hi,
I've watched your application and it did not give the errors you mention. However, the sample doesn't work. I have modified it by using the normal Delphi interface using first, next and last. It works well now.
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
Do you mean the unchanged code we sent you? This works here. If it doesn't with you then try to update the source of the sqlite components, try even the beta one and upgrade to the newest sqlite dll. If it still doesn't work I realy wouldn't know why it doesn't work. You have D6? Try this. Problems of this kind with the real 'basics' of the component have never been reported here. Do you have a correct Delphi version? The components will not work on a standard edition. Last option is to debug yourself, this is no rocket science. Stepping through the code should reveil the problem.