Author Topic: I need some help with Sqlite3 DLL, plz.  (Read 6414 times)

0 Members and 1 Guest are viewing this topic.

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
I need some help with Sqlite3 DLL, plz.
« on: October 16, 2018, 05:31:32 am »
Hi folks,
Im trying to use Sqlite3 under QB64, I´ve downloaded the DLL and the C++ header (both in the same path as qb64).

I´m reading both the header file and some online material to figure out how to do it.

But I don´t know how to declare the following function (present in the header):

int sqlite3_open(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);

So, *filename is a pointer to the first char in the string? Like " _OFFSET(dbFileName$) for example?
And **ppDb isn´t an input pointer, but it outputs data?

Thanks to everyone!


Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #1 on: October 16, 2018, 05:35:16 am »
By the way, its better use Dynamic or a Customtype library?

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #2 on: October 16, 2018, 03:31:28 pm »
Here is the DLL and the H file.

Code: QB64: [Select]
  1. 'These two simple procedures returns no errors
  2.  
  3.     SUB initSql ALIAS sqlite3_initialize ()
  4.     SUB stopSql ALIAS sqlite3_shutdown ()
  5.    
  6.  

I´m trying to implement this function now, but im getting errors when I try to use it. I guess Im not passing the parameters correctly.

Code: QB64: [Select]
  1. int sqlite3_open(
  2.   const char *filename,   /* Database filename (UTF-8) */
  3.   sqlite3 **ppDb          /* OUT: SQLite db handle */
  4. );
  5.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #3 on: October 17, 2018, 05:17:17 am »
Hi KingRat
you are touching a field very interesting for me but not in this moment.
So for now I can only give you my opinion.

See documentation about SQL3 at these webpages...
https://www.sqlite.org/c3ref/intro.html
https://www.sqlite.org/c3ref/funclist.html
https://www.sqlite.org/c3ref/initialize.html
https://www.sqlite.org/c3ref/open.html
and seeing QB64 documantation about external library and C functions at these wikipages...
http://qb64.org/wiki/DECLARE_LIBRARY
http://qb64.org/wiki/DECLARE_DYNAMIC_LIBRARY
http://qb64.org/wiki/C_Libraries

