ThomasMertes / seed7

Source code of Seed7
GNU General Public License v2.0
207 stars 11 forks source link

Problem opening a SQLite database #22

Closed celtic-coder closed 8 months ago

celtic-coder commented 9 months ago

Hi Thomas (@ThomasMertes),

I have created a simple SQLite database file with a single empty table. I am using s7 C:\seed7\prg\db7.sd7 to open the database file in Database Inspector 7. This opens my Firefox browser to the local web server on http://localhost:1080/ which then displays the following:

Db7-open-SQLite-database

When I click the Login button, the following appears on the screen:

Database-error-SQLite3-dll

Further, when I run the SQL command line tool in the folder containing the database, a similar error appears:

s7 C:\seed7\prg\sql7.sd7 SQLite Rosetta-Code.db '' ''

Error-opening-database-cmd-line

Command line output:

~~~ SEED7 INTERPRETER Version 5.2.10 Copyright (c) 1990-2023 Thomas Mertes Sql7 - Sql command line tool Copyright (C) 2014 Thomas Mertes This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Sql7 is written in the Seed7 programming language Homepage: http://seed7.sourceforge.net *** Database error: Searching dynamic libraries failed: sqlite3.dll ~~~

Might I be doing something incorrect with using either one of these two utility programs?

In my comment on Speeding up the Windows installation (Issue 16), I copied the log output for the seed7_05_20230709_win.exe installation. Part of the database portion of that installation log is as follows:

Using Windows libraries
MySql/MariaDb: db_my.h found in Seed7 include directory.
MySql/MariaDb: DLL / Shared library: libmariadb.dll
MySql/MariaDb: DLL / Shared library: libmysql.dll
SQLite: db_lite.h found in Seed7 include directory.
SQLite: DLL / Shared library: sqlite3.dll
PostgreSQL: db_post.h found in Seed7 include directory.
PostgreSQL: DLL / Shared library: libpq.dll
PostgreSQL: DLL / Shared library: libintl.dll
PostgreSQL: DLL / Shared library: libintl-8.dll
PostgreSQL: DLL / Shared library: libintl-9.dll
PostgreSQL: DLL / Shared library: libeay32.dll
PostgreSQL: DLL / Shared library: libcrypto-1_1-x64.dll
PostgreSQL: DLL / Shared library: libssl-1_1-x64.dll
Odbc: sql.h found in system include directory.
Odbc: Linker option: -lodbc32

Does this mean that the sqlite3.dll is in a Windows shared library rather than part of the Seed7 install itself?

In comparison, if I do a search on my Windows system for libpq.dll, for example, it is part of a LibreOffice installation. However, this location is not in my system PATH, so I don't understand why it shows as "DLL / Shared library".

Similarly, the sqlite3.dll appears in many folders, but I am not aware that any of them are in the system PATH. To resolve the Database error: Searching dynamic libraries failed: sqlite3.dll problem, I copied the latest version of sqlite3.dll into the same folder as the SQLite database. My expectation is that Seed7 would have searched the current directory first for the DLL. This, however, did not solve the problem.

Is there some way I can establish where Seed7 is looking for the sqlite3.dll file? Could the Seed7 installation process have information about the "DLL / Shared library" location put into the log output?

Also, I have a question about the sql7.sd7 program. In line 244, it seems to use a different version of the openDatabase line, compared to Opening a database connection section (13.1) in the Manual.

sql7.sd7: currDb := openDatabase(driver, argv(PROGRAM)[2], argv(PROGRAM)[3], password); 13.1.4 Opening a SQLite database connection: currDb := openDatabase(DB_SQLITE, "", 0, "aDir/dbName.db", "testUser", "testPassword");

Should the sql7.sd7 program have the host and the port included in the openDatabase command line?

In any case, I would be interested in knowing how to use Seed7 in processing data in a SQLite database. If I am doing something incorrectly, please let me know.

Kind Regards, Liam

ThomasMertes commented 8 months ago

Hi Liam,

As you have guessed sqlite3.dll is a Windows shared library and not part of the Seed7 install. The error

Searching dynamic libraries failed: sqlite3.dll

refers to the sqlite3.dll provided by SQLite.

During installation chkccomp.c does not search for sqlite3.dll. It just knows that SQLite needs the sqlite3.dll. This is shown in the installation log:

SQLite: DLL / Shared library: sqlite3.dll

The Seed7 run-time attempts to load sqlite3.dll in the moment an SQLite DB is opened. This is done with the function LoadLibrary from Windows. This function has strict rules where to search for a DLL:

  1. The directory from which the application is loaded. (In other words: The directory of the EXE file)
  2. C:\Windows\System32.
  3. C:\Windows\System.
  4. C:\Windows.
  5. The current working directory.
  6. Directories in the system PATH environment variable.

Obviously sqlite3.dll is in none of these directories. You found the sqlite3.dll in many folders because many applications use point 1. You will find that the sqlite3.dll files are in the same directory as an EXE file that needs SQLite. In case of the Seed7 interpreter the directory would be .../seed7/bin (if you did a make install). If you copy sqlite3.dll into this directory the s7 interpreter will always find sqlite3.dll.

If you compile a Seed7 program to an EXE the sqlite3.dll must be placed into the directory of this EXE.

As alternative you could copy sqlite3.dll to one of the Windows directories (e.g. to C:\Windows\System32). Of course this has a system wide effect.

