How to use SQLite with Mac OS X?

Mac OSX specific forum
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

How to use SQLite with Mac OS X?

Post by CSAUER »

I have found out, that SQLite comes with Tiger, as you can see in following developer note of Apple:
http://developer.apple.com/documentatio ... on_20.html

Any idea arround there how to access/use it? Do I need to have a wrapper? Can I access via "_"-Commands?
Should I be able to access it via OpenLibrary?

Code: Select all

sqlite = OpenLibrary(#PB_Any, "/usr/lib/libsqlite3.dylib")
It looks like it works, but should I use it?

Kind Regards
CSAUER
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

I tried following:

Code: Select all

sqlite3DLL = OpenLibrary(0, "/usr/lib/libsqlite3.dylib")
If sqlite3DLL
  Debug "Lib reachable"
  sqlite3_libversion = IsFunction(sqlite3DLL, "sqlite3_libversion")
  If sqlite3_libversion = 0
    Debug "no function 'libversion'"
  Else
    Debug "function 'libversion' reachable"
  EndIf   
  sqlite3_open = IsFunction(sqlite3DLL, "sqlite3_open")
  If sqlite3_open
    ;hResult = CallCFunctionFast(*sqlite3_open, "Test.db", @sqlite3_dbHandle)
  EndIf
EndIf
I can access to the lib. No error. But Purebasic cannot access the function "sqlite3_libversion". The variable returns always a zero. If I look into the header-file of the lib (/usr/includes/sqlite3.h), I can see that this function should exist:

Code: Select all

/*
** The version string is also compiled into the library so that a program
** can check to make sure that the lib*.a file and the *.h file are from
** the same version.  The sqlite3_libversion() function returns a pointer
** to the sqlite3_version variable - useful in DLLs which cannot access
** global variables.
*/
extern const char sqlite3_version[];
const char *sqlite3_libversion(void);

/*
** Return the value of the SQLITE_VERSION_NUMBER macro when the
** library was compiled. 
*/ 
int sqlite3_libversion_number(void); 

/* 
** Each open sqlite database is represented by an instance of the
** following opaque structure.
*/ 
typedef struct sqlite3 sqlite3;
Any idea out there?

The sqlite3 terminal application works well on Mac. You can admin, create, read, edit databases and tables. Its looks like only a short way to get the Sqlite workable with PB on Mac...
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I will take a quick look to see what is exactly happening.
Post Reply