and  seeing this documentation C example
Quote
01  #include <stdio.h>
02  #include <sqlite3.h>
03 
04  static int callback(void *NotUsed, int argc, char **argv, char **azColName){
05    int i;
06    for(i=0; i<argc; i++){
07      printf("%s = %s\n", azColName, argv ? argv : "NULL");
08    }
09    printf("\n");
10    return 0;
11  }
12 
13  int main(int argc, char **argv){
14    sqlite3 *db;
15    char *zErrMsg = 0;
16    int rc;
17 
18    if( argc!=3 ){
19      fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
20      return(1);
21    }
22    rc = sqlite3_open(argv[1], &db);
23    if( rc ){
24      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
25      sqlite3_close(db);
26      return(1);
27    }
28    rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
29    if( rc!=SQLITE_OK ){
30      fprintf(stderr, "SQL error: %s\n", zErrMsg);
31      sqlite3_free(zErrMsg);
32    }
33    sqlite3_close(db);
34    return 0;

I can affirm that
1. it is very useful to gain sqlite3.h to have the declaration fo type of data used in sqlite3
2. it seems better to define strictly_type the function of the DLL, so it is easier to manage a database, so why don't declare as function initSql and StopSql?
3. **ppDb is an handle to the specific dataType of database that in this documantation is undefined! So how can I manage and take informations from ppDB?

but this code seems to work to open a database Test.db with a dimension of  0 kb .

Programming isn't difficult, only it's  consuming time and coffee

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #4 on: October 17, 2018, 05:48:48 pm »
Thanks for reply my topic, TempodiBasic!!!

I´m into the sqlite documentation pages for three days now... :/

I´m trying to isolate the sqlite3 struct by hand from its source code, but the bad thing about these "opaque structs" is that the typedefs are not located at the same block....

Here is a small amount of what´s going on!

Code: QB64: [Select]
  1. typedef sqlite_int64 i64;          /* 8-byte signed integer */
  2. typedef sqlite_uint64 u64;         /* 8-byte unsigned integer */
  3. typedef UINT32_TYPE u32;           /* 4-byte unsigned integer */
  4. typedef UINT16_TYPE u16;           /* 2-byte unsigned integer */
  5. typedef INT16_TYPE i16;            /* 2-byte signed integer */
  6. typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
  7. typedef INT8_TYPE i8;
  8.  
  9. struct CollSeq {
  10.   char *zName;          /* Name of the collating sequence, UTF-8 encoded */
  11.   u8 enc;               /* Text encoding handled by xCmp() */
  12.   void *pUser;          /* First argument to xCmp() */
  13.   int (*xCmp)(void*,int, const void*, int, const void*);
  14.   void (*xDel)(void*);  /* Destructor for pUser */
  15. };
  16.  
  17. typedef void (*sqlite3_syscall_ptr)(void);
  18.  
  19. #ifdef SQLITE_INT64_TYPE
  20.   typedef SQLITE_INT64_TYPE sqlite_int64;
  21. # ifdef SQLITE_UINT64_TYPE
  22.     typedef SQLITE_UINT64_TYPE sqlite_uint64;
  23. # else  
  24.     typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  25. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  26.   typedef __int64 sqlite_int64;
  27.   typedef unsigned __int64 sqlite_uint64;
  28. #else
  29.   typedef long long int sqlite_int64;
  30.   typedef unsigned long long int sqlite_uint64;
  31. #endif
  32. typedef sqlite_int64 sqlite3_int64;
  33. typedef sqlite_uint64 sqlite3_uint64;
  34.  
  35. struct sqlite3_file {
  36.   const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
  37. };
  38.  
  39. struct sqlite3_vfs {
  40.   int iVersion;            /* Structure version number (currently 3) */
  41.   int szOsFile;            /* Size of subclassed sqlite3_file */
  42.   int mxPathname;          /* Maximum file pathname length */
  43.   sqlite3_vfs *pNext;      /* Next registered VFS */
  44.   const char *zName;       /* Name of this virtual file system */
  45.   void *pAppData;          /* Pointer to application-specific data */
  46.   int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  47.                int flags, int *pOutFlags);
  48.   int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  49.   int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  50.   int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  51.   void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  52.   void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  53.   void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  54.   void (*xDlClose)(sqlite3_vfs*, void*);
  55.   int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  56.   int (*xSleep)(sqlite3_vfs*, int microseconds);
  57.   int (*xCurrentTime)(sqlite3_vfs*, double*);
  58.   int (*xGetLastError)(sqlite3_vfs*, int, char *);
  59.   /*
  60.   ** The methods above are in version 1 of the sqlite_vfs object
  61.   ** definition.  Those that follow are added in version 2 or later
  62.   */
  63.   int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  64.   /*
  65.   ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  66.   ** Those below are for version 3 and greater.
  67.   */
  68.   int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  69.   sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  70.   const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  71.   /*
  72.   ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  73.   ** New fields may be appended in future versions.  The iVersion
  74.   ** value will increment whenever this happens.
  75.   */
  76. };
  77.  
  78. struct sqlite3 {
  79.   sqlite3_vfs *pVfs;            /* OS Interface */
  80.   struct Vdbe *pVdbe;           /* List of active virtual machines */
  81.   CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
  82.   sqlite3_mutex *mutex;         /* Connection mutex */
  83.   Db *aDb;                      /* All backends */
  84.   int nDb;                      /* Number of backends currently in use */
  85.   u32 mDbFlags;                 /* flags recording internal state */
  86.   u32 flags;                    /* flags settable by pragmas. See below */
  87.   i64 lastRowid;                /* ROWID of most recent insert (see above) */
  88.   i64 szMmap;                   /* Default mmap_size setting */
  89.   u32 nSchemaLock;              /* Do not reset the schema when non-zero */
  90.   unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */
  91.   int errCode;                  /* Most recent error code (SQLITE_*) */
  92.   int errMask;                  /* & result codes with this before returning */
  93.   int iSysErrno;                /* Errno value from last system error */
  94.   u16 dbOptFlags;               /* Flags to enable/disable optimizations */
  95.   u8 enc;                       /* Text encoding */
  96.   u8 autoCommit;                /* The auto-commit flag. */
  97.   u8 temp_store;                /* 1: file 2: memory 0: default */
  98.   u8 mallocFailed;              /* True if we have seen a malloc failure */
  99.   u8 bBenignMalloc;             /* Do not require OOMs if true */
  100.   u8 dfltLockMode;              /* Default locking-mode for attached dbs */
  101.   signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
  102.   u8 suppressErr;               /* Do not issue error messages if true */
  103.   u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
  104.   u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
  105.   u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
  106.   u8 noSharedCache;             /* True if no shared-cache backends */
  107.   u8 nSqlExec;                  /* Number of pending OP_SqlExec opcodes */
  108.   int nextPagesize;             /* Pagesize after VACUUM if >0 */
  109.   u32 magic;                    /* Magic number for detect library misuse */
  110.   int nChange;                  /* Value returned by sqlite3_changes() */
  111.   int nTotalChange;             /* Value returned by sqlite3_total_changes() */
  112.   int aLimit[SQLITE_N_LIMIT];   /* Limits */
  113.   int nMaxSorterMmap;           /* Maximum size of regions mapped by sorter */
  114.   struct sqlite3InitInfo {      /* Information used during initialization */
  115.     int newTnum;                /* Rootpage of table being initialized */
  116.     u8 iDb;                     /* Which db file is being initialized */
  117.     u8 busy;                    /* TRUE if currently initializing */
  118.     unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
  119.     unsigned imposterTable : 1; /* Building an imposter table */
  120.     unsigned reopenMemdb : 1;   /* ATTACH is really a reopen using MemDB */
  121.   } init;
  122.   int nVdbeActive;              /* Number of VDBEs currently running */
  123.   int nVdbeRead;                /* Number of active VDBEs that read or write */
  124.   int nVdbeWrite;               /* Number of active VDBEs that read and write */
  125.   int nVdbeExec;                /* Number of nested calls to VdbeExec() */
  126.   int nVDestroy;                /* Number of active OP_VDestroy operations */
  127.   int nExtension;               /* Number of loaded extensions */
  128.   void **aExtension;            /* Array of shared library handles */
  129.   int (*xTrace)(u32,void*,void*,void*);     /* Trace function */
  130.   void *pTraceArg;                          /* Argument to the trace function */
  131.   void (*xProfile)(void*,const char*,u64);  /* Profiling function */
  132.   void *pProfileArg;                        /* Argument to profile function */
  133.   void *pCommitArg;                 /* Argument to xCommitCallback() */
  134.   int (*xCommitCallback)(void*);    /* Invoked at every commit. */
  135.   void *pRollbackArg;               /* Argument to xRollbackCallback() */
  136.   void (*xRollbackCallback)(void*); /* Invoked at every commit. */
  137.   void *pUpdateArg;
  138.   void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
  139. #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  140.   void *pPreUpdateArg;          /* First argument to xPreUpdateCallback */
  141.   void (*xPreUpdateCallback)(   /* Registered using sqlite3_preupdate_hook() */
  142.     void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
  143.   );
  144.   PreUpdate *pPreUpdate;        /* Context for active pre-update callback */
  145. #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
  146. #ifndef SQLITE_OMIT_WAL
  147.   int (*xWalCallback)(void *, sqlite3 *, const char *, int);
  148.   void *pWalArg;
  149. #endif
  150.   void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
  151.   void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
  152.   void *pCollNeededArg;
  153.   sqlite3_value *pErr;          /* Most recent error message */
  154.   union {
  155.     volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
  156.     double notUsed1;            /* Spacer */
  157.   } u1;
  158.   Lookaside lookaside;          /* Lookaside malloc configuration */
  159. #ifndef SQLITE_OMIT_AUTHORIZATION
  160.   sqlite3_xauth xAuth;          /* Access authorization function */
  161.   void *pAuthArg;               /* 1st argument to the access auth function */
  162. #endif
  163. #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  164.   int (*xProgress)(void *);     /* The progress callback */
  165.   void *pProgressArg;           /* Argument to the progress callback */
  166.   unsigned nProgressOps;        /* Number of opcodes for progress callback */
  167. #endif
  168. #ifndef SQLITE_OMIT_VIRTUALTABLE
  169.   int nVTrans;                  /* Allocated size of aVTrans */
  170.   Hash aModule;                 /* populated by sqlite3_create_module() */
  171.   VtabCtx *pVtabCtx;            /* Context for active vtab connect/create */
  172.   VTable **aVTrans;             /* Virtual tables with open transactions */
  173.   VTable *pDisconnect;          /* Disconnect these in next sqlite3_prepare() */
  174. #endif
  175.   Hash aFunc;                   /* Hash table of connection functions */
  176.   Hash aCollSeq;                /* All collating sequences */
  177.   BusyHandler busyHandler;      /* Busy callback */
  178.   Db aDbStatic[2];              /* Static space for the 2 default backends */
  179.   Savepoint *pSavepoint;        /* List of active savepoints */
  180.   int busyTimeout;              /* Busy handler timeout, in msec */
  181.   int nSavepoint;               /* Number of non-transaction savepoints */
  182.   int nStatement;               /* Number of nested statement-transactions  */
  183.   i64 nDeferredCons;            /* Net deferred constraints this transaction. */
  184.   i64 nDeferredImmCons;         /* Net deferred immediate constraints */
  185.   int *pnBytesFreed;            /* If not NULL, increment this in DbFree() */
  186. #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
  187.   /* The following variables are all protected by the STATIC_MASTER
  188.   ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
  189.   **
  190.   ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
  191.   ** unlock so that it can proceed.
  192.   **
  193.   ** When X.pBlockingConnection==Y, that means that something that X tried
  194.   ** tried to do recently failed with an SQLITE_LOCKED error due to locks
  195.   ** held by Y.
  196.   */
  197.   sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */
  198.   sqlite3 *pUnlockConnection;           /* Connection to watch for unlock */
  199.   void *pUnlockArg;                     /* Argument to xUnlockNotify */
  200.   void (*xUnlockNotify)(void **, int);  /* Unlock notify callback */
  201.   sqlite3 *pNextBlocked;        /* Next in list of all blocked connections */
  202. #endif
  203. #ifdef SQLITE_USER_AUTHENTICATION
  204.   sqlite3_userauth auth;        /* User authentication information */
  205. #endif
  206. };
  207.  
  208. /* ------------------------------------------------------------------------------------------------------------------------------------*/
  209.  
  210. struct Instancia sqlite3;
  211.  
  212. int *GetInstancePtr(){
  213.         return *Instancia;
  214. }
  215.  