The Seed7 installation process regarding SQLite is simple (see function determineSqliteDefines() in chkccomp.c). For other databases a much more extensive search for static and dynamic libraries is done. When I did the SQLite support I did not find any common SQLite installation directory or SQLite related environment variable that I could use to find a static or dynamic SQLite library. So I assumed that SQLite might be installed in C:/sqlite or D:/sqlite. If a static or dynamic SQLite library is found in these directories it it used.

If the Seed7 installation process could find a sqlite3.dll at an "official" place the function LoadLibrary could be invoked with an absolute path or SQLite could be linked statically (with sqlite3.lib).

Kind Regards, Thomas

ThomasMertes commented 8 months ago

Regarding your question about the sql7.sd7 program:

In line 244 the program sql7.sd7 uses the openDatabase function from Other ways to open a database connection section (13.2) in the Manual. The line

sql7.sd7: currDb := openDatabase(driver, argv(PROGRAM)[2], argv(PROGRAM)[3], password);

invokes the function

const func database: openDatabase (in dbCategory: driver, in string: dbPath,
                                   in string: user, in string: password)

where the dbPath can be given in one of these forms:

I hope that helps.

Kind Regards, Thomas

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

I installed the latest release (20231104) into the c:\seed7 directory using the previously downloaded seed7_05_20230709_win.exe. As an FYI, I have included the installation log below:

Installation Log:

