HOWTO: write a DataBasic program that will read data from SQL server

2 views
Skip to first unread message

GVP

unread,
Aug 16, 2007, 8:14:33 AM8/16/07
to BRIZ
BRIZ ODBC and DAO API provides read/write data access to remote data
bases.

The following program reads table from MS SQL and writes it into D3
file
*********************************************
program conv.SQL
include GP_TERM.LIB, GPTerm.COMMON
aTables = ''
aTables<-1> = 'SCL_MOVE'
aTables<-1> = 'SCL_NAKL'
oDBHandler = ''
sConnectionString = 'Driver={SQLServer};Server=ServerPath
\ServerName;Database=MYDATABASE;Uid=MyUser;Pwd=MyPwd;'
sDBOptions = 'NODIALOG'
DelayValue = 20
DelaySub = 'GPTerm.DefDelaySub'
MPstartEnd = 1
execute "run dm,bp, xcs-on" capturing NULL
echo off
call GP.ODBCDatabaseOpen( oDBHandler, sConnectionString, sDBOptions )
if oDBHandler<1> # -1 then
for i=1 to dcount( aTables, @am )
open 'dt.' : aTables<i> to dt.tmp else
crt 'cant open dt.' : aTables<i>
exit
end
execute 'clear-file dt.' : aTables<i> capturing NULL
oRSHandler = ''
sSQLString = 'select * from [dbo].[' : aTables<i> : ']'
sRSOptions = 'NONE'
call GP.ODBCRecordsetOpen( oDBHandler, oRSHandler, sSQLString,
sRSOptions )
if oRSHandler<1> # -1 then
loop
sOperation = 'IsEOF'
sRetVal = ''
call GP.ODBCRecordsetFn( oRSHandler, sOperation, sRetVal )
if sRetVal = 0 then
sOperation = 'ReadRowMoveNext'
******* ReadRows method can reads many rows at once. It is increases
speed up to 10th times
sRetVal = ''
call GP.ODBCRecordsetFn( oRSHandler, sOperation, sRetVal )
write sRetVal on dt.tmp, sRetVal<1>
end else
exit
end
repeat
close dt.tmp
call GP.ODBCRecordsetClose( oRSHandler )
end else
crt 'error while GP.ODBCRecordsetOpen'
close dt.tmp
exit
end
next i
call GP.ODBCDatabaseClose( oDBHandler )
end else
crt 'error while GP.ODBCDatabaseOpen'
end
echo on
stop
*************************************

Any comments, please

Reply all
Reply to author
Forward
0 new messages