Forums


Aducom Software :: Forums :: Delphi SQLite Version 2.8.x Components :: Questions
 
<< Voorgaande discussie | Volgende discussie >>
sample application
Ga naar pagina  [1] 2 3 4
Moderators: aducom, aducomadmin2
Auteur Bericht
TartaroZ
di mrt 09 2004, 02:33
Geregistreerde deelnemer #22
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);

db.DriverDLL := 'Q:tempsqlite.dll';
db.Database := 'Q:tempdbF';
tab.Connection := db;
q.Connection := db;

db.Open;
db.LoadLibs;

with tab do begin
Active := false;
tablename := 'F';

with FieldDefs do begin
Clear;
Add('ID', ftAutoInc, 0, false);
Add('Directory', ftString, 255, false);
Add('Filename', ftString, 255, false);
end;

// CreateTable;

end;

[...]

thanks for your help,

phil
Terug omhoog
aducom
di mrt 09 2004, 03:11

Geregistreerde deelnemer #1
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.

insert:

MyTable.Append;
MyTable.FieldByName('myfield').AsString := 'somevalue';
MyTable.FieldByName('myintegerfield').AsInteger := 12;
MyTable.Post;

update
MyTable.Edit;
MyTable.FieldByName('myfield').AsString := 'somevalue';
MyTable.FieldByName('myintegerfield').AsInteger := 12;
MyTable.Post;

delete
MyTable.Delete;

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);

db.DriverDLL := 'Q:tempsqlite.dll';
db.Database := 'Q:tempdbF';
q.Connection := db;

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.

Albert

albert
Terug omhoog
TartaroZ
di mrt 09 2004, 03:35
Geregistreerde deelnemer #22
Geregistreerd: di mrt 09 2004, 01:51
berichten: 29
thank you very very much for the fast answer.
if i have problems again, i will use this forum to contact you again.

greetings from heidelberg, germany

ps: did you write a documentation? our am i just to stupid to find it?
Terug omhoog
aducom
di mrt 09 2004, 04:10

Geregistreerde deelnemer #1
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

Albert

albert
Terug omhoog
TartaroZ
di mrt 09 2004, 05:08
Geregistreerde deelnemer #22
Geregistreerd: di mrt 09 2004, 01:51
berichten: 29
so i'm back again only about two hours later.

i suceeded to create a table and to insert some entries:

with q do begin
Close;
sql.Clear;

sql.Add('CREATE TABLE F (');
sql.Add(' "ID" INT,');
sql.Add(' "Directory" TEXT,');
sql.Add(' "Filename" TEXT');
sql.Add(');');

ExecSQL;
end;

[..]

with q do begin
Close;
sql.Clear;

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.

Phil
Terug omhoog
aducom
wo mrt 10 2004, 05:01

Geregistreerde deelnemer #1
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.

Albert

albert
Terug omhoog
aducom
wo mrt 10 2004, 01:03

Geregistreerde deelnemer #1
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.

Albert

albert
Terug omhoog
TartaroZ
do mrt 11 2004, 12:13
Geregistreerde deelnemer #22
Geregistreerd: di mrt 09 2004, 01:51
berichten: 29
i tried your corrected app, but the same error raises. it's a pity. i want to use the components, but it doesn't work
Terug omhoog
aducom
do mrt 11 2004, 03:08

Geregistreerde deelnemer #1
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.

Albert

albert
Terug omhoog
TartaroZ
do mrt 11 2004, 03:18
Geregistreerde deelnemer #22
Geregistreerd: di mrt 09 2004, 01:51
berichten: 29
yeah! 1.2.b works you are great! thank you!

edit: it worked, now the same error appears. And i know that it has something to do with the params. i don't know why, but it is so...
Terug omhoog
Ga naar pagina  [1] 2 3 4  

Ga naar:     Terug omhoog

Publiceer deze discussie: RSS 0.92 Publiceer deze discussie: RSS 2.0 Publiceer deze discussie: RDF
Powered by e107 Forum System