~~~ C:\Users\New\Downloads>seed7_05_20230709_win.exe Chkccomp uses NUL: as null device. Prepare compile command: .. done Check for link time optimization: . Not available. Numeric sizes: ........................ determined General settings: ........................................................................................ determined Numeric properties: .................................................................................................. determined Advanced settings: ................................................ determined Using Windows libraries MySql/MariaDb: db_my.h found in Seed7 include directory. MySql/MariaDb: DLL / Shared library: libmariadb.dll MySql/MariaDb: DLL / Shared library: libmysql.dll SQLite: db_lite.h found in Seed7 include directory. SQLite: DLL / Shared library: sqlite3.dll PostgreSQL: db_post.h found in Seed7 include directory. PostgreSQL: DLL / Shared library: libpq.dll PostgreSQL: DLL / Shared library: libintl.dll PostgreSQL: DLL / Shared library: libintl-8.dll PostgreSQL: DLL / Shared library: libintl-9.dll PostgreSQL: DLL / Shared library: libeay32.dll PostgreSQL: DLL / Shared library: libcrypto-1_1-x64.dll PostgreSQL: DLL / Shared library: libssl-1_1-x64.dll Odbc: sql.h found in system include directory. Odbc: Linker option: -lodbc32 Oracle: db_oci.h found in Seed7 include directory. Oracle: DLL / Shared library: oci.dll Firebird: db_fire.h found in Seed7 include directory. Firebird: DLL / Shared library: fbclient.dll Firebird: DLL / Shared library: gds32.dll DB2: db_odbc.h found in Seed7 include directory. DB2: DLL / Shared library: db2cli.dll Informix: sql.h found in system include directory. Informix: DLL / Shared library: iclit09b.dll SQL Server: sql.h found in system include directory. SQL Server: DLL / Shared library: sqlsrv32.dll TDS: db_tds.h found in Seed7 include directory. TDS: DLL / Shared library: sybdb.dll Macro read_buffer_empty defined. 10 times removing a file needed a reattempt. Current level is 20 ar: creating ..\bin\s7_comp.a ar: creating ..\bin\s7_data.a ar: creating ..\bin\s7_draw.a ar: creating ..\bin\s7_con.a ar: creating ..\bin\s7_db.a ar: creating ..\bin\seed7_05.a SEED7 INTERPRETER Version 5.2.20 Copyright (c) 1990-2023 Thomas Mertes Current level is 20 SEED7 INTERPRETER Version 5.2.20 Copyright (c) 1990-2023 Thomas Mertes Compiling the compiler ... SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/s7c Compiling the program ... Compiling the compiler ... Generating code ... after walk_const_list 6588 declarations processed 8231 optimizations done 14054 evaluations done 68 division checks inserted 150 range checks inserted 3566 index checks inserted 2250 overflow checks inserted Calling the C compiler ... c:\seed7\bin\call_gcc -w -O2 -ffunction-sections -fdata-sections -c tmp_s7c.c 2>tmp_s7c.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o s7c.exe tmp_s7c.o ..\bin\s7_comp.a ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_con.a ..\bin\s7_db.a ..\bin\seed7_05.a -lws2_32 -lodbc32 -lgdi32 -lm 2>tmp_s7c.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/bas7.sd7 Compiling the program ... Generating code ... after walk_const_list 4319 declarations processed 4560 optimizations done 599 functions inlined 5918 evaluations done 19 division checks inserted 301 range checks inserted 13 range checks optimized away 1181 index checks inserted 33 index checks optimized away 1584 overflow checks inserted 159 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_bas7.c 2>tmp_bas7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o bas7.exe tmp_bas7.o ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 -lgdi32 -lm 2>tmp_bas7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/bigfiles.sd7 Compiling the program ... Generating code ... after walk_const_list 1365 declarations processed 703 optimizations done 74 functions inlined 887 evaluations done 1 division checks inserted 37 range checks inserted 3 range checks optimized away 174 index checks inserted 2 index checks optimized away 241 overflow checks inserted 23 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_bigfiles.c 2>tmp_bigfiles.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o bigfiles.exe tmp_bigfiles.o ..\bin\s7_data.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 2>tmp_bigfiles.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/calc7.sd7 Compiling the program ... Generating code ... after walk_const_list 2758 declarations processed 1622 optimizations done 348 functions inlined 1973 evaluations done 1 division checks inserted 57 range checks inserted 5 range checks optimized away 538 index checks inserted 7 index checks optimized away 761 overflow checks inserted 40 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_calc7.c 2>tmp_calc7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o calc7.exe tmp_calc7.o ..\bin\s7_comp.a ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_con.a ..\bin\s7_db.a ..\bin\seed7_05.a -lws2_32 -lodbc32 -lgdi32 -lm 2>tmp_calc7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/cat.sd7 Compiling the program ... Generating code ... after walk_const_list 657 declarations processed 253 optimizations done 46 functions inlined 306 evaluations done 1 division checks inserted 30 range checks inserted 2 range checks optimized away 106 index checks inserted 2 index checks optimized away 80 overflow checks inserted 8 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_cat.c 2>tmp_cat.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o cat.exe tmp_cat.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_cat.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/comanche.sd7 Compiling the program ... Generating code ... after walk_const_list 4438 declarations processed 4747 optimizations done 787 functions inlined 5538 evaluations done 3 division checks inserted 354 range checks inserted 72 range checks optimized away 1333 index checks inserted 311 index checks optimized away 1416 overflow checks inserted 304 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_comanche.c 2>tmp_comanche.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o comanche.exe tmp_comanche.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 -lm 2>tmp_comanche.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/db7.sd7 Compiling the program ... Generating code ... after walk_const_list 5661 declarations processed 4585 optimizations done 673 functions inlined 5892 evaluations done 32 division checks inserted 361 range checks inserted 40 range checks optimized away 1490 index checks inserted 127 index checks optimized away 2007 overflow checks inserted 332 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_db7.c 2>tmp_db7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o db7.exe tmp_db7.o ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_db.a ..\bin\seed7_05.a -lws2_32 -lodbc32 -lgdi32 -lm 2>tmp_db7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/diff7.sd7 Compiling the program ... Generating code ... after walk_const_list 1138 declarations processed 746 optimizations done 65 functions inlined 920 evaluations done 1 division checks inserted 37 range checks inserted 3 range checks optimized away 174 index checks inserted 2 index checks optimized away 260 overflow checks inserted 26 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_diff7.c 2>tmp_diff7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o diff7.exe tmp_diff7.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_diff7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/find7.sd7 Compiling the program ... Generating code ... after walk_const_list 1270 declarations processed 700 optimizations done 66 functions inlined 894 evaluations done 1 division checks inserted 37 range checks inserted 3 range checks optimized away 165 index checks inserted 2 index checks optimized away 232 overflow checks inserted 24 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_find7.c 2>tmp_find7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o find7.exe tmp_find7.o ..\bin\s7_data.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 2>tmp_find7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/findchar.sd7 Compiling the program ... Generating code ... after walk_const_list 1271 declarations processed 714 optimizations done 66 functions inlined 903 evaluations done 1 division checks inserted 37 range checks inserted 3 range checks optimized away 166 index checks inserted 2 index checks optimized away 240 overflow checks inserted 25 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_findchar.c 2>tmp_findchar.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o findchar.exe tmp_findchar.o ..\bin\s7_data.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 2>tmp_findchar.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/ftp7.sd7 Compiling the program ... Generating code ... after walk_const_list 1876 declarations processed 1399 optimizations done 185 functions inlined 1615 evaluations done 1 division checks inserted 49 range checks inserted 15 range checks optimized away 282 index checks inserted 19 index checks optimized away 593 overflow checks inserted 78 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_ftp7.c 2>tmp_ftp7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o ftp7.exe tmp_ftp7.o ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 -lgdi32 2>tmp_ftp7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/ftpserv.sd7 Compiling the program ... Generating code ... after walk_const_list 1653 declarations processed 1279 optimizations done 123 functions inlined 1537 evaluations done 1 division checks inserted 49 range checks inserted 15 range checks optimized away 220 index checks inserted 6 index checks optimized away 551 overflow checks inserted 75 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_ftpserv.c 2>tmp_ftpserv.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o ftpserv.exe tmp_ftpserv.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_ftpserv.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/hd.sd7 Compiling the program ... Generating code ... after walk_const_list 1130 declarations processed 678 optimizations done 65 functions inlined 875 evaluations done 1 division checks inserted 37 range checks inserted 3 range checks optimized away 159 index checks inserted 2 index checks optimized away 227 overflow checks inserted 23 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_hd.c 2>tmp_hd.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o hd.exe tmp_hd.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_hd.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/ide7.sd7 Compiling the program ... Generating code ... after walk_const_list 5348 declarations processed 4351 optimizations done 652 functions inlined 5701 evaluations done 32 division checks inserted 353 range checks inserted 39 range checks optimized away 1434 index checks inserted 127 index checks optimized away 1939 overflow checks inserted 327 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_ide7.c 2>tmp_ide7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o ide7.exe tmp_ide7.o ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\seed7_05.a -lws2_32 -lgdi32 -lm 2>tmp_ide7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/make7.sd7 Compiling the program ... Generating code ... after walk_const_list 1750 declarations processed 1748 optimizations done 424 functions inlined 1818 evaluations done 1 division checks inserted 48 range checks inserted 4 range checks optimized away 618 index checks inserted 5 index checks optimized away 557 overflow checks inserted 33 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_make7.c 2>tmp_make7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o make7.exe tmp_make7.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_make7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/portfwd7.sd7 Compiling the program ... Generating code ... after walk_const_list 1233 declarations processed 857 optimizations done 53 functions inlined 1050 evaluations done 1 division checks inserted 30 range checks inserted 2 range checks optimized away 140 index checks inserted 2 index checks optimized away 467 overflow checks inserted 28 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_portfwd7.c 2>tmp_portfwd7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o portfwd7.exe tmp_portfwd7.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_portfwd7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/pv7.sd7 Compiling the program ... Generating code ... after walk_const_list 4558 declarations processed 4401 optimizations done 574 functions inlined 5346 evaluations done 47 division checks inserted 504 range checks inserted 23 range checks optimized away 1400 index checks inserted 201 index checks optimized away 2134 overflow checks inserted 313 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_pv7.c 2>tmp_pv7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o pv7.exe tmp_pv7.o ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 -lgdi32 -lm 2>tmp_pv7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/sql7.sd7 Compiling the program ... Generating code ... after walk_const_list 1989 declarations processed 1371 optimizations done 140 functions inlined 1492 evaluations done 1 division checks inserted 45 range checks inserted 4 range checks optimized away 292 index checks inserted 4 index checks optimized away 603 overflow checks inserted 42 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_sql7.c 2>tmp_sql7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o sql7.exe tmp_sql7.o ..\bin\s7_data.a ..\bin\s7_draw.a ..\bin\s7_con.a ..\bin\s7_db.a ..\bin\seed7_05.a -lws2_32 -lodbc32 -lgdi32 -lm 2>tmp_sql7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/sydir7.sd7 Compiling the program ... Generating code ... after walk_const_list 1307 declarations processed 1036 optimizations done 68 functions inlined 1284 evaluations done 1 division checks inserted 37 range checks inserted 3 range checks optimized away 163 index checks inserted 2 index checks optimized away 495 overflow checks inserted 32 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_sydir7.c 2>tmp_sydir7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o sydir7.exe tmp_sydir7.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_sydir7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/tar7.sd7 Compiling the program ... Generating code ... after walk_const_list 3813 declarations processed 2685 optimizations done 312 functions inlined 3130 evaluations done 3 division checks inserted 185 range checks inserted 23 range checks optimized away 700 index checks inserted 75 index checks optimized away 1119 overflow checks inserted 201 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_tar7.c 2>tmp_tar7.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o tar7.exe tmp_tar7.o ..\bin\s7_data.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 -lm 2>tmp_tar7.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/toutf8.sd7 Compiling the program ... Generating code ... after walk_const_list 1315 declarations processed 977 optimizations done 103 functions inlined 1148 evaluations done 1 division checks inserted 49 range checks inserted 15 range checks optimized away 202 index checks inserted 2 index checks optimized away 267 overflow checks inserted 66 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_toutf8.c 2>tmp_toutf8.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o toutf8.exe tmp_toutf8.o ..\bin\s7_data.a ..\bin\s7_con.a ..\bin\seed7_05.a -lws2_32 2>tmp_toutf8.lerrs >NUL: SEED7 COMPILER Version 3.2.20 Copyright (c) 1990-2023 Thomas Mertes Source: ../prg/which.sd7 Compiling the program ... Generating code ... after walk_const_list 1920 declarations processed 1140 optimizations done 282 functions inlined 1521 evaluations done 1 division checks inserted 43 range checks inserted 3 range checks optimized away 432 index checks inserted 5 index checks optimized away 425 overflow checks inserted 23 overflow checks optimized away Calling the C compiler ... c:\seed7\bin\call_gcc -w -O3 -ffunction-sections -fdata-sections -c tmp_which.c 2>tmp_which.cerrs >NUL: Calling the linker ... c:\seed7\bin\call_gcc -Wl","--strip-debug -Wl","--stack","8388608 -Wl","--gc-sections -o which.exe tmp_which.o ..\bin\s7_data.a ..\bin\seed7_05.a -lws2_32 2>tmp_which.lerrs >NUL: .\setwpath.exe add ..\bin ~~~

