necesito leer una base de datos sqlite encriptada, en el mobil uso sqlite cipher
pero en la desktop, solo tengo esto para leer sqlite sin encriptacion.
- Code: Select all Expand view RUN
/*-------------------------------------------------------------------------------------------------*/
#include "dmolina.ch"
#include "hbsqlit3.ch"
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_Open( cDB, lCreateIfNotExist )
LOCAL pDB
IF ! Empty( cDB )
pDB := sqlite3_open( cDB, lCreateIfNotExist )
ENDIF
RETURN pDB
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_Execute( pDB, cQry )
LOCAL cError
IF !Empty( pDB ) .and. !Empty( cQry )
IF sqlite3_exec( pDB, cQry ) == SQLITE_OK
RETURN TRUE
ELSE
cError := sqlite3_errmsg( pDB )
IF !Empty( cError )
MsgAlert( cError, "Error SqlLite" )
ENDIF
ENDIF
ENDIF
RETURN FALSE
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_Query( pDB, cQuery )
LOCAL pStmt, nFields, n
LOCAL aRet, aRec
LOCAL cError
LOCAL nCType
IF !Empty( pDB )
pStmt := sqlite3_prepare( pDB, cQuery )
IF !Empty( pStmt )
aRet := {}
DO WHILE sqlite3_step( pStmt ) == SQLITE_ROW
aRec := {}
nFields := sqlite3_column_count( pStmt )
IF nFields>0
FOR n := 1 TO nFields
nCType := sqlite3_column_type( pStmt, n )
DO CASE
CASE nCType == SQLITE_NULL //5
AAdd( aRec, "NULL" )
CASE nCType == SQLITE_FLOAT //2
AAdd( aRec, sqlite3_column_double( pStmt, n ) )
CASE nCType == SQLITE_INTEGER //1
AAdd( aRec, sqlite3_column_int( pStmt, n ) )
CASE nCType == SQLITE_TEXT //3
AAdd( aRec, sqlite3_column_text( pStmt, n ) )
CASE nCType == SQLITE_BLOB //4
AAdd( aRec, sqlite3_column_blob( pStmt, n ) )
ENDCASE
NEXT
ENDIF
aadd( aRet, aRec )
ENDDO
sqlite3_reset( pStmt )
ELSE
cError := sqlite3_errmsg( pDB )
IF !Empty( cError )
MsgAlert( cError, "Error SqlLite" )
ENDIF
ENDIF
ENDIF
RETURN aRet
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_QueryValue( pDB, cQuery )
LOCAL aRet
IF !Empty( pDB ) .and. !Empty( cQuery )
aRet := SqlLite_Query( pDB, cQuery )
IF HB_IsArray( aRet ) .and. Len( aRet ) == 1
RETURN aRet[ 1, 1 ]
ENDIF
ENDIF
RETURN NIL
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_ListTables( pDB )
LOCAL aRet := {}
LOCAL cQry
IF !Empty( pDB )
cQry := "SELECT name FROM sqlite_master " +;
"WHERE type IN ('table','view') " +;
"AND name NOT LIKE 'sqlite_%' " +;
"UNION ALL " +;
"SELECT name FROM sqlite_temp_master " +;
"WHERE type IN ('table','view') " +;
"ORDER BY 1;"
aRet := SqlLite_Query( pDB, cQry )
ENDIF
RETURN aRet
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_TableExist( pDB, cTable )
LOCAL aRet := {}, cQry
cQry := "SELECT name FROM sqlite_master WHERE type='table' AND tbl_name='" + cTable + "'"
IF !Empty( pDB ) .and. !Empty( cTable )
aRet := SqlLite_Query( pDB, cQry )
ENDIF
RETURN ( Len( aRet ) > 0 )
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_Pack( pDB )
IF !Empty( pDB )
IF sqlite3_exec( pDB, "VACUUM" ) == SQLITE_OK
RETURN TRUE
ENDIF
ENDIF
RETURN FALSE
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_Fields( pDB, cTable )
LOCAL aRet := {}, nFields, n
LOCAL cError
LOCAL pStmt
IF !Empty( pDB ) .and. !Empty( cQry )
pStmt := sqlite3_prepare( pDB, "SELECT * FROM " + cTable )
IF !Empty( pStmt )
sqlite3_step( pStmt )
nFields := sqlite3_column_count( pStmt )
IF nFields > 0
FOR n:=1 TO nFields
AAdd( aRet, sqlite3_column_name( pStmt, n ) )
NEXT
ENDIF
sqlite3_reset( pStmt )
ELSE
cError := sqlite3_errmsg( pDB )
IF !Empty( cError )
MsgAlert( cError, "Error SqlLite" )
ENDIF
ENDIF
ENDIF
RETURN aRet
/*-------------------------------------------------------------------------------------------*/
FUNCTION SqlLite_Columns( pDB, cTable )
LOCAL nCType, aCType := { "SQLITE_INTEGER", "SQLITE_FLOAT", "SQLITE_TEXT", "SQLITE_BLOB", "SQLITE_NULL" }
LOCAL aRet := {}, nFields, n
LOCAL cError
LOCAL pStmt
IF !empty( pDB ) .and. !empty( cQry )
pStmt := sqlite3_prepare( pDB, "SELECT * FROM " + cTable )
IF !empty( pStmt )
sqlite3_step( pStmt )
nFields := sqlite3_column_count( pStmt )
IF nFields > 0
FOR n := 1 TO nFields
nCType := sqlite3_column_type( pStmt, n )
aadd( aRet, { sqlite3_column_name( pStmt, n ), aCType[ nCType ] } )
NEXT
ENDIF
sqlite3_reset( pStmt )
ELSE
cError := sqlite3_errmsg( pDB )
IF !Empty( cError )
MsgAlert( cError, "Error SqlLite" )
ENDIF
ENDIF
ENDIF
RETURN aRet
/*-------------------------------------------------------------------------------------------*/
/*EOF*/
/*-------------------------------------------------------------------------------------------*/