2008-06-01 17:31 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
* contrib/make_b32_all.bat
* contrib/make_vc_all.bat
* contrib/make_gcc_all.sh
+ contrib/hbsqlit3
+ contrib/hbsqlit3/Makefile
+ contrib/hbsqlit3/make_b32.bat
+ contrib/hbsqlit3/make_vc.bat
+ contrib/hbsqlit3/make_gcc.sh
+ contrib/hbsqlit3/common.mak
+ contrib/hbsqlit3/hbsqlit3.c
+ contrib/hbsqlit3/hbsqlit3.ch
+ contrib/hbsqlit3/sqlite3/sqlite3.c
+ contrib/hbsqlit3/sqlite3/sqlite3.h
+ contrib/hbsqlit3/tests/bld_b32.bat
+ contrib/hbsqlit3/tests/bld_vc.bat
+ contrib/hbsqlit3/tests/blob.prg
+ contrib/hbsqlit3/tests/pack.prg
+ contrib/hbsqlit3/tests/metadata.prg
+ contrib/hbsqlit3/tests/sqlite3_test.prg
+ Added Harbour interface for SQLite 3.x.
Thanks goes to Petr Chornyj <myorg63/at/mail.ru> for
creating this code and making it available for this project.
(The code also based on Alejandro de G rate
<alex_degarate/at/hotmail.com> SQLite 2 interface work)
+ Added make files, arranged std contrib layout.
* Renamed header, source and lib name to comply with 8.3 rules.
+ Added to 'all' make files.
+ Added foreign SQLite 3.5.9 (amalgamation) latest version
source code to the repository.
Compiles with lots of warnings under BCC and
doesn't compile in C++ mode in MSVC (due to missing
casts).
; We may remove foreign code once the warnings
has been fixed and retrofitted in the original
package. Since the two required files are simply
#included in the Harbour source code, moving them
anywhere, or accessing them from anywhere is a matter
of -I switch.
; TOFIX:
- Replace MessageBox() with RTE or HB_TRACE().
- Remove HB_OS_WIN_32_USED dependency.
- Review if __XHARBOUR__ branches are indeed necessary.
This commit is contained in:
@@ -8,6 +8,53 @@
|
||||
2008-12-31 13:59 UTC+0100 Foo Bar <foo.bar@foobar.org>
|
||||
*/
|
||||
|
||||
2008-06-01 17:31 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
|
||||
* contrib/make_b32_all.bat
|
||||
* contrib/make_vc_all.bat
|
||||
* contrib/make_gcc_all.sh
|
||||
+ contrib/hbsqlit3
|
||||
+ contrib/hbsqlit3/Makefile
|
||||
+ contrib/hbsqlit3/make_b32.bat
|
||||
+ contrib/hbsqlit3/make_vc.bat
|
||||
+ contrib/hbsqlit3/make_gcc.sh
|
||||
+ contrib/hbsqlit3/common.mak
|
||||
+ contrib/hbsqlit3/hbsqlit3.c
|
||||
+ contrib/hbsqlit3/hbsqlit3.ch
|
||||
+ contrib/hbsqlit3/sqlite3/sqlite3.c
|
||||
+ contrib/hbsqlit3/sqlite3/sqlite3.h
|
||||
+ contrib/hbsqlit3/tests/bld_b32.bat
|
||||
+ contrib/hbsqlit3/tests/bld_vc.bat
|
||||
+ contrib/hbsqlit3/tests/blob.prg
|
||||
+ contrib/hbsqlit3/tests/pack.prg
|
||||
+ contrib/hbsqlit3/tests/metadata.prg
|
||||
+ contrib/hbsqlit3/tests/sqlite3_test.prg
|
||||
+ Added Harbour interface for SQLite 3.x.
|
||||
|
||||
Thanks goes to Petr Chornyj <myorg63/at/mail.ru> for
|
||||
creating this code and making it available for this project.
|
||||
|
||||
(The code also based on Alejandro de G rate
|
||||
<alex_degarate/at/hotmail.com> SQLite 2 interface work)
|
||||
|
||||
+ Added make files, arranged std contrib layout.
|
||||
* Renamed header, source and lib name to comply with 8.3 rules.
|
||||
+ Added to 'all' make files.
|
||||
+ Added foreign SQLite 3.5.9 (amalgamation) latest version
|
||||
source code to the repository.
|
||||
Compiles with lots of warnings under BCC and
|
||||
doesn't compile in C++ mode in MSVC (due to missing
|
||||
casts).
|
||||
; We may remove foreign code once the warnings
|
||||
has been fixed and retrofitted in the original
|
||||
package. Since the two required files are simply
|
||||
#included in the Harbour source code, moving them
|
||||
anywhere, or accessing them from anywhere is a matter
|
||||
of -I switch.
|
||||
; TOFIX:
|
||||
- Replace MessageBox() with RTE or HB_TRACE().
|
||||
- Remove HB_OS_WIN_32_USED dependency.
|
||||
- Review if __XHARBOUR__ branches are indeed necessary.
|
||||
|
||||
2008-06-01 13:50 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
|
||||
* contrib/hbcurl/hbcurl.ch
|
||||
! Few typos.
|
||||
|
||||
15
harbour/contrib/hbsqlit3/Makefile
Normal file
15
harbour/contrib/hbsqlit3/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
ROOT = ../../
|
||||
|
||||
C_SOURCES =\
|
||||
hbsqlit3.c \
|
||||
|
||||
PRG_HEADERS=\
|
||||
hbsqlit3.ch \
|
||||
|
||||
LIBNAME=hbsqlit3
|
||||
|
||||
include $(TOP)$(ROOT)config/lib.cf
|
||||
16
harbour/contrib/hbsqlit3/common.mak
Normal file
16
harbour/contrib/hbsqlit3/common.mak
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
LIBNAME = $(LIBPREF)hbsqlit3
|
||||
|
||||
LIB_PATH = $(LIB_DIR)$(LIBNAME)$(LIBEXT)
|
||||
|
||||
PRG_HEADERS = \
|
||||
hbsqlit3.ch \
|
||||
|
||||
LIB_OBJS = \
|
||||
$(OBJ_DIR)hbsqlit3$(OBJEXT) \
|
||||
|
||||
all: \
|
||||
$(LIB_PATH) \
|
||||
1632
harbour/contrib/hbsqlit3/hbsqlit3.c
Normal file
1632
harbour/contrib/hbsqlit3/hbsqlit3.c
Normal file
File diff suppressed because it is too large
Load Diff
89
harbour/contrib/hbsqlit3/hbsqlit3.ch
Normal file
89
harbour/contrib/hbsqlit3/hbsqlit3.ch
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* SQLite3 library low level (client api) interface code
|
||||
*
|
||||
* Copyright 2007 P.Chornyj <myorg63@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HBSQLIT3_CH_
|
||||
#define HBSQLIT3_CH_
|
||||
|
||||
#xtranslate DB_IS_OPEN( <db> ) => !Empty( <db> )
|
||||
#xtranslate STMT_IS_PREPARED( <stmt> ) => !Empty( <stmt> )
|
||||
|
||||
/* Fundamental Datatypes */
|
||||
#define SQLITE_INTEGER 1
|
||||
#define SQLITE_FLOAT 2
|
||||
#ifdef SQLITE_TEXT
|
||||
#undef SQLITE_TEXT
|
||||
#else
|
||||
#define SQLITE_TEXT 3
|
||||
#endif
|
||||
#define SQLITE3_TEXT 3
|
||||
#define SQLITE_BLOB 4
|
||||
#define SQLITE_NULL 5
|
||||
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
|
||||
/* Beginning-of-Error-Codes */
|
||||
#define SQLITE_ERROR 1 /* SQL error or missing database */
|
||||
#define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
#define SQLITE_LOCKED 6 /* A table in the database is locked */
|
||||
#define SQLITE_NOMEM 7 /* A malloc() failed */
|
||||
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Database is empty */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SQLITE_AUTH 23 /* Authorization denied */
|
||||
#define SQLITE_FORMAT 24 /* Auxiliary database format error */
|
||||
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* End-of-Error-Codes */
|
||||
|
||||
/* Combination of the following bit values are used
|
||||
as the third argument to the sqlite3_open_v2() interface */
|
||||
#define SQLITE_OPEN_READONLY 1
|
||||
#define SQLITE_OPEN_READWRITE 2
|
||||
#define SQLITE_OPEN_CREATE 4
|
||||
#define SQLITE_OPEN_DELETEONCLOSE 8
|
||||
#define SQLITE_OPEN_EXCLUSIVE 16
|
||||
#define SQLITE_OPEN_MAIN_DB 256
|
||||
#define SQLITE_OPEN_TEMP_DB 512
|
||||
#define SQLITE_OPEN_TRANSIENT_DB 1024
|
||||
#define SQLITE_OPEN_MAIN_JOURNAL 2048
|
||||
#define SQLITE_OPEN_TEMP_JOURNAL 4096
|
||||
#define SQLITE_OPEN_SUBJOURNAL 8192
|
||||
#define SQLITE_OPEN_MASTER_JOURNAL 16384
|
||||
|
||||
#endif
|
||||
9
harbour/contrib/hbsqlit3/make_b32.bat
Normal file
9
harbour/contrib/hbsqlit3/make_b32.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
rem
|
||||
rem $Id$
|
||||
rem
|
||||
|
||||
rem ; sqlite code has lots of warnings, suppress them
|
||||
set CFLAGS=-w-
|
||||
|
||||
call ..\mtpl_b32.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
7
harbour/contrib/hbsqlit3/make_gcc.sh
Normal file
7
harbour/contrib/hbsqlit3/make_gcc.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
../mtpl_gcc.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
9
harbour/contrib/hbsqlit3/make_vc.bat
Normal file
9
harbour/contrib/hbsqlit3/make_vc.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
rem
|
||||
rem $Id$
|
||||
rem
|
||||
|
||||
rem ; sqlite won't compile in C++ mode.
|
||||
set CFLAGS=-TC
|
||||
|
||||
call ..\mtpl_vc.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
87003
harbour/contrib/hbsqlit3/sqlite3/sqlite3.c
Normal file
87003
harbour/contrib/hbsqlit3/sqlite3/sqlite3.c
Normal file
File diff suppressed because it is too large
Load Diff
5638
harbour/contrib/hbsqlit3/sqlite3/sqlite3.h
Normal file
5638
harbour/contrib/hbsqlit3/sqlite3/sqlite3.h
Normal file
File diff suppressed because it is too large
Load Diff
14
harbour/contrib/hbsqlit3/tests/bld_b32.bat
Normal file
14
harbour/contrib/hbsqlit3/tests/bld_b32.bat
Normal file
@@ -0,0 +1,14 @@
|
||||
@echo off
|
||||
rem
|
||||
rem $Id$
|
||||
rem
|
||||
|
||||
if "%HB_BIN_INSTALL%" == "" set HB_BIN_INSTALL=..\..\..\bin
|
||||
if "%HB_LIB_INSTALL%" == "" set HB_LIB_INSTALL=..\..\..\lib
|
||||
if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=..\..\..\include
|
||||
|
||||
set HB_ARCHITECTURE=w32
|
||||
set HB_COMPILER=bcc32
|
||||
set HB_USER_LIBS=hbsqlit3.lib
|
||||
|
||||
call %HB_BIN_INSTALL%\bld.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
14
harbour/contrib/hbsqlit3/tests/bld_vc.bat
Normal file
14
harbour/contrib/hbsqlit3/tests/bld_vc.bat
Normal file
@@ -0,0 +1,14 @@
|
||||
@echo off
|
||||
rem
|
||||
rem $Id$
|
||||
rem
|
||||
|
||||
if "%HB_BIN_INSTALL%" == "" set HB_BIN_INSTALL=..\..\..\bin
|
||||
if "%HB_LIB_INSTALL%" == "" set HB_LIB_INSTALL=..\..\..\lib
|
||||
if "%HB_INC_INSTALL%" == "" set HB_INC_INSTALL=..\..\..\include
|
||||
|
||||
set HB_ARCHITECTURE=w32
|
||||
set HB_COMPILER=msvc
|
||||
set HB_USER_LIBS=hbsqlit3.lib
|
||||
|
||||
call %HB_BIN_INSTALL%\bld.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
103
harbour/contrib/hbsqlit3/tests/blob.prg
Normal file
103
harbour/contrib/hbsqlit3/tests/blob.prg
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* SQLite3 Demo
|
||||
*
|
||||
* Copyright 2007 P.Chornyj <myorg63@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbsqlit3.ch"
|
||||
|
||||
#define TABLE_SQL "CREATE TABLE image( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT(50), image BLOB )"
|
||||
|
||||
PROCEDURE main()
|
||||
LOCAL lCreateIfNotExist := .t.
|
||||
LOCAL db := sqlite3_open( "test.s3db", lCreateIfNotExist )
|
||||
LOCAL stmt
|
||||
LOCAL buff, blob
|
||||
|
||||
IF ! Empty( db )
|
||||
|
||||
sqlite3_exec( db, "PRAGMA auto_vacuum=0" )
|
||||
sqlite3_exec( db, "PRAGMA page_size=8192" )
|
||||
|
||||
sqlite3_exec( db, "DROP TABLE image" )
|
||||
|
||||
sqlite3_exec( db, TABLE_SQL )
|
||||
|
||||
stmt := sqlite3_prepare( db, "INSERT INTO image( title, image ) VALUES( :title, :image )")
|
||||
IF ! Empty( stmt )
|
||||
buff := sqlite3_file_to_buff( "pngtest.png" )
|
||||
|
||||
IF sqlite3_bind_text( stmt, 1, "pngtest.png" ) == SQLITE_OK .AND. ;
|
||||
sqlite3_bind_blob( stmt, 2, @buff ) == SQLITE_OK
|
||||
IF sqlite3_step( stmt ) == SQLITE_DONE
|
||||
?"Save pngtest.png into BLOB"
|
||||
? "INSERT INTO image( title, image ) VALUES( 'pngtest.png', 'pngtest.png' ) - Done"
|
||||
ENDIF
|
||||
ENDIF
|
||||
buff := NIL
|
||||
sqlite3_clear_bindings( stmt )
|
||||
sqlite3_finalize( stmt )
|
||||
ENDIF
|
||||
|
||||
? ""
|
||||
? "The number of database rows that were changed: " + ltrim( str( sqlite3_changes( db ) ) )
|
||||
? "Total changes: " + ltrim( str( sqlite3_total_changes( db ) ) )
|
||||
? ""
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
blob := sqlite3_blob_open( db, NIL, "image", "image", sqlite3_last_insert_rowid( db ), 0 /* 0 - RO; 1- RW */ )
|
||||
IF !Empty( blob )
|
||||
? "Open BLOB image - Ok"
|
||||
|
||||
buff := sqlite3_blob_read( blob )
|
||||
|
||||
/* Call sqlite3_blob_bytes() only after sqlite3_blob_read() */
|
||||
|
||||
? "The size in bytes of the blob - ", sqlite3_blob_bytes( blob )
|
||||
|
||||
IF ( sqlite3_buff_to_file( "pngtest1.png", @buff ) == SQLITE_OK )
|
||||
? "Save BLOB into pngtest1.png - Done"
|
||||
ENDIF
|
||||
|
||||
buff := NIL
|
||||
|
||||
sqlite3_blob_close( blob )
|
||||
? "Close BLOB"
|
||||
ENDIF
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
?""
|
||||
?"Save BLOB using sqlite3_column_blob()"
|
||||
stmt := sqlite3_prepare( db, "SELECT image FROM image WHERE id == ?5 ")
|
||||
IF !Empty( stmt )
|
||||
IF sqlite3_bind_int64( stmt, 5, sqlite3_last_insert_rowid( db ) ) == SQLITE_OK
|
||||
IF sqlite3_step( stmt ) == SQLITE_ROW
|
||||
buff := sqlite3_column_blob( stmt, 1 )
|
||||
IF ( sqlite3_buff_to_file( "pngtest2.png", @buff ) == SQLITE_OK )
|
||||
? "Save BLOB into pngtest2.png - Done"
|
||||
ENDIF
|
||||
buff := NIL
|
||||
ENDIF
|
||||
sqlite3_clear_bindings( stmt )
|
||||
sqlite3_finalize( stmt )
|
||||
ENDIF
|
||||
ENDIF
|
||||
wait
|
||||
ENDIF
|
||||
|
||||
RETURN
|
||||
63
harbour/contrib/hbsqlit3/tests/metadata.prg
Normal file
63
harbour/contrib/hbsqlit3/tests/metadata.prg
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* SQLite3 Demo
|
||||
*
|
||||
* Copyright 2007 P.Chornyj <myorg63@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbsqlit3.ch"
|
||||
|
||||
#ifdef NODLL
|
||||
#define SQLITE_ENABLE_COLUMN_METADATA
|
||||
#endif
|
||||
|
||||
PROCEDURE main()
|
||||
LOCAL lCreateIfNotExist := .f.
|
||||
LOCAL db := sqlite3_open( "new.s3db", lCreateIfNotExist )
|
||||
|
||||
IF ! Empty( db )
|
||||
test( db )
|
||||
ENDIF
|
||||
RETURN
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
PROCEDURE test( db )
|
||||
|
||||
IF sqlite3_exec( db, "SELECT * FROM t1" ) == SQLITE_OK
|
||||
? "TABLE t1"
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
? "Column name : id"
|
||||
? "Declared data type: ", sqlite3_table_column_metadata( db, , "t1", "id" )[1]
|
||||
? "Collation sequence name: ", sqlite3_table_column_metadata( db, , "t1", "id" )[2]
|
||||
? "NOT NULL constraint exists: ", sqlite3_table_column_metadata( db, , "t1", "id" )[3]
|
||||
? "Column is part of PK: ", sqlite3_table_column_metadata( db, , "t1", "id" )[4]
|
||||
? "Column is auto-increment: ", sqlite3_table_column_metadata( db, , "t1", "id" )[5]
|
||||
|
||||
? "Column name : name"
|
||||
? "Declared data type: ", sqlite3_table_column_metadata( db, , "t1", "name" )[1]
|
||||
? "Collation sequence name: ", sqlite3_table_column_metadata( db, , "t1", "name" )[2]
|
||||
? "NOT NULL constraint exists: ", sqlite3_table_column_metadata( db, , "t1", "name" )[3]
|
||||
? "Column is part of PK: ", sqlite3_table_column_metadata( db, , "t1", "name" )[4]
|
||||
? "Column is auto-increment: ", sqlite3_table_column_metadata( db, , "t1", "name" )[5]
|
||||
#endif
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
ENDIF
|
||||
RETURN
|
||||
36
harbour/contrib/hbsqlit3/tests/pack.prg
Normal file
36
harbour/contrib/hbsqlit3/tests/pack.prg
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* SQLite3 Demo
|
||||
*
|
||||
* Copyright 2007 P.Chornyj <myorg63@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbsqlit3.ch"
|
||||
|
||||
PROCEDURE main()
|
||||
LOCAL db := ;
|
||||
sqlite3_open_v2( "new.s3db", SQLITE_OPEN_READWRITE + SQLITE_OPEN_EXCLUSIVE )
|
||||
|
||||
IF !Empty( db )
|
||||
IF sqlite3_exec( db, "VACUUM" ) == SQLITE_OK
|
||||
? "PACK - Done"
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
RETURN
|
||||
244
harbour/contrib/hbsqlit3/tests/sqlite3_test.prg
Normal file
244
harbour/contrib/hbsqlit3/tests/sqlite3_test.prg
Normal file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* SQLite3 Demo
|
||||
*
|
||||
* Copyright 2007 P.Chornyj <myorg63@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbsqlit3.ch"
|
||||
|
||||
#define TRACE
|
||||
#define TABLE_SQL "CREATE TABLE t1( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER )"
|
||||
|
||||
PROCEDURE main()
|
||||
|
||||
? sqlite3_libversion()
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
IF sqlite3_libversion_number() < 3005001
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
t1()
|
||||
t2()
|
||||
RETURN
|
||||
|
||||
/*
|
||||
*/
|
||||
PROCEDURE t1()
|
||||
LOCAL lCreateIfNotExist := .f.
|
||||
LOCAL db := sqlite3_open( "new.s3db", lCreateIfNotExist )
|
||||
|
||||
IF ! Empty( db )
|
||||
sqlite3_exec( db, "DROP TABLE t1" )
|
||||
ENDIF
|
||||
RETURN
|
||||
|
||||
/*
|
||||
*/
|
||||
PROCEDURE t2()
|
||||
LOCAL lCreateIfNotExist := .t.
|
||||
LOCAL db := sqlite3_open( "new.s3db", lCreateIfNotExist )
|
||||
LOCAL stmt
|
||||
LOCAL nCCount, nCType, nI, nJ
|
||||
LOCAL aCType := { "SQLITE_INTEGER", "SQLITE_FLOAT", "SQLITE_TEXT", "SQLITE_BLOB", "SQLITE_NULL" }
|
||||
LOCAL aTable
|
||||
|
||||
IF ! Empty( db )
|
||||
|
||||
#ifdef TRACE
|
||||
sqlite3_profile( db, .t. )
|
||||
sqlite3_trace( db, .t. )
|
||||
#endif
|
||||
sqlite3_exec( db, "PRAGMA auto_vacuum=0" )
|
||||
sqlite3_exec( db, "PRAGMA page_size=4096" )
|
||||
|
||||
IF sqlite3_exec( db, TABLE_SQL ) == SQLITE_OK
|
||||
? "CREATE TABLE t1 - Ok"
|
||||
END
|
||||
|
||||
sqlite3_exec( db, ;
|
||||
"BEGIN TRANSACTION;" + ;
|
||||
"INSERT INTO t1( name, age ) VALUES( 'Bob', 52 );" + ;
|
||||
"INSERT INTO t1( name, age ) VALUES( 'Fred', 40 );" + ;
|
||||
"INSERT INTO t1( name, age ) VALUES( 'Sasha', 25 );" + ;
|
||||
"INSERT INTO t1( name, age ) VALUES( 'Ivet', 28 );" + ;
|
||||
"COMMIT;" )
|
||||
|
||||
? "BEGIN TRANSACTION"
|
||||
? "INSERT INTO t1( name, age ) VALUES( 'Bob', 52 )"
|
||||
? "INSERT INTO t1( name, age ) VALUES( 'Fred', 40 )"
|
||||
? "INSERT INTO t1( name, age ) VALUES( 'Sasha', 25 )"
|
||||
? "INSERT INTO t1( name, age ) VALUES( 'Ivet', 28 )"
|
||||
? "COMMIT"
|
||||
|
||||
? "The number of database rows that were changed: " + ltrim( str( sqlite3_changes( db ) ) )
|
||||
? "Total changes: " + ltrim( str( sqlite3_total_changes( db ) ) )
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
stmt := sqlite3_prepare( db, "INSERT INTO t1( name, age ) VALUES( :name, :age )")
|
||||
IF ! Empty( stmt )
|
||||
IF sqlite3_bind_text( stmt, 1, "Andy" ) == SQLITE_OK .AND. ;
|
||||
sqlite3_bind_int( stmt, 2, 17 ) == SQLITE_OK
|
||||
IF sqlite3_step( stmt ) == SQLITE_DONE
|
||||
? "INSERT INTO t1( name, age ) VALUES( 'Andy', 17 ) - Done"
|
||||
ENDIF
|
||||
ENDIF
|
||||
sqlite3_reset( stmt )
|
||||
|
||||
IF sqlite3_bind_text( stmt, 1, "Mary" ) == SQLITE_OK .AND. ;
|
||||
sqlite3_bind_int( stmt, 2, 19 ) == SQLITE_OK
|
||||
IF sqlite3_step( stmt ) == SQLITE_DONE
|
||||
? "INSERT INTO t1( name, age ) VALUES( 'Mary', 19 ) - Done"
|
||||
ENDIF
|
||||
ENDIF
|
||||
sqlite3_clear_bindings( stmt )
|
||||
sqlite3_finalize( stmt )
|
||||
ENDIF
|
||||
|
||||
? "The number of database rows that were changed: " + ltrim( str( sqlite3_changes( db ) ) )
|
||||
? "Total changes: " + ltrim( str( sqlite3_total_changes( db ) ) )
|
||||
? "Last _ROWID_: " + str( sqlite3_last_insert_rowid( db ) )
|
||||
? ""
|
||||
|
||||
stmt := sqlite3_prepare( db, "SELECT * FROM t1 WHERE name == :name ")
|
||||
sqlite3_bind_text( stmt, 1, "Andy" )
|
||||
|
||||
?
|
||||
? "SELECT * FROM t1 WHERE name == 'Andy'"
|
||||
nJ := 0
|
||||
|
||||
DO WHILE sqlite3_step( stmt ) == SQLITE_ROW
|
||||
nCCount := sqlite3_column_count( stmt )
|
||||
++nJ
|
||||
? "Record # " + str( nJ )
|
||||
|
||||
IF nCCount > 0
|
||||
FOR nI := 0 TO nCCount - 1
|
||||
nCType := sqlite3_column_type( stmt, nI )
|
||||
? "Column name : " + sqlite3_column_name( stmt, nI )
|
||||
? "Column type : " + aCType[ nCType ]
|
||||
? "Column value: "
|
||||
|
||||
SWITCH nCType
|
||||
CASE SQLITE_BLOB
|
||||
?? "BLOB" //sqlite3_column_blob( stmt, nI )
|
||||
EXIT
|
||||
|
||||
CASE SQLITE_INTEGER
|
||||
?? str ( sqlite3_column_int( stmt, nI ) )
|
||||
EXIT
|
||||
|
||||
CASE SQLITE_NULL
|
||||
?? "NULL"
|
||||
EXIT
|
||||
|
||||
CASE SQLITE_TEXT
|
||||
?? sqlite3_column_text( stmt, nI )
|
||||
EXIT
|
||||
END SWITCH
|
||||
|
||||
NEXT nI
|
||||
ENDIF
|
||||
ENDDO
|
||||
? "Total records - " + str( nJ )
|
||||
|
||||
sqlite3_clear_bindings( stmt )
|
||||
sqlite3_finalize( stmt )
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
stmt := sqlite3_prepare( db, "SELECT * FROM t1 WHERE age >= ?5")
|
||||
sqlite3_bind_int( stmt, 5, 40 )
|
||||
|
||||
?
|
||||
? "SELECT * FROM t1 WHERE age >= 40 "
|
||||
nJ := 0
|
||||
DO WHILE sqlite3_step( stmt ) == SQLITE_ROW
|
||||
nCCount := sqlite3_column_count( stmt )
|
||||
++nJ
|
||||
? "Record # " + str( nJ )
|
||||
|
||||
IF nCCount > 0
|
||||
FOR nI := 1 TO nCCount
|
||||
nCType := sqlite3_column_type( stmt, nI )
|
||||
? "Column name : " + sqlite3_column_name( stmt, nI )
|
||||
? "Column type : " + aCType[ nCType ]
|
||||
? "Column value: "
|
||||
SWITCH nCType
|
||||
CASE SQLITE_BLOB
|
||||
?? "BLOB" //sqlite3_column_blob( stmt, nI )
|
||||
EXIT
|
||||
|
||||
CASE SQLITE_INTEGER
|
||||
?? str( sqlite3_column_int( stmt, nI ) )
|
||||
EXIT
|
||||
|
||||
CASE SQLITE_NULL
|
||||
?? "NULL"
|
||||
EXIT
|
||||
|
||||
CASE SQLITE_TEXT
|
||||
?? sqlite3_column_text( stmt, nI )
|
||||
EXIT
|
||||
END SWITCH
|
||||
|
||||
NEXT nI
|
||||
ENDIF
|
||||
ENDDO
|
||||
? "Total records - " + str( nJ )
|
||||
sqlite3_clear_bindings( stmt )
|
||||
sqlite3_finalize( stmt )
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
?
|
||||
? "SELECT id, name, age + 5 FROM t1"
|
||||
stmt := sqlite3_prepare( db, "SELECT id, name, age + 5 FROM t1")
|
||||
|
||||
? sqlite3_column_name( stmt, 1 )
|
||||
? sqlite3_column_name( stmt, 2 )
|
||||
? sqlite3_column_name( stmt, 3 )
|
||||
|
||||
? aCType[ sqlite3_column_type( stmt, 1 ) ]
|
||||
? aCType[ sqlite3_column_type( stmt, 2 ) ]
|
||||
? aCType[ sqlite3_column_type( stmt, 3 ) ]
|
||||
|
||||
? sqlite3_column_decltype( stmt, 1 )
|
||||
? sqlite3_column_decltype( stmt, 2 )
|
||||
? sqlite3_column_decltype( stmt, 3 )
|
||||
|
||||
sqlite3_finalize( stmt )
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
|
||||
?
|
||||
? "sqlite3_get_table"
|
||||
?
|
||||
aTable = sqlite3_get_table( db, "SELECT name, age FROM t1 WHERE age BETWEEN 10 AND 20" )
|
||||
FOR nI := 1 TO Len( aTable )
|
||||
FOR nJ := 1 TO Len( aTable[nI] )
|
||||
?? aTable[nI][nJ], " "
|
||||
NEXT nJ
|
||||
?
|
||||
NEXT nI
|
||||
|
||||
sqlite3_sleep( 3000 )
|
||||
ENDIF
|
||||
|
||||
RETURN
|
||||
@@ -39,10 +39,13 @@ rem *******************************************************
|
||||
rem Compiling contrib dirs ...
|
||||
rem *******************************************************
|
||||
|
||||
set _HB_DIRS=rddado hbbmcdx hbbtree gtwvg hbct hbgt hbmisc hbnf hbmsql hbmzip
|
||||
set _HB_DIRS=rddado hbbmcdx hbbtree gtwvg hbct hbgt hbmisc
|
||||
for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
set _HB_DIRS=hbole hbziparch hbodbc hbtpathy hbtip hbvpdf hbw32 hbwhat32 xhb
|
||||
set _HB_DIRS=hbnf hbmsql hbmzip hbole hbziparch hbodbc hbsqlit3
|
||||
for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
set _HB_DIRS=hbtpathy hbtip hbvpdf hbw32 hbwhat32 xhb
|
||||
for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
set _HB_DIRS=hbclipsm hbw32ddr
|
||||
|
||||
@@ -38,7 +38,7 @@ fi
|
||||
|
||||
#**************************************************************
|
||||
|
||||
_HB_DIRS="hbbmcdx hbbtree hbclipsm hbct hbgt hbmisc hbmsql hbmzip hbnf hbtip hbtpathy hbvpdf xhb"
|
||||
_HB_DIRS="hbbmcdx hbbtree hbclipsm hbct hbgt hbmisc hbmsql hbmzip hbnf hbtip hbsqlit3 hbtpathy hbvpdf xhb"
|
||||
|
||||
case "$HB_ARCHITECTURE" in
|
||||
w32|cyg|os2)
|
||||
|
||||
@@ -39,10 +39,13 @@ rem *******************************************************
|
||||
rem Compiling contrib dirs ...
|
||||
rem *******************************************************
|
||||
|
||||
set _HB_DIRS=rddado hbbmcdx hbbtree gtwvg hbct hbgt hbmisc hbnf hbmsql hbmzip
|
||||
set _HB_DIRS=rddado hbbmcdx hbbtree gtwvg hbct hbgt hbmisc
|
||||
for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
set _HB_DIRS=hbole hbziparch hbodbc hbtpathy hbtip hbvpdf hbw32 hbwhat32 xhb
|
||||
set _HB_DIRS=hbnf hbmsql hbmzip hbole hbziparch hbodbc hbsqlit3
|
||||
for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
set _HB_DIRS=hbtpathy hbtip hbvpdf hbw32 hbwhat32 xhb
|
||||
for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
set _HB_DIRS=hbclipsm hbw32ddr
|
||||
|
||||
Reference in New Issue
Block a user