Also, the "chk_all" tests ran without any errors, with "okay" for every check.

After the installation, I ran the "where" command for the Seed7 interpreter (where s7) to request the appropriate PATH information and this gave the following output:

c:\seed7\bin\s7.exe

I copied the sqlite3.dll into the c:\seed7\bin folder as suggested above ("If you copy sqlite3.dll into this directory the s7 interpreter will always find sqlite3.dll."). However, I encountered the same problems as before with both the Database Inspector 7 and the SQL command line tool.

As a further check, I ran the chkdb.sd7 check of the database interface, with the s7 C:\seed7\prg\chkdb.sd7 Lite Rosetta-Code.db command and I got a similar result:

SEED7 INTERPRETER Version 5.2.20  Copyright (c) 1990-2023 Thomas Mertes
Password:
Test Rosetta-Code.db with driver DB_SQLITE
 *** Cannot open database Rosetta-Code.db with driver DB_SQLITE
 *** Database error: Searching dynamic libraries failed: sqlite3.dll

In your description of the determineSqliteDefines function in chkccomp.c, you mentioned that C:/sqlite could be used as a "default" directory for the sqlite3.dll file. As time allows, my next approach would be to create that directory, reinstall the latest release of Seed7, and see if that will resolve problem of locating the DLL.

Again, I am open to any other suggestions that you might have to troubleshoot this issue.

Kind Regards, Liam

ThomasMertes commented 8 months ago

Hi Liam,

I have a new idea. The makefile mk_mingw.mak contains the command:

copy ..\bin\s7.exe ..\prg /Y

So s7.exe is copied from bin to prg. As consequence s7.exe exists in both directories. When you run chkdb.sd7 in the prg directory it probably executes c:\seed7\prg\s7.exe instead of c:\seed7\bin\s7.exe.