The function at the end is where I´ll try to send the struct pointer back to the QB64 application to be used.
But QB64 still cant compile it as a .H file cause there are more deftypes out there in the sqlite mess files..

I´will take a look at your code.

Thx!

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #5 on: October 17, 2018, 06:44:01 pm »
Yes, I got your code here
I did some experiences with sqlite3_open function but I deleted it to post here (thats the blank line in the declare library part in my code).
I´ll be playing with that again using long as ppDb, cause I was using offset.

Thanks again!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #6 on: October 18, 2018, 06:20:33 pm »
Hi KingRat
I find sqlite3.h...
now it must be converted in QB64 compatible type data

grab it here
https://github.com/LuaDist/libsqlite3/blob/master/sqlite3.h

Good Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #7 on: October 22, 2018, 03:28:21 pm »
Hi TempodiBasic!

This is the same file I posted in the first message at this topic. I was travelling, now Im back I´ll restart coding again.

Thanks again!

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #8 on: October 27, 2018, 11:13:41 am »
Just to keep the topic running.
Im still trying.... I tryed some C/C++ stuff at a .H file....
I´ve downloaded the amalgmation version of sqlite3 to embed it on the aplication but the C++ compiler behind qb64 returns that there were a #endif without a #if...

The following code is a scrap that Im using to try to work with the DLL, I wrote a simple function to return the actual error returned by the DLL functions.

