Recent

Author Topic: Are there any current SQLite demos?  (Read 4886 times)

jbmckim

  • Full Member
  • ***
  • Posts: 144
Are there any current SQLite demos?
« on: January 30, 2018, 12:26:23 am »
After having stepped through the SQL tutorial (tsqlscriptsample), it seems to be riddled with problems.  Most immediately notable is an 'EDataBaseError' of "Unknown connector type SQLite" thrown from TForm1.ConnectionTest.  (I encountered problems with all DB types but my interest is SQLite.)

I did have a bit more success building the database manually (using sqlite3.exe) and running sqldbtutorial3 but that wound up not being able to find sqlite3.dll, no matter where it was located.  Is this a version issue?  Is there a property somewhere that needs to specify the dll location?   (See the resurrected thread https://forum.lazarus.freepascal.org/index.php/topic,19238.15.html re versioning.)

Just looking for something that will open a db, query, write and close.

Thanks.

hakuna

  • New member
  • *
  • Posts: 7
  • Taking Lazarus seriously
Re: Are there any current SQLite demos?
« Reply #1 on: January 30, 2018, 03:12:54 am »
jbmckim in what path are you putting the sqlite3.dll file? Please do the test by placing it in the root directory of your application, at the same level as the .exe file or in the C: \ Windows path.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Are there any current SQLite demos?
« Reply #2 on: January 30, 2018, 04:12:57 am »
Did you see -
http://wiki.freepascal.org/SqlDBHowto and specifically http://wiki.freepascal.org/SqlDBHowto#How_to_execute_direct_queries.2Fmake_a_table.3F

These examples worked OK when I updated that page six or seven months ago. But be warned, at that time, it was my first play with Lazarus ....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Are there any current SQLite demos?
« Reply #3 on: January 30, 2018, 08:29:07 am »
After having stepped through the SQL tutorial (tsqlscriptsample), it seems to be riddled with problems.  Most immediately notable is an 'EDataBaseError' of "Unknown connector type SQLite" thrown from TForm1.ConnectionTest.  (I encountered problems with all DB types but my interest is SQLite.)

Maybe you mixed up Sqlite with Sqlite3? These are different: the former is Sqlite 2.X and the latter is Sqlite3. FPC supports both.
Specialize a type, not a var.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Are there any current SQLite demos?
« Reply #4 on: January 30, 2018, 08:18:33 pm »
Pt 1 solved.  Win 10 OS sees the sqlite3.dll if its in SysWOW64 but not if its co-located with the .exe...Thanks Bill Gates.

dbannon - Examples you cite do work after pt. 1 above.  The app examples though seem to have major issues or the debugger is really confused.  Stepping through the code, it doesn't like the attributes of TSQLScript. Example:

Code: Pascal  [Select][+][-]
  1. var
  2.   OurScript: TSQLScript;
  3. begin
  4.   OurScript:=TSQLScript.Create(nil);
  5.   try
  6.     OurScript.Database:=FConn; //Indicate what db & ...

Inspecting OurScript.Database, the debugger says that TSQLScript does not contain a .Database attribute.  Inspecting the class as presented by the debugger (by hovering), this is true.

Sqlite vs. SQLite3.  The example uses 3:

Code: Pascal  [Select][+][-]
  1. LoginForm.ConnectorType.AddItem('SQLite3', nil);

This is the dll I've downloaded and as above, works with the other example.

I'd say that from the time this example was created, things have changed.  This is at least true for the assumed target environment (i.e. the example is no longer "plug and play").  It would also seem to be the case that there's a disconnect between the source code and the current example set, at least as pertains to SQLite(3).  There are likely also problems with Firebird although I didn't spend much time looking at FB.  Probably its time to update the example(s).

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Are there any current SQLite demos?
« Reply #5 on: January 30, 2018, 10:05:20 pm »
hello,
you can have a look to my database example (in Lazarus\examples\Database\Image_Mushrooms ) :
Quote
[MushRoomsDatabase by Jurassic Pork using SQLite - January 2014
Updated for Firebird Embedded - August 2014

Features:
- Use SqlDb and lazreport components.
- Sqlite3 or Firebird embedded database DeadlyMushrooms with 5 mushrooms.
Sqlite3 will be tried first; if no Sqlite library is available, Firebird
embedded will be tried.
- It demonstrates:
- creating a new SQLite3 database with table if the db does not exist
- use of TSQLScript to run multiple SQL statements
- use of FBAdmin to restore Firebird backup (smaller than the live .fdb file)
on first run, useful for keeping your setup file small and compatible with
older Firebird versions
- The images are stored in blob field without extension at the beginning.
With this you can view blob images with database browser editor
(e.g. sqlite2009pro).
- In the database there is also a field with images links (filenames).
- The linked images are stored in the folder images of the project.
- You can see the linked images in a Timage.
- You can change the images in the database:
- for Tdbimage (image in db): double click on the component and choose your
image.
- for Timage (linked image): click on the button near the image filename
(you must be in edit mode).
- Transaction commits when you click on Tdbnavigator refresh button or on close
form.
- Small pictures of the mushrooms are in the sqlite3Database. Largest images are
in files in the folder images.
- Print button to print all the mushrooms (lazreport).
On each page you have:
- a title.
- the field common_name of the mushroom database.
- the field notes of the mushroom database.
- the field picture of the mushroom database (picture picture1).
- the picture of the field image_link (picture picture2).

The report name is Mushroom_Report.lrf

You need to install Lazreport and sqldb packages for the example to work.  Works with Lazarus 1.8.0



Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Are there any current SQLite demos? [solved]
« Reply #6 on: January 31, 2018, 01:09:33 am »
Thanks Jurassic.  I will take a look at that as I'm in the "sandbox" stage at this point and different perspectives are appreciated.

Here's what I was able to accomplish with help from here and perspiration - remember, this applies to sqlite3

1)  Move the sqlite(x).dll file to either System32 or SysWOW64. (This eliminates most major security hang ups on Windows.)
2)  To use the tutorial http://wiki.freepascal.org/SQLdb_Tutorial0, avoid the automatic DB creation.  Manually cut and paste the entries in Tutorial 1, using a tool of your choice. I used command line sqlite3 with PowerShell to create the database.
3)  This approach was successful for me navigating through the end of Tutorial1.  I assume the subsequent tutorials will work as well.

thanks all

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: Are there any current SQLite demos?
« Reply #7 on: February 04, 2018, 04:27:58 am »
FYI:
If your Windows is 64 bit, Windows\system32 or system folder contains 64-bit library files, and SYSWOW64 32-bit libraries.
So if your  SQLite3 is 32-bit application then it must be in sysWOW64 folder, and system32 or system folder if SQLite3.dll is 64-bit library.

 

TinyPortal © 2005-2018