Try to copy sqlite3.dll to c:\seed7\prg. Now the executable c:\seed7\prg\s7.exe and the DLL c:\seed7\prg\sqlite3.dll are in the same directory.

Alternatively you can try to remove c:\seed7\prg\s7.exe. In this case `c:\seed7\prg\s7.exewill be executed instead ofc:\seed7\prg\s7.exe. In this casec:\seed7\bin\sqlite3.dll` is in the same directory as the executable.

If this still fails I have another idea: The function LoadLibrary from Windows might also fail after it found sqlite3.dll. If sqlite3.dll itself has dependencies to other DLLs LoadLibrary tries to resolve these dependencies as well. So LoadLibrary might search for further DLLs. I have no idea which DLLs would be requested by sqlite3.dll. In case of PostgreSQL it is necessary to load libintl.dll, libeay32.dll, libcrypto.dll and libssl.dll before loading libpq.dll. You told me that you found sqlite3.dll in several directories. Maybe some other DLL is always in the same directory as sqlite3.dll. This might be a candidate for a DLL that should also be copied to c:\seed7\bin and c:\seed7\prg.

About installing SQLite in C:/sqlite: This would be the next step if the ideas from above failed. On my Windows laptop the files sqlite3.dll and sqlite3.h are the directory C:/sqlite. Probably sqlite3.h is not needed because determineSqliteDefines can take db_lite.h instead. I took a look at determineSqliteDefines in chkcomp.c. It looks like determineSqliteDefines determines an absolute path to sqlite3.dll. If sqlite3.dll does not depend on other DLLs this should work. Otherwise an absolute path to these other DLLs would be needed as well.

I did a test on my Windows laptop and the approach with the directory C:/sqlite works. The DLL sqlite3.dll is loaded with the absolute path C:/sqlite/sqlite3.dll. This approach has the advantage that it also works with compiled Seed7 programs (that might be placed in a directory without sqlite3.dll).

I hope that will help.

Kind Regards, Thomas

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

Thanks for the comprehensive list of suggestions! Here are the results of my testing:

Copying the DLL into the C:\seed7\prg directory

Testing with s7 C:\seed7\prg\chkdb.sd7 Lite Rosetta-Code.db gave the same error as before:

SEED7 INTERPRETER Version 5.2.20  Copyright (c) 1990-2023 Thomas Mertes
Password:
Test Rosetta-Code.db with driver DB_SQLITE
 *** Cannot open database Rosetta-Code.db with driver DB_SQLITE
 *** Database error: Searching dynamic libraries failed: sqlite3.dll

Removing the c:\seed7\prg\s7.exe executable

(Likewise, the same error as above)

Checking for another DLL file

On the SQLite Download page, is a 64-bit DLL (x64) for SQLite version 3.44.0 download. This Zip file contains only a "DEF" text file and the sqlite3.dll file.

In my research, the only other DLL associated with SQLite is the sqlcipher.dll used for encrypting SQLite databases. The application DB Browser for SQLite, for example, installs this DLL. Since SQLCipher is an open-source extension to SQLite, created by the company Zetetic, then it would be safe to assume that it would not be necessary in normal SQLite usage and would not be called by the sqlite3.dll itself.

Putting the DLL in the C:\sqlite directory

I only noticed a short time ago that you had edited your previous answer several times to address this particular option. Thanks for doing this specific testing!

By the way, something I noticed previously but didn't comment on: should the folder be called C:\sqlite rather than C:/sqlite (with the forward slash) as given in line 7609 of chkccomp.c? Does the Seed7 interpreter recognize this as a Windows file path, in any case?

Thanks again for your effort in testing SQLite on Windows. I will return to this issue, time permitting, over the next few days and hopefully will get the same successful results that you have obtained.

Kind Regards, Liam

ThomasMertes commented 8 months ago

You mentioned that the sqlite3.dll you downloaded is a 64-bit DLL. If you execute (in seed7/prg):

s7 confval

what does it write for POINTER_SIZE? If POINTER_SIZE is 32 then s7.exe is a 32-bit executable. As 32-bit executable it is not able to load a 64-bit DLL. This would explain why loading sqlite3.dll always fails.

If this is the case I suggest you download a 32-bit sqlite3.dll and put it into the directory C:\sqlite. Do a make clean, make depend, make to build Seed7 again.

The Seed7 installer uses a 32-bit GCC to make sure that Seed7 works on 32-bit and 64-bit windows. The corresponding makefile is mk_mingc.mak.

If you want to switch to 64-bit you need install a 64-bit version of MinGW. Probably the packages gcc and glibc-devel are needed (not sure about the names).

Regarding slash or backslash in paths: C programs under Windows allow / and \ as path delimiters. This includes all the usual file operations fopen(), mkdir(), stat(), etc. Seed7 only works with / as path delimiter. The Windows function LoadLibrary works only with \ as path delimiter. This is no problem as the Seed7 run-time makes sure that / is converted to \ before LoadLibrary is called.

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

Yes, the POINTER_SIZE is indeed 32.

To obtain the latest version of the SQLite DLL, I had installed it via the Chocolatey package manager. This installed the 64-bit version, by default. I will install the 32-bit version and build Seed7 again as you have suggested.

Kind Regards, Liam

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