If someone knows how to deal with it please reply!

Code: QB64: [Select]
  1.     FUNCTION StartSqlite% ALIAS sqlite3_initialize ()
  2.     FUNCTION StopSqlite% ALIAS sqlite3_shutdown ()
  3.     FUNCTION SqliteLibVersion& ALIAS sqlite3_libversion_number ()
  4.     FUNCTION OpenDb% ALIAS sqlite3_open (filename AS STRING, ppDb AS _OFFSET)
  5.     FUNCTION CloseDb% ALIAS sqlite3_close ()                        
  6.    'FUNCTION SqliteExec& ALIAS sqlite3_exec (sqlite3 AS _OFFSET, sql AS STRING, CbackPtr AS _UNSIGNED LONG, Vd AS LONG, errmsg AS STRING) ' This one needs a callback function.
  7.     FUNCTION Prepare% ALIAS sqlite3_prepare_v2 (Db AS _OFFSET, zSql AS STRING, nByte AS INTEGER, stmt AS _OFFSET, pzTail AS _OFFSET) ' instead of using sqlite3_exec() witch is a convenience wrapper, we can compile query statement using this funcion an then execute it using step(), this is the way Im going...
  8.  
  9. '-------------------------------------------------------------------------------------------------------------------------------------------------
  10.  
  11. PRINT "Start DB engine"
  12. PRINT ResultCode(StartSqlite)
  13.  
  14. Db = _OFFSET(DbVar)
  15.  
  16. PRINT "Open DB"
  17. PRINT ResultCode(OpenDb%("tst.db", Db))
  18.  
  19. 'CPtr = _OFFSET(C)
  20.  
  21. DIM QueryStr AS STRING * 256
  22. DIM QueryPtr AS _OFFSET
  23. QueryStr = "CREATE TABLE Teste(Id Int, Nome Varchar)"
  24. QueryPtr = _OFFSET(QueryStr)
  25.  
  26. DIM Stmt AS LONG
  27. DIM Tail AS LONG
  28.  
  29. PRINT "Query preparation."
  30. PRINT ResultCode(Prepare(Db, QueryStr, 256, QueryPtr, Tail))
  31.  
  32. PRINT "Close DB"
  33. PRINT ResultCode(CloseDb%)  ' Here we should pass ppDb as a reference of the DB to be closed by sqlite3_close(), I´ve tryed LONG, _UNSIGNED LONG and _OFFSET but it still returns Sqlite3 Misuse, leaving empty returns OK
  34.  
  35. PRINT "Stop DB engine"
  36. PRINT ResultCode(StopSqlite)
  37.  
  38.  
  39.  
  40.  
  41.  
  42. FUNCTION ResultCode$ (Code AS INTEGER)
  43.  
  44.     SELECT CASE Code
  45.  
  46.         CASE 0
  47.             ResultCode$ = "SQLITE_OK"
  48.         CASE 1
  49.             ResultCode$ = "SQLITE_ERROR"
  50.         CASE 2
  51.             ResultCode$ = "SQLITE_INTERNAL"
  52.         CASE 3
  53.             ResultCode$ = "SQLITE_PERM"
  54.         CASE 4
  55.             ResultCode$ = "SQLITE_ABORT"
  56.         CASE 5
  57.             ResultCode$ = "SQLITE_BUSY"
  58.         CASE 6
  59.             ResultCode$ = "SQLITE_LOCKED"
  60.         CASE 7
  61.             ResultCode$ = "SQLITE_NOMEM"
  62.         CASE 8
  63.             ResultCode$ = "SQLITE_READONLY"
  64.         CASE 9
  65.             ResultCode$ = "SQLITE_INTERRUPT"
  66.         CASE 10
  67.             ResultCode$ = "SQLITE_IOERR"
  68.         CASE 11
  69.             ResultCode$ = "SQLITE_CORRUPT"
  70.         CASE 12
  71.             ResultCode$ = "SQLITE_NOTFOUND"
  72.         CASE 13
  73.             ResultCode$ = "SQLITE_FULL"
  74.         CASE 14
  75.             ResultCode$ = "SQLITE_CANTOPEN"
  76.         CASE 15
  77.             ResultCode$ = "SQLITE_PROTOCOL"
  78.         CASE 16
  79.             ResultCode$ = "SQLITE_EMPTY"
  80.         CASE 17
  81.             ResultCode$ = "SQLITE_SCHEMA"
  82.         CASE 18
  83.             ResultCode$ = "SQLITE_TOOBIG"
  84.         CASE 19
  85.             ResultCode$ = "SQLITE_CONSTRAINT"
  86.         CASE 20
  87.             ResultCode$ = "SQLITE_MISMATCH"
  88.         CASE 21
  89.             ResultCode$ = "SQLITE_MISUSE"
  90.         CASE 22
  91.             ResultCode$ = "SQLITE_NOLFS"
  92.         CASE 23
  93.             ResultCode$ = "SQLITE_AUTH"
  94.         CASE 24
  95.             ResultCode$ = "SQLITE_FORMAT"
  96.         CASE 25
  97.             ResultCode$ = "SQLITE_RANGE"
  98.         CASE 26
  99.             ResultCode$ = "SQLITE_NOTADB"
  100.         CASE 27
  101.             ResultCode$ = "SQLITE_NOTICE"
  102.         CASE 28
  103.             ResultCode$ = "SQLITE_WARNING"
  104.         CASE 100
  105.             ResultCode$ = "SQLITE_ROW"
  106.         CASE 101
  107.             ResultCode$ = "SQLITE_DONE"
  108.  
  109.     END SELECT
  110.  
  111.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #9 on: October 27, 2018, 01:24:29 pm »
Hi KingRat
do you run for Halloween Challenge? https://www.qb64.org/forum/index.php?topic=694.0
It lasts only 4 days....
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #10 on: October 27, 2018, 01:49:52 pm »
About your issue...

1. the error comes up from the
Quote
DIM QueryStr AS STRING * 256
DIM QueryPtr AS _OFFSET
QueryStr = "CREATE TABLE Teste(Id Int, Nome Varchar)"
QueryPtr = _OFFSET(QueryStr)

DIM Stmt AS LONG
DIM Tail AS LONG

PRINT "Query preparation."
PRINT ResultCode(Prepare(Db, QueryStr, 256, QueryPtr, Tail))

My feedback is limited because I don't know SQL.... but I see two issues
 1. has QueryStr a right SQL command into it?
 2. is possible to make a query with a void database?

About theory...https://www.sqlite.org/c3ref/prepare.html
we can focus on this
Quote
int sqlite3_prepare_v2(
  sqlite3 *db,            /* Database handle */
  const char *zSql,       /* SQL statement, UTF-8 encoded */
  int nByte,              /* Maximum length of zSql in bytes. */
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
);
so I can understand that QueryStr must be a valid SQLStatement UTF-8 encoded....

but I need time to study.... https://www.sqlite.org/lang_createtable.html
So that is all for now...

