Page 1 of 1

SQLite

Posted: Mon Aug 29, 2011 10:46 pm
by jairpinho
Hola a todos, tengo problemas con SQLite para crear una lista de nombres de tablas de una base de datos utilizando inhibidores de la HMG 3.0.38 siguiendo los ejemplos, pero no puede devolver los nombres que parecen tener por favor, cualquier cosa que no se fijan en el ejemplo

Code: Select all

********************************************************************************\
*********************
FUNCTION SQLITE_TABLES()
********************************************************************************\
***********************
* Uses a (special) master table where the names of all tables are stored
* Returns an array with names of tables inside of the database

LOCAL aTables := {}
Local cSelect := ""

cSelect := "SELECT name FROM sqlite_master WHERE type IN ('table','name')
AND name NOT LIKE 'sqlite_%' UNION ALL SELECT name FROM sqlite_temp_master WHERE
type IN ('table','name') ORDER BY 1;"



IF DB_IS_OPEN( Database )

aTables := SQLITE_QUERY( Database, cSelect )
msginfo( STR(Len( aTables )))
msginfo(alltrim(aTables) )


ENDIF

RETURN( aTables )


********************************************************************************\
****************************************************
FUNCTION SQLITE_QUERY( Database, cSelect )
********************************************************************************\
****************************************************
LOCAL STMT, nCCount, nI, nCType
LOCAL aRet := {}, oQuery := {}

STMT := sqlite3_prepare( Database, cSelect )

IF STMT_IS_PREPARED( STMT )
DO WHILE sqlite3_step( STMT ) == SQLITE_ROW
oQuery := {}
nCCount := sqlite3_column_count( STMT )

IF nCCount > 0
FOR nI := 1 TO nCCount
nCType := sqlite3_column_type( STMT, nI )

SWITCH nCType
CASE SQLITE_NULL
AADD( oQuery, "NULL")
EXIT

CASE SQLITE_FLOAT
CASE SQLITE_INTEGER
AADD( oQuery, LTRIM(STR( sqlite3_column_int( STMT, nI ) )) )
EXIT

CASE SQLITE_TEXT
AADD( oQuery, sqlite3_column_text( STMT, nI ) )
EXIT
END SWITCH


NEXT nI
ENDIF
aadd(aRet, oQuery)
ENDDO
sqlite3_finalize( STMT )
ENDIF

RETURN( aRet )

Re: SQLite

Posted: Tue Aug 30, 2011 5:22 am
by Rathinagiri
Hi,

Your code is working nice to me.

What or where do you get the problem? Also, had you seen HMGSQL\source\hmgsqlite.prg?

Is 'Database' a public variable?

Re: SQLite

Posted: Tue Aug 30, 2011 3:26 pm
by jairpinho
I can not treat the array as a string to view or compare it with text

Code: Select all

IF DB_IS_OPEN( Database )

aTables := SQLITE_QUERY( Database, cSelect )
msginfo( STR(Len( aTables )))
msginfo(alltrim(aTables) )  ----->>>> here is the problem of error


ENDIF

Re: SQLite

Posted: Tue Aug 30, 2011 3:48 pm
by Rathinagiri
I think you can use the following code:

Code: Select all

cList := ''
for i := 1 to len( aTables )
   cList := cList + alltrim( aTables[ i ] )
   if i < len( aTables )
      cList := cList + ', '
   endif
next i
msginfo( 'These are the tables: ' + cList )

Re: SQLite

Posted: Tue Aug 30, 2011 4:16 pm
by jairpinho
still the same problem I can not view the array as follows

Date:08/30/11 Time: 13:12:24
Error BASE/2022 Argument error: ALLTRIM

Called from ALLTRIM(0)
Called from SQLITE_TABLES(312)
Called from PESUIQSA_DADOS(77)
Called from (b)CLIENTE(4)
Called from _PROCESSINITPROCEDURE(5088)
Called from _ACTIVATEWINDOW(4921)
Called from DOMETHOD(7374)
Called from CLIENTE(53)
Called from (b)MAIN(11)
Called from _DOCONTROLEVENTPROCEDURE(5268)
Called from EVENTS(1389)
Called from _DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(4933)
Called from DOMETHOD(7374)
Called from MAIN(21)

Re: SQLite

Posted: Tue Aug 30, 2011 4:58 pm
by Rathinagiri
Hi,

Please just change this line to:

Code: Select all

cList := ''
for i := 1 to len( aTables )
   cList := cList + alltrim( aTables[ i, 1 ] )
   if i < len( aTables )
      cList := cList + ', '
   endif
next i
msginfo( 'These are the tables: ' + cList )

Re: SQLite

Posted: Tue Aug 30, 2011 6:09 pm
by jairpinho
Thanks it worked Rathi

Re: SQLite

Posted: Thu Jul 23, 2015 1:36 pm
by Hazael
Thanks for sharing your code