On 11th November, before the https://github.com/ThomasMertes/seed7/commit/c6d2fa0f80a23cc11e1bc4b96582426b532e4d49 and https://github.com/ThomasMertes/seed7/commit/24d20309bd92256fa170e2ffe4cef53f8382ffb7 commits were applied, I ran the following commands in the C:\seed7\src folder:

  1. ..\bin\make7 -f mk_mingc.mak clean
  2. ..\bin\make7 -f mk_mingc.mak depend
  3. ..\bin\make7 -f mk_mingc.mak
  4. ..\bin\make7 -f mk_mingc.mak s7c
  5. ..\bin\make7 -f mk_mingc.mak utils..\bin\make7 -f mk_mingc.mak utils
  6. ..\bin\make7 -f mk_mingc.mak test

After the "make depend" step these were the significant changes, compared to the previous versions:

C:\seed7\src\version.h

version-h

C:\seed7\src\vers_mingc.h

vers_mingc-h

Further, the "chk_all" tests all ran correctly with an "okay" summary for each one. I had previously copied the 32-bit "sqlite3.dll" into the c:\sqlite folder as was noted in the two screenshots.

The SQL command line tool (sql7.sd7) no longer has a problem with finding the DLL, but instead it cannot now open the database as it expects a default user:

usage: sql7 driver dbName user [password [sqlfile]]

However, no default user (or password) exists for the SQLite database, as noted in this response to a superuser.com question. Using a blank ('') for both the user and password (s7 C:\seed7\prg\sql7.sd7 Lite Rosetta-Code.db '' '') results in this error:

SEED7 INTERPRETER Version 5.2.21  Copyright (c) 1990-2023 Thomas Mertes
Sql7 - Sql command line tool
Copyright (C) 2014 Thomas Mertes
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Sql7 is written in the Seed7 programming language
Homepage: http://seed7.sourceforge.net

 *** Cannot open Rosetta-Code.db

Also, the Database Inspector (s7 C:\seed7\prg\db7.sd7) is now showing a simple Error occurred, but this is probably related to the same issue of expecting a default user and password.

Does Seed7 expect that all supported databases have a default or admin user? During my IT career, I supported mainly MS SQL Server and Oracle databases, and the expectation was that there was always an admin login, separate from normal user logins.

This is my first time working with SQLite, and it does seem strange that no admin login exists, but this seems to be the norm for this file-based database. I use DB Browser for SQLite for the initial creation of tables, and I have not yet found a requirement in the documentation for an admin login.

Might setting up SQLite without a default user be something that could be incorporated into Seed7?

Kind Regards, Liam

ThomasMertes commented 8 months ago

Hi Liam,

Regarding the the https://github.com/ThomasMertes/seed7/commit/c6d2fa0f80a23cc11e1bc4b96582426b532e4d49 and https://github.com/ThomasMertes/seed7/commit/24d20309bd92256fa170e2ffe4cef53f8382ffb7 commits: With them the command ..\bin\make7 -f mk_mingc.mak depend writes a log line like:

SQLite: DLL / Shared library: C:/sqlite/sqlite3.dll (present) (32-bit)

I added an explanation regarding the error "Searching dynamic libraries failed" to the FAQ. What do you think about this explanation?

The change to C:\seed7\src\version.h seems okay. The file C:\seed7\src\vers_mingc.h is an exact copy of C:\seed7\src\version.h and it is not used in the build process. If you compile with different makefiles (as I do) you get a *vers_.h** for every makefile you use.

but instead it cannot now open the database as it expects a default user:

The SQLite driver (see function 'sqlOpenLite` in sql_lite.c) ignores user and password.

The SQL command line tool (sql7.sd7) expects a user and asks for a password if you did not provide it in the command line. Using a blank ('') for both the user and password is okay. You could also use an empty string for user and password (s7 C:\seed7\prg\sql7.sd7 Lite Rosetta-Code.db "" "").

The function sqlOpenLite (in sql_lite.c) checks if the provided dbName (in your case Rosetta-Code.db) is a regular file. It also adds .db if it is missing from dbName. Since Rosetta-Code.db does not contain a slash (/) it is assumed that the file Rosetta-Code.db is in the current working directory.

I guess that on your computer Rosetta-Code.db is not in the current working directory and this triggers:

*** Cannot open Rosetta-Code.db

You can provide an absolute or relative path as dbName but the path must use the standard path representation (=no drive letters and / as path delimiters). In the standard path representation the path /c/some_dir/Rosetta-Code.db corresponds to the Windows path C:\some_dir\Rosetta-Code.db. So I guess that

`s7 C:\seed7\prg\sql7.sd7 Lite /c/some_dir/Rosetta-Code.db "" ""

works (if you replace some_dir with the path to Rosetta-Code.db in the C: drive). On my Windows computer I succeed with s7 sql7 Lite test.db "" "" and s7 sql7 Lite /c/Users/tm/Documents/seed7_5/prg/test.db "" "" (test.db is in my current working directory C:\Users\tm\Documents\seed7_5\prg). On my Linux computer I succeed with s7 sql7 Lite test.db "" "" and s7 sql7 Lite /home/tm/seed7_5/prg/test.db "" "" (test.db is in my current working directory /home/tm/seed7_5/prg).

BTW.: In most C files of Seed7 are the lines

#define LOG_FUNCTIONS 0
#define VERBOSE_EXCEPTIONS 0

directly after the introducing comment block. If you change both zeros to one and compile with ..\bin\make7 -f mk_mingc.mak you get an s7 interpreter that logs functions in this file. You could do this in sql_lite.c to find out what is going on.

Does Seed7 expect that all supported databases have a default or admin user?

No. In case of SQLite user and password are ignored, but for all other databases user and password are forwarded to the database connect command. How the database interprets user and password is not the job of Seed7.

This is my first time working with SQLite, and it does seem strange that no admin login exists, ...

I use the function sqlite3_open to open a SQLite database and this function has no parameters for user and password.

I hope that helps.

Kind Regards, Thomas

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

Thanks for the further background information on sql_lite.c and using "#define" to change the logging options. As regards the "current working directory", for both the SQL command line tool and the Database Inspector, I had launched the s7 command from the directory in which the Rosetta-Code.db resided. I presume that this was the correct expectation?

As per your comments regarding both double-quotes and single quotes for the username and password, I ran the s7 C:\seed7\prg\sql7.sd7 Lite Rosetta-Code.db again from that folder with both the single and double-quotes for the username and password, but got the same error (*** Cannot open ...) as previously. I also tried it from the C:\seed7\prg folder with the fully-qualified path to the SQLite database, and it again gave the same error.

However, interestingly, when I dropped the ".db" from the path, the resulting error message did not include the ".db" as might be expected. This would suggest that sql7 was unable to find the database file, even though the path was fully qualified. To ensure that I got the path written correctly, I put an "index.html" file in that folder and ran the Comanche web server s7 comanche.sd7 "/c/Users..." on the top-level folder and the "index.html" content was displayed correctly.

Also, from the C:\seed7\prg folder, I ran s7 chkdb.sd7 lite "/c/Users/....Rosetta-Code.db" "" "" (I put double quotes around the path as there is a space in the path name), and the chkdb program prompted for a password, which seems to imply that the database was found, but that Windows doesn't think that a double-quote is the correct format for a blank password. But this doesn't make sense as it worked correctly on your Windows machine for sql7. This implies that further investigation is required.

My next step will be to change the "#define" statements and see what the logging will reveal. Recompiling will also help with verifying the updated documentation in the How to fix the error "Searching dynamic libraries failed"? in the Seed7 FAQ. From what I have seen so far this looks fine, but I will get back to if I find anything that might need to be modified.

Kind Regards, Liam

ThomasMertes commented 8 months ago

Hi Liam,

I just improved the logging functions for SQLite. Now the logging function writes the exact parameter that is used with sqlite3_open() and the SQLite error message of the failing sqlite3_open().

The function sqlOpenLite (in seed7/src/sql_lite.c) checks if the file dbName exists. If the file dbName does not exist it writes the error:

File \"%s\" not found.

If the file dbName exists it calls the SQLite function sqlite3_open().

You mentioned that you have the error:

*** Cannot open ...

In sql7.sd7 are the lines:

block
  currDb := openDatabase(driver, argv(PROGRAM)[2], argv(PROGRAM)[3], password);
exception
  catch DATABASE_ERROR:
    writeln(" *** Database error: " <& errMessage(DATABASE_ERROR));
  otherwise:
    writeln(" *** Cannot open " <& argv(PROGRAM)[2]);
end block;

This code writes the error message *** Cannot open ... if an exception other than DATABASE_ERROR is raised. I can trigger this error with:

s7 sql7 Lite C:\Users\tm\Documents\seed7_5\prg\test "" ""

The reason is: This path is not in the standard path representation. If I use /c/Users/tm/Documents/seed7_5/prg/test instead everything is fine.

Maybe there is another reason to get an exception. If you start the interpreter with -te you should get the information about the exception raised. If an exception is raised you get a message like:

*** Exception NUMERIC_ERROR raised at integer.s7i(118)
{1 div 0 } at chkexc.sd7(401)
*** Action "INT_DIV"

*** The following commands are possible:
  RETURN  Continue
  *       Terminate
  /       Trigger SIGFPE
  !n      Raise exception with number (e.g.: !1 raises MEMORY_ERROR)

By typing !1 you get a MEMORY_ERROR that usually triggers a stack trace.

Edit: I just added an initialization of the SQLite connection variable. In case of an sqlite3_open() error the connection is used to write logging information if it is not NULL.

Kind Regards, Thomas

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

Thanks for adding the extra logging functionality for the SQLite database including the updating of the connection variable.

As noted in https://github.com/ThomasMertes/seed7/issues/24, I did a fresh build of Seed7 but with a modification of sql_lite.c where both the "#define" values for LOG_FUNCTIONS and VERBOSE_EXCEPTIONS were set to 1.

In the working directory containing the Rosetta-Code.db database, I ran the command: s7 C:\seed7\prg\sql7.sd7 Lite Rosetta-Code.db "" ""

This was the result:

SEED7 INTERPRETER Version 5.2.24  Copyright (c) 1990-2023 Thomas Mertes
Sql7 - Sql command line tool
Copyright (C) 2014 Thomas Mertes
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Sql7 is written in the Seed7 programming language
Homepage: http://seed7.sourceforge.net

 *** sqlOpenLite("", 0, "Rosetta-Code.db", "", ""): SQLite driver not present.
 *** Cannot open Rosetta-Code.db

Interestingly, when I ran the Database Inspector in the same directory with the s7 c:\seed7\prg\db7.sd7 command, I got the following message in the console:

SEED7 INTERPRETER Version 5.2.24  Copyright (c) 1990-2023 Thomas Mertes
 *** sqlOpenLite("", 0, "Rosetta-Code.db", "", ""): SQLite driver not present.

The Database Inspector itself just gave a simple Error occurred message as had happened previously.

Using a fully-qualified filename for the SQLite database results in a similar error. This time I checked the full database file path using the convDosPath from "osfiles.s7i" to ensure that I was specifying it correctly.

Command: s7 c:\seed7\prg\sql7.sd7 Lite "/c/Users/..../Rosetta-Code.db" "" ""

Result:

SEED7 INTERPRETER Version 5.2.24  Copyright (c) 1990-2023 Thomas Mertes
Sql7 - Sql command line tool
Copyright (C) 2014 Thomas Mertes
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Sql7 is written in the Seed7 programming language
Homepage: http://seed7.sourceforge.net

 *** sqlOpenLite("", 0, "/c/Users/..../Rosetta-Code.db", "", ""): SQLite driver not present.
 *** Cannot open /c/Users/..../Rosetta Code Pages/Rosetta-Code.db

Running the -te command line option (s7 -te C:\seed7\prg\sql7.sd7 Lite Rosetta-Code "" "") gave the following output:

SEED7 INTERPRETER Version 5.2.24  Copyright (c) 1990-2023 Thomas Mertes
Sql7 - Sql command line tool
Copyright (C) 2014 Thomas Mertes
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Sql7 is written in the Seed7 programming language
Homepage: http://seed7.sourceforge.net

 *** sqlOpenLite("", 0, "Rosetta-Code", "", ""): SQLite driver not present.

*** Exception RANGE_ERROR raised at /c/seed7/lib/sql_base.s7i(216)
{DB_SQLITE "" 0 "Rosetta-Code" "" "" openDatabase }
*** Action "SQL_OPEN_LITE"

*** The following commands are possible:
  RETURN  Continue
  *       Terminate
  /       Trigger SIGFPE
  !n      Raise exception with number (e.g.: !1 raises MEMORY_ERROR)
!1
 *** Cannot open Rosetta-Code

At line 347 in the sql_base.s7i code, it mentions the DB_SQLITE driver and that dbPath is the path of the database file. Below this it states that "RANGE_ERROR" occurs If dbPath, user or password cannot be converted to the character set of the database.

Since the RANGE_ERROR was pointing to a possible issue with the path and also to check if there might be a problem with spaces in the file path (where the SQLite database currently resides), I copied the Rosetta-Code.db file into the C:\seed7\prg folder and then ran s7 sql7.sd7 Lite Rosetta-Code.db "" "" command as before, but this gave the same SQLite driver not present error as previously.

The "make depend" step from the build earlier in the day (..\bin\make7 -f mk_mingc.mak depend) had the following lines in the output:

Using Windows libraries
MySql/MariaDb: db_my.h found in Seed7 include directory.
MySql/MariaDb: DLL / Shared library: libmariadb.dll (not present)
MySql/MariaDb: DLL / Shared library: libmysql.dll (not present)
SQLite: DLL / Shared library: C:/sqlite/sqlite3.dll (present) (32-bit)
SQLite: DLL / Shared library: sqlite3.dll (present)
PostgreSQL: db_post.h found in Seed7 include directory.
PostgreSQL: DLL / Shared library: libpq.dll (not present)

This would seem to indicate that the 32-bit DLL is indeed present, so the SQLite driver not present error looks to be due to some other cause.

Kind Regards, Liam

ThomasMertes commented 8 months ago

Hi Liam,

I just checked in a fix in chkccomp.c to GitHub.

The old code checks if C:/sqlite exists and expects the files C:/sqlite/sqlite3.h and C:/sqlite/sqlite3.dll. If C:/sqlite/sqlite3.h was missing it did not write #define SQLITE_INCLUDE ... to version.h. Without that the SQLite driver (in sql_lite.c) is reduced to a function that writes SQLite driver not present and triggers a RANGE_ERROR.

The new code uses the include seed7/src/db_lite.h if it could not find C:/sqlite/sqlite3.h.

Another change in chkccomp.c triggers a search for sqlite3.dll in the seed7/bin directory (it uses the absolute path to your seed7/bin directory.

Now, instead of using C:/sqlite you could also copy sqlite3.dll to your seed7/bin directory.

Edit: I did another change in chkccomp.c. Now it logs if the seed7/bin/sqlite3.dll (or `.so?) is 32-bit or 64-bit.