Programming isn't difficult, only it's  consuming time and coffee

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #11 on: October 27, 2018, 03:22:10 pm »
Hi Tempo!

Quote
Hi KingRat
do you run for Halloween Challenge? https://www.qb64.org/forum/index.php?topic=694.0
It lasts only 4 days....
No man! I´m not running. I think I´m not good enought to these kind of stuff... I mean, I´ll not bring anything new to the table...

Quote
1. has QueryStr a right SQL command into it?
Yes!
That query come from a query example I found at sqlite site.
And I´ve tryied both ways, sending the string offset QueryPtr and sending the string itself QueryStr.

Quote
2. is possible to make a query with a void database?
I think we can use a query into a void database to create tables (this is my for now) to start working with it.

Thanks again brother!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #12 on: October 28, 2018, 08:09:22 am »
Programming isn't difficult, only it's  consuming time and coffee

Offline KingRat

  • Newbie
  • Posts: 16
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #13 on: November 01, 2018, 07:04:04 pm »
Hi Folks!

Quote
Tuning on the error
https://sqliteviewer.com/blog/how-to-fix-sqlite-error-code-21/

The text still brings me to the sqlite3*, the same stuff I was trying to figure out...

Quote
Would it help to use a tool such as dllexp.exe from Nirsoft to view the exported functions? I think the tool can look into the DLL in further detail, perhaps the information you need can be extracted from using dllexp.exe or pelook.exe or some other DLL dumping tool?

Nice output you got, thanks! But the functions that the DLL exports isn´t the actual problem, aswe have the source code, but the way to deal with it in a QB64 code.
Cause qb64 dont support callback functions and que need to point to a sqlite3 struct....

Im still trying in my spare time, I need such a exercise to came back to programming and stuff and I think a sqlite3 will be a nice feature for this nice language..

Thanks!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: I need some help with Sqlite3 DLL, plz.
« Reply #14 on: November 10, 2018, 04:01:10 pm »
Yes I agree
sqlite3 may be a nice addon for QB64.
Programming isn't difficult, only it's  consuming time and coffee