SQLite

Moderator: Rathinagiri

Post Reply
User avatar
jairpinho
Posts: 421
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

SQLite

Post 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 )
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: SQLite

Post 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?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
jairpinho
Posts: 421
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: SQLite

Post 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
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: SQLite

Post 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 )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
jairpinho
Posts: 421
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: SQLite

Post 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)
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: SQLite

Post 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 )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
jairpinho
Posts: 421
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: SQLite

Post by jairpinho »

Thanks it worked Rathi
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Re: SQLite

Post by Hazael »

Thanks for sharing your code
Harbour | GTWVT | MingW | Visual Studio Code
Post Reply