I try to create a table for access as diccussed a month ago (ADDTABLE from Enrico)
- Code: Select all Expand view
# include "fivewin.ch"
# include "dbstruct.ch"
# include "ado.ch"
#define STRIM( cStr, nChr ) Left( cStr, Len( cStr ) - nChr )
#define NTRIM( nNumber ) LTrim( Str( nNumber ) )
PROC MAIN()
LOCAL aFlds := {{"Frank","C",10,0},{"Number","N",10,2}}
/*
FW_CreateMDB( "Test.mdb") //|.accdb] )
? File("Test.mdb")
// ok , test.mdb exists
*/
AddTable("JET","FrankDemont",aFlds)
RETURN
*****************************************************************************************************************************
FUNCTION SQLEXEC( cQuery )
LOCAL cCns := "Provider='Microsoft.Jet.OLEDB.4.0'; Data Source=Test.mdb"//"Your connectionstring here"
LOCAL oCn := CREATEOBJECT( "ADODB.Connection" )
oCn:CursorLocation = adUseClient
oCn:Open( cCns )
? cQuery
oCn:Execute( cQuery )
oCn:Close()
RETURN NIL
FUNCTION ADDTABLE( cMot, cTab, aFld )
LOCAL cQuery := "CREATE TABLE " + cTab + " ( "
LOCAL cType
LOCAL i
IF cMot == "JET"
cQuery += "Id COUNTER PRIMARY KEY, "
ELSEIF cMot == "MSSQL"
cQuery += "Id INT IDENTITY PRIMARY KEY, "
ELSEIF cMot == "MYSQL"
cQuery += "Id SERIAL, "
ENDIF
FOR i = 1 TO LEN( aFld )
cType = aFld[ i, DBS_TYPE ]
DO CASE
CASE cType = "C"
cQuery += aFld[ i, DBS_NAME ] + " VARCHAR ( " + NTRIM( aFld[ i, DBS_LEN ] ) + " ), "
CASE cType = "N"
cQuery += aFld[ i, DBS_NAME ] + " NUMERIC ( " + NTRIM( aFld[ i, DBS_LEN ] ) + ", " + NTRIM( aFld[ i, DBS_DEC ] ) + " ), "
CASE cType = "D"
cQuery += aFld[ i, DBS_NAME ] + " DATETIME, "
CASE cType = "L"
cQuery += aFld[ i, DBS_NAME ] + " INT, "
CASE cType = "M"
IF cMot == "JET"
cQuery += "[" + aFld[ i, DBS_NAME ] + "]" + " MEMO, "
ELSEIF cMot == "MSSQL"
cQuery += "[" + aFld[ i, DBS_NAME ] + "]" + " TEXT, "
ELSEIF cMot == "MYSQL"
cQuery += aFld[ i, DBS_NAME ] + " TEXT, "
ENDIF
ENDCASE
NEXT
cQuery = STRIM( cQuery, 2 ) + " )"
SQLEXEC( cQuery )
RETURN NIL
It gives a syntax error in fielddefinition :
Error description: (DOS Error -2147352567) WINOLE/1007 Syntaxisfout in velddefinitie. (0x80040E14): Microsoft JET Database Engine
Args:
[ 1] = C CREATE TABLE FrankDemont ( Id COUNTER PRIMARY KEY, Frank VARCHAR ( 10 ), Number NUMERIC ( 10, 2 ) )
What i am doing wrong ?
Frank