comp.lang.ada
 help / color / mirror / Atom feed
* sqlite binding
@ 2003-07-07 12:30 Ching Bon Lam
  2003-07-07 14:16 ` Andreas Almroth
  2003-07-11 15:34 ` Michael Erdmann
  0 siblings, 2 replies; 3+ messages in thread
From: Ching Bon Lam @ 2003-07-07 12:30 UTC (permalink / raw)


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);

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;

-------------------------------------------------------------------------

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sqlite binding
  2003-07-07 12:30 sqlite binding Ching Bon Lam
@ 2003-07-07 14:16 ` Andreas Almroth
  2003-07-11 15:34 ` Michael Erdmann
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Almroth @ 2003-07-07 14:16 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sqlite binding
  2003-07-07 12:30 sqlite binding Ching Bon Lam
  2003-07-07 14:16 ` Andreas Almroth
@ 2003-07-11 15:34 ` Michael Erdmann
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Erdmann @ 2003-07-11 15:34 UTC (permalink / raw)
  To: Ching Bon Lam

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):

I have read you thread and i  think it is an interesting idea. I am
running for the last two years a project called GNADE, wehre we collect
bindings to different database systems. I guess it would be a good
idea if you join us in the project.

See http://gnade.sourceforge.net/

Michael




> 
> -- Code -----------------------------------------------------------------
> 
> sqlite *sqlite_open(const char *filename, int mode, char **errmsg);
> 
> 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;
> 
> -------------------------------------------------------------------------
> 
> 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-11 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-07 12:30 sqlite binding Ching Bon Lam
2003-07-07 14:16 ` Andreas Almroth
2003-07-11 15:34 ` Michael Erdmann

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