<< Click to Display Table of Contents >> Converting from DBF to SQL |
![]() ![]() ![]() |
To get started one of the first things you need to do is to convert your existing DBF data to a SQL database.
We have created a sample program (Convert to SQL) that shows how to do this. We are assuming you are using DBFCDX and have all your indexes as production indexes (index file has the same name as DBF file).
Please remember that this sample DOES NOT CHECK for conflicts with RESERVED WORDS and only has the DEFAULT TRANSLATIONS for index expressions.
What you need to do to run this sample program is:
•Compile and link the program
•Change the connection string in the Connectionstring Callback method:
•Run the program in the data directory of your application.
Source code of a translation program:
FUNCTION Start
LOCAL aDir AS ARRAY
LOCAL cFile AS STRING
LOCAL cTag AS STRING
LOCAL cExpr AS STRING
LOCAL i,j AS DWORD
SetDeleted(TRUE)
RDDSETDEFAULT("VO2ADO")
// Prevent automatic selection of first order
// to speed up processing
RDDINFO(_SET_AUTOORDER, FALSE)
SET ALTE TO DbCONVERT.LOG
aDir := Directory("*.DBF")
FOR i := 1 TO ALen(aDir)
cFile := aDir[i,1]
cFile := LEFT(cFIle, At2(".", cFile)-1)
// Open existing file
USE (cFile) alias OLD via "DBFCDX"
? "Copying data for file ", cFile, "(",RECCOUNT(), "Records,",FCount()," fields)"
?
// Copy to SQL table
COPY TO (cFile) FOR ProgressBar()
// Create indexes on destination
USE (cFile) new alias NEW
FOR j := 1 TO OLD->(DBORDERINFO(DBOI_ORDERCOUNT))
cTag := OLD->(DBORDERINFO(DBOI_NAME, cFile,j))
cExpr := OLD->(DBORDERINFO(DBOI_EXPRESSION,cFile, cTag))
? "Creating index tag",cTag, cExpr
NEW->(DBCREATEORDER(cTag,cFile , cExpr))
NEXT
// Optionally create ADF File
// NEW->(DBINFO(DBI_SAVETABLEDEF))
close data
?
NEXT
FUNCTION ProgressBar()
IF RECNO()% 25 == 0 .or. RECNO() == RECCOUNT()
@ row(),0 say STR(100 * RECNO()/RECCOUNT(),3,0)+"%"
ENDIF
RETURN TRUE
FUNCTION AdoRddCallBack(sType, sName)
IF sType == #Connection
RETURN cConnCallBack{sName}
ENDIF
RETURN cTCallBack{sName}
CLASS cConnCallBack
METHOD ConnectionString(sConn) CLASS cConnCallBack
RETURN "Provider=sqloledb;Data Source=(LOCAL);Initial Catalog=NewDb;User Id=sa;Password=;"
CLASS cTCallBack
METHOD MaxRecords(sName, nDefault) CLASS cTCallBack
RETURN 0x7FFFFFFF
METHOD PreExecute(sName, cStmt) CLASS cTCallBack
RETURN cStmt
METHOD WarningMessage(sName, cString) CLASS cTCallBack
? "Warning" , sName, cString
RETURN cString