// Creating fields for new DBF - dbCreate() in current workarea
STATIC FUNCTION ADO_CREATEFIELDS( nWA, aStruct )
LOCAL aWData := USRRDD_AREADATA( nWA )
aWData[ 1 ] := { ;
NIL ,; // DATABASE_FILENAME
{} ,; // DATABASE_RECORDS
{} ,; // DATABASE_RECINFO
0 ,; // DATABASE_OPENNUMBER
FALSE ,; // DATABASE_LOCKED
aStruct; // DATABASE_STRUCT
}
RETURN SUCCESS
STATIC FUNCTION ADO_CREATE( nWA, aOpenInfo )
LOCAL aWData := USRRDD_AREADATA( nWA )
LOCAL aRData := USRRDD_RDDDATA( USRRDD_ID( nWA ) )
LOCAL aField, oError, cName
LOCAL cFullName, aDBFData
LOCAL cCMD := "CREATE TABLE "
Local aStruct, I
/* getting database infos from current workarea */
aDBFData := aWData[ 1 ]
aStruct := aWData[ 1 ][ 6 ]
/* setting in uppercase chars to avoid differences */
cFullName := Upper( aOpenInfo[ UR_OI_NAME ] )
// When there is no ALIAS we will create new one using file name
IF aOpenInfo[ UR_OI_ALIAS ] == NIL
HB_FNAMESPLIT( cFullName, , @cName )
aOpenInfo[ UR_OI_ALIAS ] := cName
ENDIF
// Check if database is already present in memory slots
IF !( cFullName IN aRData )
// Setting file attribs
aDBFData[ 1 ] := cFullName
aDBFData[ 5 ] := TRUE /* I need Exclusive mode in creation */
cCMD += cFullName+" ( "
FOR I=1 TO LEN( aStruct )
cCMD += aStruct[i,1]+" "
IF aStruct[i,2]=="C"
cCMD += "VARCHAR("+ALLTRIM(STR(aStruct[i,3]))+")"
ELSEIF aStruct[i,2]=="M"
cCMD += "VARCHAR("+ALLTRIM(STR(aStruct[i,3]))+")"
ELSEIF aStruct[i,2]=="N"
cCMD += "NUMERIC("+ALLTRIM(STR(aStruct[i,3]))+","+ALLTRIM(STR(aStruct[i,4]))+" )"
ELSEIF aStruct[i,2]=="D"
cCMD += "DATE"
ENDIF
IF i==LEN(aStruct)
cCMD += " )"
ELSE
cCMD += ", "
ENDIF
NEXT I
if s_cConnection != NIL
TRY
s_cConnection:Execute( "DROP TABLE "+cFullName )
CATCH
END
TraceLog( cCMD )
s_cConnection:Execute( cCMD )
endif
// Adding new database in RDD memory slots using filename as key
ELSE
// ERROR: database already exists
oError := ErrorNew()
oError:GenCode := EG_CREATE
oError:SubCode := 1004 // EDBF_CREATE_DBF
oError:Description := HB_LANGERRMSG( EG_CREATE ) + " (" + ;
HB_LANGERRMSG( EG_UNSUPPORTED ) + " - database already exists)"
oError:FileName := aOpenInfo[ UR_OI_NAME ]
oError:CanDefault := .T.
UR_SUPER_ERROR( nWA, oError )
RETURN FAILURE
ENDIF
// Set WorkArea Info
aWData[ 3 ] := aOpenInfo // Put open informations
// increase open number
aDBFData[ 4 ]++
RETURN SUCCESS
Add this code in ADORDD.PRG
aMyFunc[ UR_CREATE ] := ( @ADO_CREATE() )
aMyFunc[ UR_CREATEFIELDS ] := ( @ADO_CREATEFIELDS() )
Add this two line into FUNCTION ADORDD_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID )
Test it !
dbCreate is work