[plt-scheme] SOLVED: how to do this in C?

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Fri Jun 2 22:33:15 EDT 2006

Just wondering, why dont you use the FFI which is part of standard mzscheme?

Mike wrote:
> Is there a better way? Below is my solution.
> The relevant parts are the two while loops at the bottom.
>
> Mike
>
> static Scheme_Object *sch_dbqueryAndFetch(int argc, Scheme_Object **argv)
> {
>     DB *dbo;
>     Stmt stmto;
>     sqlite3 *db;
>     sqlite3_stmt *stmt;
>     Results *results;
>     char *msg, *funcstr = "sqlite:fetchall";
>     const char *sql;
>     int rc, nrows;
>     Scheme_Object *sol, *sov;	/* scheme object list, scheme object vector */
>
>     /* check the arguments */
>     if(SCHEME_TYPE(argv[0]) != dbtype) {
>         scheme_wrong_type(funcstr, dbtypestr, 0, argc, argv);
>     }
>     if(!SCHEME_CHAR_STRINGP(argv[1])) {
>         scheme_wrong_type(funcstr, "string", 1, argc, argv);
>     }
>
>     /* prepare the query */
>     dbo = (DB *) argv[0];
>     stmto.db = dbo->db;
>     stmto.stmt = _doquery(funcstr, dbo->db, argv[1]);
>     stmto.type = stmttype;
>     stmto.ncols = stmto.currow = nrows = 0;
>     sol = scheme_null;
>
>     /* execute the query, get the results, turn the list into a vector */
>     while((sov = _dofetch(funcstr, &stmto)) != scheme_false) {
>         sol = scheme_make_pair(sov, sol);
>         nrows++;
>     }
>     sov = scheme_make_vector(nrows, scheme_void);
>     while(nrows-- > 0) {
>         SCHEME_VEC_ELS(sov)[nrows] = SCHEME_CAR(sol);
>         sol = SCHEME_CDR(sol);
>     }
>
>     return sov;
> }
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
>   


Posted on the users mailing list.