FreeBasic/SQL

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
WJSwan
Posts: 1
Joined: Jan 04, 2023 11:08

FreeBasic/SQL

Post by WJSwan »

I am trying my hand at accessing a SQLite3 database using Freebasic.

I looked at this post: viewtopic.php?p=210774#p210774 and tried the class and test.bas but I get the following errors when I try to compile the test.bas program:

C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(90) error 42: Variable not declared, sqlite3_api in 'psz = sqlite3_libversion'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(99) error 9: Expected expression, found 'sqlite3_api' in 'Function = sqlite3_libversion_number()'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(100) warning 13(1): Function result was not explicitly set
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(108) error 9: Expected expression, found 'sqlite3_api' in 'psz = sqlite3_sourceid'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(141) error 9: Expected expression, found 'sqlite3_api' in 'Dim rc As Integer = sqlite3_open( DBName, @m_dbHandle)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(154) error 9: Expected expression, found 'sqlite3_api' in 'Dim rc As Integer = sqlite3_close(m_dbHandle)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(166) error 99: No matching overloaded function, LASTERROR() in 'this.LastError = sqlite3_exec(this.dbHandle, sql, 0, 0, @errmsg)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(167) error 3: Expected End-of-Line, found 'sqlite3_api' in 'sqlite3_free(errmsg)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(178) error 9: Expected expression, found 'sqlite3_api' in 'pzSql = sqlite3_mprintf("%q", sql)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(180) error 3: Expected End-of-Line, found 'sqlite3_api' in 'sqlite3_free(pzSql)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(206) error 3: Expected End-of-Line, found 'sqlite3_api' in 'sqlite3_finalize(this.hstmt)'
C:\FreeBASIC\fltk-c-1.3.3\clsSqlite3.bas(206) error 133: Too many errors, exiting

Results:
Compilation failed

Any advice?
Imortis
Moderator
Posts: 1929
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: FreeBasic/SQL

Post by Imortis »

I just compiled with the newest official release of the FB compiler and it worked. What version of the compiler are you using?
Julcar
Posts: 141
Joined: Oct 19, 2010 18:52
Contact:

Re: FreeBasic/SQL

Post by Julcar »

Maybe you could try my own sqlite implementation:

sqlite3.bi
data.bi
data.bas

you should include only data.bi anywhere you need to perform sql queries, here is a dummy example:

Code: Select all

#include "data.bi"

Dim myDST as DataSet, sql as string

OpenConnection("data.s3db")

sql = "SELECT * FROM myTable"
myDST = FetchData(sql)

CloseConnection()

For i as ulong = 0 to myDST.RowCount
  For j as ulong = 0 to myDST.Rows(i).FieldCount
    Print myDST.Rows(i).Fields(j).Value
  Next j
Next i
Whopper19
Posts: 2
Joined: Jan 31, 2023 10:52

Re: FreeBasic/SQL

Post by Whopper19 »

It looks like you need to declare the 'sqlite3_api' variable before using it in your code. The 'sqlite3_api' variable is used to access the functions exposed by the SQLite3 library.

To declare the 'sqlite3_api' variable, you need to add a line of code at the top of your program:

Declare Function sqlite3_api Lib "sqlite3.dll" Alias "sqlite3_api" () As Any

Once you add this line of code, the compiler should be able to find the 'sqlite3_api' variable and you should be able to compile and run your program successfully.
Whopper19
Posts: 2
Joined: Jan 31, 2023 10:52

Re: FreeBasic/SQL

Post by Whopper19 »

Check this problem post might be helpful.
Last edited by fxm on Mar 22, 2023 12:06, edited 2 times in total.
Reason: Link suppressed and user warned.
adeyblue
Posts: 302
Joined: Nov 07, 2019 20:08

Re: FreeBasic/SQL

Post by adeyblue »

A lead time of nearly two months for the lowest grade spam imaginable? I guess they didn't pay for a particularly advanced package
Post Reply