Recent

Author Topic: SQLite and Lazarus  (Read 4885 times)

BertHart

  • Newbie
  • Posts: 3
SQLite and Lazarus
« on: October 16, 2017, 08:23:07 pm »
Hi, I am new to this forum. I am trying to replace an old Access application with Lazarus and SQLite. Using the tutorials and browsing this forum I have made some progress.  Looking for a replacement for the DLookUp function I found this topic: http://forum.lazarus.freepascal.org/index.php/topic,27940.msg173442.html#msg173442
Unfortunately I get some errors I can't seem to solve.
In the lines 120 - 123
    mySQl.DataBase        := Database;
    transaction.database  := Database;
    mySQL.transaction     := Transaction;
    mySql.text            := Format('SELECT %s FROM %s WHERE %s = :veldwaarde',[veld,tabel,Lookupveld]);

The following errors are found:
Compile Project, Target: project1.exe: Exit code 1, Errors: 3
unit1.pas(120,38) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TDataBase"
unit1.pas(121,38) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TDataBase"
unit1.pas(123,11) Error: identifier idents no member "text"

I am using Lazarus 1.6.4 and SQLite3

I hope someone can help me to understand these error messages and suggest how to solve them.

Bert

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: SQLite and Lazarus
« Reply #1 on: October 16, 2017, 08:41:01 pm »
Hello BertHart,
Welcome to the forum.

Database programming is not my area of expertise. But I found a good video tutorial, which I think may be useful:
https://www.youtube.com/watch?v=pq2oCiJePHo

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: SQLite and Lazarus
« Reply #2 on: October 17, 2017, 02:30:32 am »
Hi, I am new to this forum. I am trying to replace an old Access application with Lazarus and SQLite. Using the tutorials and browsing this forum I have made some progress.  Looking for a replacement for the DLookUp function I found this topic: http://forum.lazarus.freepascal.org/index.php/topic,27940.msg173442.html#msg173442
Unfortunately I get some errors I can't seem to solve.
In the lines 120 - 123
    mySQl.DataBase        := Database;
    transaction.database  := Database;
    mySQL.transaction     := Transaction;
    mySql.text            := Format('SELECT %s FROM %s WHERE %s = :veldwaarde',[veld,tabel,Lookupveld]);

The following errors are found:
Compile Project, Target: project1.exe: Exit code 1, Errors: 3
unit1.pas(120,38) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TDataBase"
unit1.pas(121,38) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TDataBase"
unit1.pas(123,11) Error: identifier idents no member "text"

I am using Lazarus 1.6.4 and SQLite3

I hope someone can help me to understand these error messages and suggest how to solve them.

Bert
what is mysql? what is its data type? the information you porvide is very limited. In this case I would say that you have declared a string variable named database that the compiler finds instead of the connection object to the server. You have to share more info if you want us to find a work around for you.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BertHart

  • Newbie
  • Posts: 3
Re: SQLite and Lazarus
« Reply #3 on: October 17, 2017, 01:47:12 pm »
Thanks for your suggestion, I had seen the youtube tutorial.

The code mentioned came from the post I mentioned. Since that was marked as Solved I assumed it was a working example. My Lazarus experience is very limited so I copied the code from the example in the hope it would solve my knowledge gap.

What I need is a function that allows me to use data from the next or previous record in my table. The Access function "DLookUp" does that, but I could not find a similar function in Lazarus. See the subject mentioned in my original post.

http://forum.lazarus.freepascal.org/index.php/topic,27940.msg173442.html#msg173442

Bert

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: SQLite and Lazarus
« Reply #4 on: October 17, 2017, 02:02:40 pm »
As you can see in the mentioned topic you need to fill TSQLQuery.Database with a database-component.
Code: Pascal  [Select][+][-]
  1. mySQl.DataBase:=Form_RefereeMain.SQLite3Connection_RefereeDB;
Database can't be a string (which you are using now). It needs to be a connection-component from the SQLdb-tab. Which component you choose depends on the database you are using. If you want to connect to a Interbase/Firebird database, you use TIBConnection. If you want to connect to a SQLite database you choose TSQLite3Connection. etc. etc.

Once you setup that connection (setting the TConnection.Databasename to point to the DB-file or connection-string) you can use the name of that component to put into TSQLQuery.Database (as is done in the line above).

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: SQLite and Lazarus
« Reply #5 on: October 17, 2017, 02:06:33 pm »
@BertHart

... Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TDataBase"

Did you get that error on this line below?
Code: Pascal  [Select][+][-]
  1. mySQl.DataBase        := Database;

If yes, then I guess I know why. If not, simply ignore all my post below.

That "mySQl" variable need to linked with a TDatabase or TDatabase's descendant. In your case it should be SQLite3Connection.

Please see the attached picture below. You first need to find those 2 components. Can you find it? They are under SQLdb tab.

BertHart

  • Newbie
  • Posts: 3
Re: SQLite and Lazarus
« Reply #6 on: October 17, 2017, 03:12:11 pm »
Many thanks for your suggestions. I'll try to apply them and in the mean time try to understand more about Lazarus.

 

TinyPortal © 2005-2018