Hecha 100x100 en clases de C++ preparadas fara funcionar en PRG de Harbour.
Con las mismas características que HDBC para SQLite:
Con sentencias preparadas en el lado del servidor para evitar código inyectado y aumentar la seguridad.
Las pruebas que he hecho tarda en importar la DBF test de harbour de 500 registros en 54 milisegundos más rápido incluso que la versión para SQLite que se demora 114 milisegundos.
El fuente de la importación es este:
Code: Select all | Expand
///////////////////////////////////////////////////////////////////////////////
// Proyecto: hdbc
// Fichero: test008.prg
// Autor: Manu Exposito
// Fecha:
// Descripcion: Traspasa test.dbf de los ejemplos de Harbour a SQL.
// Si no existe la bases de datos la crea.
// Si no existe la tabla test la crea.
// Uso de bindParam
///////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
#include "hdbc.ch"
#include "postgresql_connect.ch"
#define ID_CARGA 500
//------------------------------------------------------------------------------
// Programa principal
procedure main()
local oDb, e
local cCreaTable
TEXT INTO cCreaTable
CREATE TABLE IF NOT EXISTS test
(
id SERIAL,
first VARCHAR( 20 ),
last VARCHAR( 20 ),
street VARCHAR( 30 ),
city VARCHAR( 30 ),
state VARCHAR( 2 ),
zip VARCHAR( 10 ),
hiredate DATE,
married BOOLEAN,
age INTEGER,
salary DECIMAL( 9, 2 ),
notes VARCHAR( 70 ),
PRIMARY KEY ( id )
)
ENDTEXT
cls
msg( "Traspaso de datos..." )
try
oDb := THDbc():new( _DRIVER_ )
oDb:connect( _CONN_STRING_ )
oDb:exec( cCreaTable )
traspasa( oDb )
catch e
eval( errorBlock(), e )
finally
oDb:disconnect()
msg( "Esto es todo!!!" )
end
return
//------------------------------------------------------------------------------
// Usa sentencias preparadas en el lado del servidor y transacciones.
static procedure traspasa( oDb )
local n := 0, nSec
local oInsert
local first, last, street, city, state, zip, hiredate, married, age, salary, notes
local cSentencia := "INSERT INTO test ( first, last, street, city, state, zip, " + ;
"hiredate, married, age, salary, notes ) " + ;
"VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11 );"
if file( "test.dbf" )
use test new
oInsert := oDb:prepareStatement( cSentencia ) // Crea el objeto y prepara la sentencia
// Vincula las variables harbour con cada una de las "?" por su posicion
oInsert:bindParam( 1, @first )
oInsert:bindParam( 2, @last )
oInsert:bindParam( 3, @street )
oInsert:bindParam( 4, @city )
oInsert:bindParam( 5, @state )
oInsert:bindParam( 6, @zip )
oInsert:bindParam( 7, @hiredate )
oInsert:bindParam( 8, @married )
oInsert:bindParam( 9, @age )
oInsert:bindParam( 10, @salary )
oInsert:bindParam( 11, @notes )
nSec := hb_milliSeconds()
oDb:startTransaction()
while n < ID_CARGA
while test->( !eof() )
first := test->first
last := test->last
street := test->street
city := test->city
state := test->state
zip := test->zip
hiredate := test->hiredate
married := test->married
age := test->age
salary := test->salary
notes := test->notes
oInsert:execute()
++n
test->( dbskip( 1 ) )
end
test->( DbGoTop() )
end
oDb:commit()
nSec := hb_milliSeconds() - nSec
msg( "Se han pasado " + Hb_NToS( n ) + " registros en " + Hb_NToS( nSec ) + " milisegundos", "Uso de bindParam" )
else
msg( "Fichero test.dbf no existe" )
endif
return
//------------------------------------------------------------------------------
Saludos