Edit 2: Sorry for your compilation problems. This fix should solve them. At least: I am able to compile Seed7 with a 32-bit and 64-bit gcc now.

I hope this helps.

Kind Regards, Thomas

celtic-coder commented 8 months ago

Hi Thomas (@ThomasMertes),

After creating the build noted in Make7 Error #24, the Database Inspector (s7 c:\seed7\prg\db7.sd7) now correctly displays the database GUI. For example, here is the content from one of the tables:

select-star-from-table

The Database Inspector also gives the following messages in the console:

sql_lite.c: sqlOpenLite("Rosetta-Code", "", "")
sql_lite.c: setupDll("C:/sqlite/sqlite3.dll")
sql_lite.c: setupDll --> 1
sql_lite.c: sqlOpenLite --> 59698680
sql_lite.c: sqlPrepare(59698680, "SELECT name FROM sqlite_master WHERE type='table'")

Similarly, the command s7 c:\seed7\prg\sql7.sd7 Lite "/c/Users/..../Rosetta-Code.db" "" "" gave the following result in the console:

s7 c:\seed7\prg\sql7.sd7 Lite "/c/Users/...../Rosetta-Code.db" "" ""

[snip]

sql_lite.c: sqlOpenLite("/c/Users/...../Rosetta-Code.db", "", "")
sql_lite.c: setupDll("C:/sqlite/sqlite3.dll")
sql_lite.c: setupDll --> 1
sql_lite.c: sqlOpenLite --> 48292736
Sql7?

I originally opened this issue on October 30th and I want to thank you for your patience that for more than three weeks you have taken the time to respond to my questions and make technical and documentation updates to Seed7 to resolve these concerns.

Kind Regards, Liam