It looks all as it should work and it compiles with the same number of warnings, but I get a bad dll calling convention in VB with the extra integer argument iFields.
This is the altered .c source file: #include "vbsql.h" int NumberofRowsReturned=0; int _stdcall number_of_rows_from_last_call(void) { return NumberofRowsReturned; } SAFEARRAY * __stdcall sqlite_get_table( sqlite3 *db, /* The database on which the SQL executes */ const char *zSql, /* The SQL to be executed */ BSTR *ErrMsg, /* Write error messages here */ int iFields) /* if 1 then include headers in the array, if 0 then not /* Return the SAFEARRAY */ { // Temp result fields char **SQL_Results; char *ErrMessage= 0; int NumberofCols; int NumberRows; int rc; SAFEARRAY *resultp=NULL; NumberofRowsReturned=0; rc=sqlite3_get_table( db, zSql, &SQL_Results, &NumberRows, &NumberofCols, &ErrMessage); if( rc==SQLITE_OK ) { NumberofRowsReturned=NumberRows; if (NumberofCols> 0 ) { //We have a resultset so transform this into a SAFEARRAY // Create SAFEARRAY SAFEARRAYBOUND SA_Bounds[2]; //SAFEARRAY FAR* resultp = NULL; BSTR bstrTemporyStringHolder = NULL; VARIANT tmpVariant; BSTR bstr1 = NULL; HRESULT hr; LPOLESTR* TempWideDataHolder = NULL; ULONG WideCharacterLength; ULONG intCurrentColumn ; // Tempory counter for looping ULONG intCurrentRow ; // Tempory counter for looping ULONG sqlite_return_array_int=0; TempWideDataHolder = CoTaskMemAlloc(1); // Set up array bounds SA_Bounds[0].cElements = NumberRows + iFields; SA_Bounds[0].lLbound = 0; SA_Bounds[1].cElements = NumberofCols; SA_Bounds[1].lLbound = 0; //Create array resultp = SafeArrayCreate(VT_VARIANT, 2, SA_Bounds); // Start Place column headers in first row if (iFields == 1) { for (intCurrentColumn=0;intCurrentColumn< (ULONG)NumberofCols ;intCurrentColumn++) { long indices[] = {0,intCurrentColumn}; VariantInit(&tmpVariant); // Start Convert to unicode WideCharacterLength=strlen(SQL_Results[intCurrentColumn]) + 1 ; *TempWideDataHolder = (LPOLESTR) CoTaskMemAlloc(WideCharacterLength*2); MultiByteToWideChar( CP_ACP, 0, SQL_Results[intCurrentColumn], strlen(SQL_Results[intCurrentColumn])+1, *TempWideDataHolder, WideCharacterLength ); //Convert the VT_Object element to the BSTR - Here we may change if SQLite type casts tmpVariant.bstrVal=SysAllocString(*TempWideDataHolder); V_VT(&tmpVariant) = VT_BSTR; CoTaskMemFree(*TempWideDataHolder); // End convert to unicode // Safearray Column headers hr = SafeArrayPutElement(resultp, indices, &tmpVariant); SysFreeString(tmpVariant.bstrVal); VariantClear(&tmpVariant); } } // End Place column headers in first row // Start Loop through array and fill SAFEARRAY for (intCurrentRow=iFields;intCurrentRow<=(ULONG)NumberRows ;intCurrentRow++) { for (intCurrentColumn=0;intCurrentColumn< (ULONG)NumberofCols ;intCurrentColumn++) { long indices[] = {intCurrentRow , intCurrentColumn}; // set return array index VariantInit(&tmpVariant); sqlite_return_array_int= (intCurrentRow * (ULONG)NumberofCols) + intCurrentColumn ; // Start Convert to unicode if (SQL_Results[sqlite_return_array_int]) { WideCharacterLength=strlen(SQL_Results[sqlite_return_array_int]) + 1 ; *TempWideDataHolder= (LPOLESTR) CoTaskMemAlloc(WideCharacterLength*2); MultiByteToWideChar( CP_ACP, 0, SQL_Results[sqlite_return_array_int], strlen(SQL_Results[sqlite_return_array_int])+1, *TempWideDataHolder, WideCharacterLength ); //Convert the VT_Object element to the BSTR - Here we may change if SQLite type casts tmpVariant.bstrVal=SysAllocString(*TempWideDataHolder); V_VT(&tmpVariant) = VT_BSTR; CoTaskMemFree(*TempWideDataHolder); // End convert to unicode hr = SafeArrayPutElement(resultp, indices, &tmpVariant); SysFreeString(tmpVariant.bstrVal); VariantClear(&tmpVariant); } } } // END Loop through array and fill SAFEARRAY } } else { *ErrMsg = SysAllocStringByteLen( ErrMessage,strlen( ErrMessage) ); } sqlite3_free(ErrMessage); sqlite3_free_table(SQL_Results); return resultp; } BSTR __stdcall sqlite_libversion() { return SysAllocStringByteLen( VB_SQLITE_VERSION,strlen( VB_SQLITE_VERSION) ); } And this is the altered .h file: #include <windows.h> #include <stdio.h> #include <io.h> #include <oleauto.h> #include <wtypes.h> #include "sqlite3.h" #define VB_SQLITE_VERSION "3.3.13" /* Source Code Version */ SAFEARRAY * __stdcall sqlite_get_table(sqlite3 * , const char *, BSTR *, int); BSTR __stdcall sqlite_libversion(void); int __stdcall number_of_rows_from_last_call(void); And this my function in VB: Private Declare Function sqlite_get_table _ Lib "SQLite3VB.dll" _ (ByVal DB_Handle As Long, _ ByVal SQLString As String, _ ByRef ErrStr As String, ByVal iFields As Long) As Variant() Have tried ByRef iFields as long as well, but same error. Any obvious mistakes here? I know this is not that much to do with SQLite, but maybe it is something simple I am doing wrong and somebody could tell me, other than that I should learn C first. RBS -----Original Message----- From: RB Smissaert [mailto:[EMAIL PROTECTED] Sent: 06 March 2007 23:14 To: sqlite-users@sqlite.org Subject: RE: [sqlite] What is wrong with this simple query (offset)? OK, forget about this, I think I am nearly there. RBS -----Original Message----- From: RB Smissaert [mailto:[EMAIL PROTECTED] Sent: 06 March 2007 22:42 To: sqlite-users@sqlite.org Subject: RE: [sqlite] What is wrong with this simple query (offset)? Could I ask if somebody could tell me how I add an optional Boolean argument to this: SAFEARRAY * __stdcall sqlite_get_table( sqlite3 *db, /* The database on which the SQL executes */ const char *zSql, /* The SQL to be executed */ BSTR *ErrMsg /* Write error messages here */ ) /* Return the SAFEARRAY */ I had a go, but I know nil about C and it isn't that simple. Once I have the Boolean argument (variable) I probably manage to do the if To either put the fields in the array or leave them out. RBS -----Original Message----- From: RB Smissaert [mailto:[EMAIL PROTECTED] Sent: 06 March 2007 21:45 To: sqlite-users@sqlite.org Subject: RE: [sqlite] What is wrong with this simple query (offset)? Yes, I can see now where this happens: TempWideDataHolder = CoTaskMemAlloc(1); // Set up array bounds SA_Bounds[0].cElements = NumberRows + 1; SA_Bounds[0].lLbound = 0; SA_Bounds[1].cElements = NumberofCols; SA_Bounds[1].lLbound = 0; //Create array resultp = SafeArrayCreate(VT_VARIANT, 2, SA_Bounds); // Start Place column headers in first row for (intCurrentColumn=0;intCurrentColumn< (ULONG)NumberofCols ;intCurrentColumn++) { long indices[] = {0,intCurrentColumn}; VariantInit(&tmpVariant); // Start Convert to unicode WideCharacterLength=strlen(SQL_Results[intCurrentColumn]) + 1 ; *TempWideDataHolder = (LPOLESTR) CoTaskMemAlloc(WideCharacterLength*2); MultiByteToWideChar( CP_ACP, 0, SQL_Results[intCurrentColumn], strlen(SQL_Results[intCurrentColumn])+1, *TempWideDataHolder, WideCharacterLength ); //Convert the VT_Object element to the BSTR - Here we may change if SQLite type casts tmpVariant.bstrVal=SysAllocString(*TempWideDataHolder); V_VT(&tmpVariant) = VT_BSTR; CoTaskMemFree(*TempWideDataHolder); // End convert to unicode // Safearray Column headers hr = SafeArrayPutElement(resultp, indices, &tmpVariant); SysFreeString(tmpVariant.bstrVal); VariantClear(&tmpVariant); } // End Place column headers in first row // Start Loop through array and fill SAFEARRAY for (intCurrentRow=1;intCurrentRow<=(ULONG)NumberRows ;intCurrentRow++) { for (intCurrentColumn=0;intCurrentColumn< (ULONG)NumberofCols ;intCurrentColumn++) { long indices[] = {intCurrentRow , intCurrentColumn}; // set return array index VariantInit(&tmpVariant); sqlite_return_array_int= (intCurrentRow * (ULONG)NumberofCols) + intCurrentColumn ; // Start Convert to unicode if (SQL_Results[sqlite_return_array_int]) { WideCharacterLength=strlen(SQL_Results[sqlite_return_array_int]) + 1 ; *TempWideDataHolder= (LPOLESTR) CoTaskMemAlloc(WideCharacterLength*2); MultiByteToWideChar( CP_ACP, 0, SQL_Results[sqlite_return_array_int], strlen(SQL_Results[sqlite_return_array_int])+1, *TempWideDataHolder, WideCharacterLength ); //Convert the VT_Object element to the BSTR - //Here we may change if SQLite type casts tmpVariant.bstrVal=SysAllocString(*TempWideDataHolder); V_VT(&tmpVariant) = VT_BSTR; CoTaskMemFree(*TempWideDataHolder); // End convert to unicode hr = SafeArrayPutElement(resultp, indices, &tmpVariant); SysFreeString(tmpVariant.bstrVal); VariantClear(&tmpVariant); } } } // END Loop through array and fill SAFEARRAY } } else { *ErrMsg = SysAllocStringByteLen( ErrMessage,strlen( ErrMessage) ); } Now I will have to figure out how to re-code this. RBS -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 06 March 2007 21:22 To: sqlite-users@sqlite.org Subject: Re: [sqlite] What is wrong with this simple query (offset)? "RB Smissaert" <[EMAIL PROTECTED]> wrote: > Ah, thanks. > I am not using the sqlite3 command line utility, but a VB adapted version of > the regular sqlite3.dll. I take it should be no problem to do the same with > that. Is there a pragma for this? > No. The returning of field names is going to be a function of your VB interface layer. The SQLite core does not do this unless requested - which means that your VB interface is requesting it. So turning of the field names is going to be some sort of call into your VB interface, not into the SQLite core. -- D. Richard Hipp <[EMAIL PROTECTED]> ---------------------------------------------------------------------------- - To unsubscribe, send email to [EMAIL PROTECTED] ---------------------------------------------------------------------------- - ---------------------------------------------------------------------------- - To unsubscribe, send email to [EMAIL PROTECTED] ---------------------------------------------------------------------------- - ---------------------------------------------------------------------------- - To unsubscribe, send email to [EMAIL PROTECTED] ---------------------------------------------------------------------------- - ---------------------------------------------------------------------------- - To unsubscribe, send email to [EMAIL PROTECTED] ---------------------------------------------------------------------------- - ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------