comp.lang.ada
 help / color / mirror / Atom feed
From: Andreas Almroth <andreas@almroth.com>
Subject: Re: sqlite binding
Date: Mon, 07 Jul 2003 15:16:39 +0100
Date: 2003-07-07T15:16:39+01:00	[thread overview]
Message-ID: <bebv7t$3c0r9$3@ID-198985.news.dfncis.de> (raw)
In-Reply-To: <Xns93B193A67A651cblamstudentutwenten@194.109.133.20>

Ching Bon Lam wrote:
> hello everyone,
> 
> I've been trying to make some sort of sqlite binding. SQLite itself is at 
> http://www.sqlite.org/ . For now i just want to import the core api 
> consisting of three functions (taken from sqlite.h):
> 
> -- Code -----------------------------------------------------------------
> 
> sqlite *sqlite_open(const char *filename, int mode, char **errmsg);
> 

function Sqlite_Open(Filename : in Interfaces.C.Strings.Chars_Ptr;
		     mode     : Interfaces.C.Int;
                      Errmsg   : access interfaces.C.Strings.Chars_Ptr)
		return Sqlite_T;
pragma Import(C,Sqlite_Open,"sqlite_open);

> void sqlite_close(sqlite *);
> 
> int sqlite_exec(
>   sqlite*,          /* An open database */
>   const char *sql,  /* SQL to be executed */
>   sqlite_callback,  /* Callback function */
>   void *,           /* 1st argument to callback function */
>   char **errmsg     /* Error msg written here */
> );
> 
> -------------------------------------------------------------------------
> 
> with:
> 
> -- Code -----------------------------------------------------------------
> 
> typedef struct sqlite sqlite; /* opaque struct */
> typedef int (*sqlite_callback)(void*,int,char**, char**);
> 
> -------------------------------------------------------------------------
> 
> What I did till now is:
> 
> -- Code -----------------------------------------------------------------
> 
> -- typedef struct sqlite sqlite; /* opaque struct */
> subtype sqlite is Interfaces.C.Extensions.opaque_structure_def;
> 

Without knowing the details, but I would probably use System.Address as
pointer, so;

type Sqlite_T is System.Address;

This takes that you will never access anything within the record, and 
only reference it as pointer.

As for the callback, you define a type for the callback pointer;

type Sqlite_Callback_T is access function(P  : System.Address;
					  I  : Interfaces.C.Int;
					  C1 : System.Address;
					  C2 : System.Address)
					return Interfaces.C.Int;

OK,ok, using System.Address is a bit of a hack, but one should probably 
look into using access interfaces.c.strings.chars_ptr instead.
Could make it easier instead of using 
System.Address_To_Access_Conversions feature...


> -------------------------------------------------------------------------
> 
> i don't know how to do the rest with the tons of pointers as arguments..
> if someone would give me some pointers/guidance/hints, i would be really 
> grateful.
> 
> greetings,
> CBL


Cheers,
Andreas




  reply	other threads:[~2003-07-07 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-07 12:30 sqlite binding Ching Bon Lam
2003-07-07 14:16 ` Andreas Almroth [this message]
2003-07-11 15:34 ` Michael Erdmann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox