From 1ebf0fee92578277a64649ce259f998e30b325d6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 4 Jun 2008 12:09:26 +0000 Subject: [PATCH] 2008-06-04 14:02 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * contrib/hbsqlit3/hbsqlit3.c % Removed __XHARBOUR__ guards. * Minor cleanups. * contrib/hbsqlit2/hbsqlit2.c % Major cleanup, formatting, optimizations. ! INCOMPATIBLE: public vars prefixed with 'hb_sqlite2_'. --- harbour/ChangeLog | 9 + harbour/contrib/hbsqlit2/hbsqlit2.c | 490 +++++++++++----------------- harbour/contrib/hbsqlit3/hbsqlit3.c | 125 ++----- 3 files changed, 224 insertions(+), 400 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7a26d1e323..6d13478795 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,15 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-04 14:02 UTC+0100 Viktor Szakats (harbour.01 syenar hu) + * contrib/hbsqlit3/hbsqlit3.c + % Removed __XHARBOUR__ guards. + * Minor cleanups. + + * contrib/hbsqlit2/hbsqlit2.c + % Major cleanup, formatting, optimizations. + ! INCOMPATIBLE: public vars prefixed with 'hb_sqlite2_'. + 2008-06-04 11:41 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * include/hbver.h + Added HB_VERSION unified version identifier: diff --git a/harbour/contrib/hbsqlit2/hbsqlit2.c b/harbour/contrib/hbsqlit2/hbsqlit2.c index 36eeff1cd1..9bacbde7cc 100644 --- a/harbour/contrib/hbsqlit2/hbsqlit2.c +++ b/harbour/contrib/hbsqlit2/hbsqlit2.c @@ -4,21 +4,21 @@ /* *------------------------------------------------------------------------ - * HARBOUR INTERFACE for SQLITE + * HARBOUR INTERFACE for SQLITE *------------------------------------------------------------------------ * * Copyright 2003 Alejandro de Gárate * * License: General Public License (GNU) - * + * * Developed using: - * Harbour 0.42 or upper - * Borland C++ BCC 5.5.1 + * Harbour 0.42 or upper + * Borland C++ BCC 5.5.1 * * History: * * Ver 0.40 30 December 2003 Fixed an opening error not detected - * It seems is a problem with BCC compiler. + * It seems is a problem with BCC compiler. * If "xxFile" database is not found, an empty file is * created with the same name, given an incorrect signal * to FILE() function. File is empty but exists (Oh man...) @@ -52,9 +52,6 @@ // NOTE: we need this to prevent base types redefinition #define _CLIPDEFS_H -#if defined(HB_OS_WIN_32_USED) - #include -#endif #include "hbapi.h" #include "extend.api" @@ -69,435 +66,324 @@ #include "sqliteInt.h" // PUBLIC VARS - sqlite *db ; // public by ale - char * szErrMsg = 0; - int iLastErrCode = 0; // for use in foreign languages (translate msg) - +sqlite * hb_sqlite2_db; // public by ale +char * hb_sqlite2_szErrMsg = NULL; +int hb_sqlite2_iLastErrCode = 0; // for use in foreign languages (translate msg) // public (temporary) buffer till I can find a better approach -char * aDataRows[ 1024]; -char * aDataCols[ 255]; -int iDataRows = 0; // records -int iDataCols = 0; // fields - +char * hb_sqlite2_aDataRows[ 1024 ]; +char * hb_sqlite2_aDataCols[ 255 ]; +int hb_sqlite2_iDataRows = 0; // records +int hb_sqlite2_iDataCols = 0; // fields //-------------------------------------------------------------------------- -static int callback(void *NotUsed, int argc, char **argv, char **azColName) +static int callback( void * NotUsed, int argc, char ** argv, char ** azColName ) //-------------------------------------------------------------------------- // INTERNAL DO NOT TOUCH !!! //--------------------------------------------------------------------------- { - int i; + int i; - // in arg is the number of data fields for each row -// printf("argc =>%d\n", argc); + // in arg is the number of data fields for each row +// printf("argc =>%d\n", argc); - HB_SYMBOL_UNUSED( NotUsed ); - HB_SYMBOL_UNUSED( argv ); - HB_SYMBOL_UNUSED( azColName ); + HB_SYMBOL_UNUSED( NotUsed ); + HB_SYMBOL_UNUSED( argv ); + HB_SYMBOL_UNUSED( azColName ); - for( i=0; i < argc; i++) - { -// printf(">>> %s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); -// aDataCols[i] = azColName[i]; // en realidad copiar cadena a cadena -// aDataRows[i] = argv[i]; - } -// printf("\n"); - return 0; + for( i = 0; i < argc; i++) + { +// printf(">>> %s = %s\n", azColName[ i ], argv[ i ] ? argv[ i ] : "NULL" ); +// hb_sqlite2_aDataCols[ i ] = azColName[ i ]; // en realidad copiar cadena a cadena +// hb_sqlite2_aDataRows[ i ] = argv[ i ]; + } +// printf("\n"); + + return 0; } - //---------------------- - HB_FUNC( SQLITE_ERROR ) +HB_FUNC( SQLITE_ERROR ) //-------------------------------------------------------------------------- // Returns a string explaining last error //-------------------------------------------------------------------------- { - if( szErrMsg ) - hb_retc( szErrMsg ); - else - hb_ret(); + if( hb_sqlite2_szErrMsg ) + hb_retc( hb_sqlite2_szErrMsg ); } - //---------------------- - HB_FUNC( SQLITE_OPEN ) // sqlite * = sqlite_open(argv[1], 0, &zErrMsg); +HB_FUNC( SQLITE_OPEN ) // sqlite * = sqlite_open( argv[ 1 ], 0, &zErrMsg ); //-------------------------------------------------------------------------- // Open a database file (in SQLite format) and set a public structure //-------------------------------------------------------------------------- { char * szDB = hb_parc( 1 ); - int iMode = 0; // hb_parni( 2 ); + int iMode = 0; // hb_parni( 2 ); HB_SYMBOL_UNUSED( iMode ); - // db is a public var (by ale) - db = (sqlite *) sqlite_open( szDB, 0, &szErrMsg); + // hb_sqlite2_db is a public var (by ale) + hb_sqlite2_db = ( sqlite * ) sqlite_open( szDB, 0, &hb_sqlite2_szErrMsg ); // It seems Borland BCC55 do not return a correct pointer to a sqlite // struc, thus I can't check if database was successfully open :( -// (sqlite *) -// printf("\n %lu ", db->flags, ); +// ( sqlite * ) +// printf("\n %lu ", hb_sqlite2_db->flags, ); - if( db == 0 ) - { - hb_retni( 1 ); // error! - } - else - hb_retni( 0 ); // successful + hb_retni( hb_sqlite2_db == 0 ? 1 : 0 ); // error: 1 } - //----------------------- - HB_FUNC( SQLITE_QUERY ) +HB_FUNC( SQLITE_QUERY ) //-------------------------------------------------------------------------- // Execute a query over the passed table //-------------------------------------------------------------------------- { - int rc, iResRows =0, iResCols =0, i, iRec, iField; - char * szSQLcom = hb_parc( 1 ); - char * pErrmsg ; - char ** pResStr ; - PHB_ITEM paRows; // PHB_ITEM is the Harbour equivalent of Clipper ITEM - PHB_ITEM paCols; - PHB_ITEM ptemp; - iDataRows = 0; // reset global records - iDataCols = 0; // reset global fields + int rc, iResRows = 0, iResCols = 0, i, iRec, iField; + char * szSQLcom = hb_parc( 1 ); + char * pErrmsg; + char ** pResStr; + PHB_ITEM paRows; // PHB_ITEM is the Harbour equivalent of Clipper ITEM + PHB_ITEM paCols; - // reset temporary store - for( i=0; i< 255; i++) - aDataCols [i] = 0L; + hb_sqlite2_iDataRows = 0; // reset global records + hb_sqlite2_iDataCols = 0; // reset global fields - for( i=0; i< 1024; i++) - aDataRows [i] = 0L; + // reset temporary store + for( i = 0; i < 255; i++) + hb_sqlite2_aDataCols[ i ] = 0L; - rc = sqlite_exec( db, szSQLcom, callback, 0, &szErrMsg); + for( i = 0; i < 1024; i++) + hb_sqlite2_aDataRows[ i ] = 0L; - // Check the operation's result - if( rc != SQLITE_OK ) - { - iLastErrCode = rc; // set last error - hb_retc( "" ); // return last error also - return; - } + rc = sqlite_exec( hb_sqlite2_db, szSQLcom, callback, 0, &hb_sqlite2_szErrMsg ); -// else -// { - // put here a routine to process results - sqlite_get_table( db, /* An open database */ - szSQLcom, /* SQL to be executed */ - &pResStr, /* Result written to a char *[] that this points to */ - &iResRows, /* Number of result rows written here */ - &iResCols, /* Number of result columns written here */ - &pErrmsg /* Error msg written here */ - ); - - // global results - iDataRows = iResRows; // set rows from last operation - iDataCols = iResCols; // set cols from last operation - - - // ------------------------------------------------------------------ - // quiero devolver un array bidimensional donde la cantidad de filas - // es rows +1 (ó reccords +1 ) y las columnas los campos - // la primer fila contiene los encabezados de los campos -/* - i=0; - for( iRec=0; iRec < iResRows+1; iRec++) - { - for( iField=0; iField < iResCols; iField++) - { - printf("%s\t", ((pResStr)[i]) ); - i++; - } - printf("\n"); - } -*/ - // -------- dimension rows array ------------------------------- - paRows = hb_itemArrayNew( iResRows + 1 ); - i = 0; - - for( iRec=0; iRec < iResRows+1; iRec++) + // Check the operation's result + if( rc == SQLITE_OK ) { + // put here a routine to process results + sqlite_get_table( hb_sqlite2_db, /* An open database */ + szSQLcom, /* SQL to be executed */ + &pResStr, /* Result written to a char *[] that this points to */ + &iResRows, /* Number of result rows written here */ + &iResCols, /* Number of result columns written here */ + &pErrmsg /* Error msg written here */ + ); - // ---------- if it's a multidimensional array -------------------- - if( iResCols > 1) - { - paCols = hb_itemArrayNew( iResCols ); + // global results + hb_sqlite2_iDataRows = iResRows; // set rows from last operation + hb_sqlite2_iDataCols = iResCols; // set cols from last operation - // for every field - for( iField=0; iField < iResCols; iField++) + // ------------------------------------------------------------------ + // quiero devolver un array bidimensional donde la cantidad de filas + // es rows +1 (ó reccords +1 ) y las columnas los campos + // la primer fila contiene los encabezados de los campos +/* + for( iRec = 0, i = 0; iRec < iResRows + 1; iRec++ ) + { + for( iField = 0; iField < iResCols; iField++, i++ ) + printf("%s\t", (pResStr)[ i ] ); + + printf("\n"); + } +*/ + // -------- dimension rows array ------------------------------- + paRows = hb_itemArrayNew( iResRows + 1 ); + i = 0; + + for( iRec = 0; iRec < iResRows + 1; iRec++ ) + { + // ---------- if it's a multidimensional array -------------------- + if( iResCols > 1 ) { - // if field is not empty + paCols = hb_itemArrayNew( iResCols ); - if( ((pResStr)[i]) != NULL) - ptemp = hb_itemPutC( NULL, ((pResStr)[i]) ); - else - ptemp = hb_itemPutC( NULL, ""); + // for every field + for( iField = 0; iField < iResCols; iField++ ) + { + hb_arraySetC( paCols, iField + 1, ( pResStr )[ i ] ? ( pResStr )[ i ] : NULL ); + i++; + } - // put data onto subarray of fields - hb_itemArrayPut( paCols, iField + 1, ptemp); - hb_itemRelease( ptemp ); - i++; // point to next data + // put data onto subarray of records + hb_itemArrayPut( paRows, iRec + 1, paCols); + hb_itemRelease( paCols ); + } + else + { + // ---------- is an unidimensional array ----------------------------- + hb_arraySetC( paRows, iRec + 1, ( pResStr )[ i ] ? ( pResStr )[ i ] : NULL ); + i++; + } + } - } //endfor internal + // free memory allocated + sqlite_free_table( pResStr ); - // put data onto subarray of records - hb_itemArrayPut( paRows, iRec + 1, paCols); - hb_itemRelease( paCols ); - } - else - { - // ---------- is an unidimensional array ----------------------------- - - if( ((pResStr)[i]) != NULL) - ptemp = hb_itemPutC( NULL, ((pResStr)[i]) ); - else - ptemp = hb_itemPutC( NULL, ""); - - // put data onto subarray of records - hb_itemArrayPut( paRows, iRec + 1, ptemp); - hb_itemRelease( ptemp ); - i++; // point to next data - } - - }//endfor extern - - // free memory allocated - sqlite_free_table( pResStr ); - -// } // endif check - - hb_itemReturn( paRows ); // final, return to harbour & release - hb_itemRelease( paRows ); + hb_itemReturn( paRows ); // final, return to harbour & release + hb_itemRelease( paRows ); + } + else + { + hb_sqlite2_iLastErrCode = rc; // set last error + hb_retc_null(); // return last error also + } } - //---------------------- - HB_FUNC( SQLITE_CLOSE ) // void sqlite_close(sqlite *db) +HB_FUNC( SQLITE_CLOSE ) // void sqlite_close( sqlite * hb_sqlite2_db ) //-------------------------------------------------------------------------- // Close currently open database //-------------------------------------------------------------------------- { - sqlite_close( db ); // db is public - hb_ret(); + sqlite_close( hb_sqlite2_db ); } - //---------------------- - HB_FUNC( SQLITE_INFO ) +HB_FUNC( SQLITE_INFO ) //-------------------------------------------------------------------------- // Returns information about current SQLite package //-------------------------------------------------------------------------- { - hb_reta(3); - hb_storc( (char *) SQLITE_VERSION, -1, 1); - hb_storc( (char *) sqlite_libversion(), -1, 2); - hb_storc( (char *) sqlite_libencoding(), -1, 3); + hb_reta( 3 ); + hb_storc( ( char * ) SQLITE_VERSION, -1, 1 ); + hb_storc( ( char * ) sqlite_libversion(), -1, 2 ); + hb_storc( ( char * ) sqlite_libencoding(), -1, 3 ); } - //------------------------- - HB_FUNC( SQLITE_GETROWS ) +HB_FUNC( SQLITE_GETROWS ) //-------------------------------------------------------------------------- // Returns the number of rows resulting from last operation //-------------------------------------------------------------------------- { - hb_retni( iDataRows ); + hb_retni( hb_sqlite2_iDataRows ); } - //------------------------ - HB_FUNC( SQLITE_GETCOLS ) +HB_FUNC( SQLITE_GETCOLS ) //-------------------------------------------------------------------------- // Returns the number of columns resulting from last operation //-------------------------------------------------------------------------- { - hb_retni( iDataCols ); + hb_retni( hb_sqlite2_iDataCols ); } - //------------------------ - HB_FUNC( SQLITE_EXECUTE ) +HB_FUNC( SQLITE_EXECUTE ) //-------------------------------------------------------------------------- // Execute a statment (not a query) over the database //-------------------------------------------------------------------------- { - int rc, iResRows =0, iResCols =0, i; // , iRec, iField; - char * szSQLcom = hb_parc( 1 ); -//char * pErrmsg ; + int rc, i; // , iRec, iField; + char * szSQLcom = hb_parc( 1 ); - HB_SYMBOL_UNUSED( iResCols ); - HB_SYMBOL_UNUSED( iResRows ); + hb_sqlite2_iDataRows = 0; // reset global records + hb_sqlite2_iDataCols = 0; // reset global fields - iDataRows = 0; // reset global records - iDataCols = 0; // reset global fields + // reset temporary store + for( i = 0; i < 255; i++ ) + hb_sqlite2_aDataCols[ i ] = 0L; - // reset temporary store - for( i=0; i< 255; i++) - aDataCols [i] = 0L; + for( i = 0; i < 1024; i++ ) + hb_sqlite2_aDataRows[ i ] = 0L; - for( i=0; i< 1024; i++) - aDataRows [i] = 0L; + rc = sqlite_exec( hb_sqlite2_db, szSQLcom, callback, 0, &hb_sqlite2_szErrMsg ); - rc = sqlite_exec( db, szSQLcom, callback, 0, &szErrMsg); - - // Check the operation's result - if( rc != SQLITE_OK ) - { - iLastErrCode = rc; // set last error - hb_retni( rc ); // return last error also - } + // Check the operation's result + if( rc != SQLITE_OK ) + { + hb_sqlite2_iLastErrCode = rc; // set last error + hb_retni( rc ); // return last error also + } } - //--------------------------- - HB_FUNC( SQLITE_SYSCOLUMNS ) +HB_FUNC( SQLITE_SYSCOLUMNS ) //-------------------------------------------------------------------------- // Returns an unidimensional array with FIELD NAMES only //-------------------------------------------------------------------------- { - sqlite *pDB = db ; - struct Table * pTable; - const char * szName = hb_parc( 1 ); - int iField; - PHB_ITEM paRows; // PHB_ITEM is the Harbour equivalent of Clipper ITEM - PHB_ITEM paCols; - PHB_ITEM ptemp; + struct Table * pTable = ( struct Table * ) sqliteFindTable( hb_sqlite2_db, ( const char * ) hb_parc( 1 ), 0 ); - pTable = (struct Table *) sqliteFindTable( pDB, szName, 0 ); + if( pTable ) + { + int iField; + PHB_ITEM paRows; // PHB_ITEM is the Harbour equivalent of Clipper ITEM + PHB_ITEM paCols; - if( pTable ) - { // -------- dimension rows array ------------------------------- paRows = hb_itemArrayNew( 2 + pTable->nCol ); // 1 is table name // 2 is field number // 3 to n cols data // the Table structure itself - // save name of table - if( (pTable->zName) != NULL) - ptemp = hb_itemPutC( NULL, pTable->zName ); - else - ptemp = hb_itemPutC( NULL, ""); + hb_arraySetC( paRows, 1, pTable->zName ); // save name of table + hb_arraySetNL( paRows, 2, pTable->nCol ); // save number of cols/fields - hb_itemArrayPut( paRows, 1, ptemp); // base 1 not zero - hb_itemRelease( ptemp ); +// hb_reta( pTable->nCol ); - // save number of cols/fields - ptemp = hb_itemPutNL( NULL, pTable->nCol ); - hb_itemArrayPut( paRows, 2, ptemp); // base 1 not zero - hb_itemRelease( ptemp ); - -// printf("\n\nName= %s", pTable->zName ); -// printf("\n\nCols = %i", pTable->nCol ); -// hb_reta( pTable->nCol ); /* - for( i=0; i < pTable->nCol; i++) + printf("\n\nName= %s", pTable->zName ); + printf("\n\nCols = %i", pTable->nCol ); + + for( i = 0; i < pTable->nCol; i++) { - printf("\n Name= %s", pTable->aCol[i].zName ); - printf("\n Dflt= %s", pTable->aCol[i].zDflt ); - printf("\n Type= %s", pTable->aCol[i].zType ); - printf("\nPrimKey= %i", pTable->aCol[i].isPrimKey ); + printf("\n Name= %s", pTable->aCol[ i ].zName ); + printf("\n Dflt= %s", pTable->aCol[ i ].zDflt ); + printf("\n Type= %s", pTable->aCol[ i ].zType ); + printf("\nPrimKey= %i", pTable->aCol[ i ].isPrimKey ); } */ - for( iField =0; iField < pTable->nCol; iField++ ) - { - - // ---------- it's a multidimensional array -------------------- - // four data columns name, default, type, isprimarykey per field + for( iField = 0; iField < pTable->nCol; iField++ ) + { + // ---------- it's a multidimensional array -------------------- + // four data columns name, default, type, isprimarykey per field paCols = hb_itemArrayNew( 4 ); - // 1) if field name is not empty - if( (pTable->aCol[iField].zName) != NULL) - ptemp = hb_itemPutC( NULL, pTable->aCol[iField].zName ); - else - ptemp = hb_itemPutC( NULL, ""); - - // put data onto subarray of fields - hb_itemArrayPut( paCols, 1, ptemp); // base 1 not 0 - hb_itemRelease( ptemp ); - - - // 2) if default value is not empty - if( (pTable->aCol[iField].zDflt) != NULL) - ptemp = hb_itemPutC( NULL, pTable->aCol[iField].zDflt ); - else - ptemp = hb_itemPutC( NULL, ""); - - // put data onto subarray of fields - hb_itemArrayPut( paCols, 2, ptemp); // base 1 not 0 - hb_itemRelease( ptemp ); - - - // 3) if field type is not empty - if( (pTable->aCol[iField].zType) != NULL) - ptemp = hb_itemPutC( NULL, pTable->aCol[iField].zType ); - else - ptemp = hb_itemPutC( NULL, ""); - - // put data onto subarray of fields - hb_itemArrayPut( paCols, 3, ptemp); // base 1 not 0 - hb_itemRelease( ptemp ); - - - // 4) if primary key is not empty - ptemp = hb_itemPutL( NULL, pTable->aCol[iField].isPrimKey); - - // put data onto subarray of fields - hb_itemArrayPut( paCols, 4, ptemp); // base 1 not 0 - hb_itemRelease( ptemp ); + hb_arraySetC( paCols, 1, pTable->aCol[ iField ].zName ); + hb_arraySetC( paCols, 2, pTable->aCol[ iField ].zDflt ); + hb_arraySetC( paCols, 3, pTable->aCol[ iField ].zType ); + hb_arraySetL( paCols, 4, pTable->aCol[ iField ].isPrimKey ); // put data onto subarray of records - hb_itemArrayPut( paRows, 3 + iField, paCols); + hb_itemArrayPut( paRows, 3 + iField, paCols ); + hb_itemRelease( paCols ); - } // endfor - - } // endif pTable - - hb_itemReturn( paRows ); // final, return to harbour & release - hb_itemRelease( paRows ); - -} // eofunc + } + hb_itemReturnRelease( paRows ); + } + else + hb_reta( 0 ); +} //----------------------- - HB_FUNC( SQLITE_FIELDS ) +HB_FUNC( SQLITE_FIELDS ) //-------------------------------------------------------------------------- // Returns an unidimensional array with field names only //-------------------------------------------------------------------------- { - sqlite *pDB = db ; - struct Table * pTable; - const char * szName = hb_parc( 1 ); - int i; + struct Table * pTable = ( struct Table * ) sqliteFindTable( hb_sqlite2_db, ( const char * ) hb_parc( 1 ), 0 ); - pTable = (struct Table *) sqliteFindTable( pDB, szName, 0 ); + if( pTable ) + { + int i; - if( pTable ) - { // the Table structure itself hb_reta( pTable->nCol ); - for( i=0; i < pTable->nCol; i++) - { - hb_storc( pTable->aCol[i].zName, -1, 1 + i ); - } - } - else - hb_ret(); - -} // eofunc - + for( i = 0; i < pTable->nCol; i++ ) + hb_storc( pTable->aCol[ i ].zName, -1, 1 + i ); + } +} //----------------------------- - HB_FUNC( SQLITE_NUMOFTABLES ) +HB_FUNC( SQLITE_NUMOFTABLES ) //-------------------------------------------------------------------------- // Returns number of tables inside current open database (not table) //-------------------------------------------------------------------------- { - if( db ) - hb_retni( (db->nTable) - 2 ) ; // two internals - else - hb_retni( 0 ); + hb_retni( hb_sqlite2_db ? hb_sqlite2_db->nTable - 2 : 0 ); } diff --git a/harbour/contrib/hbsqlit3/hbsqlit3.c b/harbour/contrib/hbsqlit3/hbsqlit3.c index f6b52646e8..4f5fb519ef 100644 --- a/harbour/contrib/hbsqlit3/hbsqlit3.c +++ b/harbour/contrib/hbsqlit3/hbsqlit3.c @@ -199,14 +199,8 @@ HB_FUNC( SQLITE3_TEMP_DIRECTORY ) #ifdef NODLL { - char * pszDirName; - - #ifdef __XHARBOUR__ - pszDirName = hb_fileNameConv( hb_strdup( ( char * ) hb_parc( 1 ) ) ); - #else - BOOL fFree; - pszDirName = hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); - #endif + BOOL fFree; + char * pszDirName = hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); if( hb_fsIsDirectory( pszDirName ) ) bResult = TRUE; @@ -226,12 +220,8 @@ HB_FUNC( SQLITE3_TEMP_DIRECTORY ) if( bResult ) sqlite3_temp_directory = hb_strdup( pszDirName ); - #ifdef __XHARBOUR__ + if( fFree ) hb_xfree( pszDirName ); - #else - if( fFree ) - hb_xfree( pszDirName ); - #endif } #endif @@ -249,14 +239,8 @@ HB_FUNC( SQLITE3_TEMP_DIRECTORY ) HB_FUNC( SQLITE3_OPEN ) { psqlite3 db; - char * pszdbName; - - #ifdef __XHARBOUR__ - pszdbName = hb_fileNameConv( hb_strdup( ( char * ) hb_parc( 1 ) ) ); - #else - BOOL fFree; - pszdbName = ( char * ) hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); - #endif + BOOL fFree; + char * pszdbName = ( char * ) hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); if( hb_fsFile( ( BYTE * ) pszdbName ) || hb_parl( 2 ) ) { @@ -276,25 +260,15 @@ HB_FUNC( SQLITE3_OPEN ) hb_retptr( NULL ); } - #ifdef __XHARBOUR__ + if( fFree ) hb_xfree( pszdbName ); - #else - if( fFree ) - hb_xfree( pszdbName ); - #endif } HB_FUNC( SQLITE3_OPEN_V2 ) { psqlite3 db; - char * pszdbName; - - #ifdef __XHARBOUR__ - pszdbName = hb_fileNameConv( hb_strdup( ( char * ) hb_parc( 1 ) ) ); - #else - BOOL fFree; - pszdbName = ( char * ) hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); - #endif + BOOL fFree; + char * pszdbName = ( char * ) hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); if( sqlite3_open_v2( pszdbName, &db, hb_parni( 2 ), NULL ) == SQLITE_OK ) hb_retsqlite3( db ); @@ -305,12 +279,8 @@ HB_FUNC( SQLITE3_OPEN_V2 ) hb_retptr( NULL ); } - #ifdef __XHARBOUR__ + if( fFree ) hb_xfree( pszdbName ); - #else - if( fFree ) - hb_xfree( pszdbName ); - #endif } /* @@ -322,10 +292,10 @@ HB_FUNC( SQLITE3_OPEN_V2 ) HB_FUNC( SQLITE3_EXEC ) { psqlite3 db = hb_parsqlite3( 1 ); - char * pszErrMsg = NULL; if( db ) { + char * pszErrMsg = NULL; int rc = sqlite3_exec( db, hb_parc( 2 ), NULL, 0, &pszErrMsg ); if( rc != SQLITE_OK ) @@ -442,7 +412,7 @@ HB_FUNC( SQLITE3_RESET ) { psqlite3_stmt pStmt = ( psqlite3_stmt ) hb_parptr( 1 ); - if( pStmt != NULL ) + if( pStmt ) hb_retni( sqlite3_reset( pStmt ) ); else hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, "SQLITE3_RESET", 1, hb_paramError( 1 ) ); @@ -855,47 +825,23 @@ HB_FUNC( SQLITE3_GET_TABLE ) { PHB_ITEM pResultList = hb_itemArrayNew( 0 ); int iRow, iCol; - char * pszErrMsg = 0; + char * pszErrMsg = NULL; char ** pResult; if( sqlite3_get_table( db, hb_parc( 2 ), &pResult, &iRow, &iCol, &pszErrMsg ) == SQLITE_OK ) { int i, j, k = 0; - #ifdef __XHARBOUR__ - PHB_ITEM pTemp = hb_itemNew( NULL ); - #endif for( i = 0; i < iRow + 1; i++ ) { PHB_ITEM pArray = hb_itemArrayNew( iCol ); for( j = 1; j <= iCol; j++, k++ ) - { - if( pResult[ k ] != NULL ) - { - #ifdef __XHARBOUR__ - hb_arraySetForward( pArray, j, hb_itemPutC( pTemp, pResult[ k ] ) ); - #else - hb_arraySetC( pArray, j, pResult[k] ); - #endif - } - else - { - #ifdef __XHARBOUR__ - hb_arraySetForward( pArray, j, hb_itemPutC( pTemp, "NULL" ) ); - #else - hb_arraySetC( pArray, j, "NULL" ); - #endif - } - } + hb_arraySetC( pArray, j, pResult[ k ] ? pResult[ k ] : NULL ); hb_arrayAddForward( pResultList, pArray ); hb_itemRelease( pArray ); } - - #ifdef __XHARBOUR__ - hb_itemRelease( pTemp ); - #endif } else { @@ -905,11 +851,7 @@ HB_FUNC( SQLITE3_GET_TABLE ) sqlite3_free_table( pResult ); - #ifdef __XHARBOUR__ - hb_itemRelease( hb_itemReturn( pResultList ) ); - #else - hb_itemReturnRelease( pResultList ); - #endif + hb_itemReturnRelease( pResultList ); } else hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, "SQLITE3_GET_TABLE", 1, hb_paramError( 1 ) ); @@ -957,27 +899,13 @@ HB_FUNC( SQLITE3_TABLE_COLUMN_METADATA ) { PHB_ITEM pArray = hb_itemArrayNew( 5 ); - #ifdef __XHARBOUR__ - PHB_ITEM pTemp = hb_itemNew( NULL ); - hb_arraySetForward( pArray, 1, hb_itemPutC( pTemp, ( char * ) pzDataType ) ); - hb_arraySetForward( pArray, 2, hb_itemPutC( pTemp, ( char * ) pzCollSeq ) ); - hb_arraySetForward( pArray, 3, hb_itemPutL( pTemp, iNotNull ) ); - hb_arraySetForward( pArray, 4, hb_itemPutL( pTemp, iPrimaryKey ) ); - hb_arraySetForward( pArray, 5, hb_itemPutL( pTemp, iAutoinc ) ); - hb_itemRelease( pTemp ); - #else - hb_arraySetC( pArray, 1, ( char * ) pzDataType ); - hb_arraySetC( pArray, 2, ( char * ) pzCollSeq ); - hb_arraySetL( pArray, 3, ( BOOL ) iNotNull ); - hb_arraySetL( pArray, 4, ( BOOL ) iPrimaryKey ); - hb_arraySetL( pArray, 5, ( BOOL ) iAutoinc ); - #endif + hb_arraySetC( pArray, 1, ( char * ) pzDataType ); + hb_arraySetC( pArray, 2, ( char * ) pzCollSeq ); + hb_arraySetL( pArray, 3, ( BOOL ) iNotNull ); + hb_arraySetL( pArray, 4, ( BOOL ) iPrimaryKey ); + hb_arraySetL( pArray, 5, ( BOOL ) iAutoinc ); - #ifdef __XHARBOUR__ - hb_itemRelease( hb_itemReturn( pArray ) ); - #else - hb_itemReturnRelease( pArray ); - #endif + hb_itemReturnRelease( pArray ); } } else @@ -1228,23 +1156,24 @@ HB_FUNC( SQLITE3_TRACE ) HB_FUNC( SQLITE3_FILE_TO_BUFF ) { - BYTE * buffer = NULL; - int handle = hb_fsOpen( ( BYTE * ) hb_parc( 1 ), FO_READ ); - ULONG iSize; + int handle = hb_fsOpen( ( BYTE * ) hb_parc( 1 ), FO_READ ); if( handle != FS_ERROR ) { + BYTE * buffer; + ULONG iSize; + iSize = ( int ) hb_fsSeek( handle, 0, FS_END ); iSize -= ( int ) hb_fsSeek( handle, 0, FS_SET ); buffer = ( BYTE * ) hb_xgrab( iSize + 1 ); iSize = hb_fsReadLarge( handle, buffer, iSize ); buffer[ iSize ] = '\0'; hb_fsClose( handle ); + + hb_retclen_buffer( ( char * ) buffer, iSize ); } else - iSize = 0; - - hb_retclen_buffer( ( char * ) buffer, iSize ); + hb_retc_null(); } HB_FUNC( SQLITE3_BUFF_TO_FILE )