I have a .DB file that I wish to convert to .DBF files
Can I make it through fivewin?
Can I export to CSV and import it to a DBF afterward?
xHarbour 1.2.3 + Fwhh 20.2
I have a .DB file that I wish to convert to .DBF files
Can I make it through fivewin?
Can I export to CSV and import it to a DBF afterward?
function dbtodbf( cDb )
local oCn, oRs, aTables, cTable
oCn := FW_OpenAdoConnection( cDb ) // connect to sqlite3 database cDb
aTables := FW_AdoTables( oCn ) // get list of tables
xbrowser aTables // view the list of tables for information
for each cTable in aTables
oRs := FW_OpenRecordSet( oCn, cTable )
FW_AdoExportToDBF( oRs, cFileSetExt( cTable, "dbf" ), .t. )
// By setting the last parameter as .T.
// you can view/edit/modify structure before saving
// if the fieldnames exceed 10 chars you will have an opportunity to rename the field names
oRs:Close()
next
? "Done"
return nilsqlite3 ODBC installed on your computer
Download and install latest ODBC driver from here
Error: Unresolved external '_HB_FUN_FW_OPENADOCONNECTION' referenced from OBJ\MAIN.OBJ
Error: Unresolved external '_HB_FUN_FW_ADOTABLES' referenced from OBJ\MAIN.OBJ
Error: Unresolved external '_HB_FUN_FW_OPENRECORDSET' referenced from OBJ\MAIN.OBJ
Error: Unresolved external '_HB_FUN_FW_ADOEXPORTTODBF' referenced from OBJ\MAIN.OBJ
Error: Unresolved external '_HB_FUN_CFILESETEXT' referenced from OBJ\MAIN.OBJSorry I did not notice that you are using very old fwh versions.
All these functions are available in FWH for almost a year or so.
Can I send you the file?
ok send me.
I can also attempt a special program for you, but sending the db to me is easier
function db2csv( cDb )
local oCn, cCnStr, oTables
? "start"
cCnStr := "Driver=SQLite3 ODBC Driver;Database=" + cDb
oCn := TOleAuto():New( "ADODB.Connection" )
oCn:ConnectionString := cCnStr
oCn:CursorLocation := 3
oCn:Open()
oTables := oCn:OpenSchema( 20, { nil, nil, nil, "TABLE" } )
do while !oTables:Eof()
table2csv( oTables:Fields( "TABLE_NAME" ):Value, oCn )
oTables:MoveNext()
enddo
oTables:Close()
oCn:Close()
? "done"
return nil
static function table2csv( cTable, oCn )
local oRs, n, cStr, cCsv
oRs := TOleAuto():New( "ADODB.RecordSet" )
WITH OBJECT oRs
:Source := 'SELECT * FROM "' + cTable + '"'
:ActiveConnection := oCn
:Open()
END
cStr := oRs:Fields( 0 ):Name
for n := 1 to oRs:Fields:Count() - 1
cStr += "," + oRs:Fields( n ):Name
next
cStr += CRLF
if oRs:RecordCount() > 0
cStr += oRs:GetString( 2, oRs:RecordCount() , ",", CRLF )
endif
cCsv := StrTran( cTable, ' ', '_' ) + ".csv"
MEMOWRIT( cCsv, cStr, .f. )
return nilnageswaragunupudi wrote:You can try this code. This code does not use any FWH functions but only xHarbour functions.
If you already installed SqLite 3 ODBC driver on your computer this program will work.
I tested the function at my end with some db files I have with me.
function db2csv( cDb ) local oCn, cCnStr, oTables ? "start" cCnStr := "Driver=SQLite3 ODBC Driver;Database=" + cDb oCn := TOleAuto():New( "ADODB.Connection" ) oCn:ConnectionString := cCnStr oCn:CursorLocation := 3 oCn:Open() oTables := oCn:OpenSchema( 20, { nil, nil, nil, "TABLE" } ) do while !oTables:Eof() table2csv( oTables:Fields( "TABLE_NAME" ):Value, oCn ) oTables:MoveNext() enddo oTables:Close() oCn:Close() ? "done" return nil static function table2csv( cTable, oCn ) local oRs, n, cStr, cCsv oRs := TOleAuto():New( "ADODB.RecordSet" ) WITH OBJECT oRs :Source := 'SELECT * FROM "' + cTable + '"' :ActiveConnection := oCn :Open() END cStr := oRs:Fields( 0 ):Name for n := 1 to oRs:Fields:Count() - 1 cStr += "," + oRs:Fields( n ):Name next cStr += CRLF cStr += oRs:GetString( 2, oRs:RecordCount() , ",", CRLF ) cCsv := StrTran( cTable, ' ', '_' ) + ".csv" MEMOWRIT( cCsv, cStr, .f. ) return nil
This creates one csv file for each table in the db.
Usage : db2csv( "filename.db" )
Application
===========
Path and name: C:\DbToDbf\Projeto.EXE (32 bits)
Size: 2,795,520 bytes
Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 6715)
FiveWin Version: FWHX 10.6
Windows version: 6.1, Build 7601 Service Pack 1
Time from start: 0 hours 0 mins 17 secs
Error occurred at: 06/02/2015, 08:15:21
Error description: Error ADODB.RecordSet/6 DISP_E_UNKNOWNNAME: GETSTRING
Args:
[ 1] = N 2
[ 2] = N 0
[ 3] = C ,
[ 4] = C
Stack Calls
===========
Called from: source\rtl\win32ole.prg => TOLEAUTO:GETSTRING(0)
Called from: C:\DbToDbf\Source\Main.PRG => TABLE2CSV(402)
Called from: C:\DbToDbf\Source\Main.PRG => DB2CSV(377)
Called from: C:\DbToDbf\Source\Main.PRG => ACTION1(335)ok send me.
I can also attempt a special program for you, but sending the db to me is easier
1) You got this error because that particular table did not contain any records. I did not check for this in the code. Now I edited and modified the code to check if the table is blank. I advise you to copy the edited code again and try.
2) While you can try the code, you can also send me the db file.
nageswaragunupudi at gmail dot com.
Mr. Rao
I received your email, but I can't reduce the length of the collums.
I can split then in two separate fields but I can't loss any data.
Can you break the fields greater than 255 into two fields?