James, Pieter,
I think the easiest way might be:
1. Change the ID SQL field to WHATEVER_ID
- Code: Select all Expand view RUN
"ALTER TABLE sqltable_name CHANGE old_column_name new_column_name"
2. Add new ID field EX.
- Code: Select all Expand view RUN
"ALTER TABLE sqltable_name ADD COLUMN ID <DATATYPE>"
Now we have a AUTOINC field WHATEVER_ID and a ID with datatype you indicated.
If the ID field in the dbf file is autoinc I think FW_AdoImportFromDBF will try to import it as AUTOINC and you will get an error.
With ADORDD you can do (although it will be slow):
- Code: Select all Expand view RUN
//ado sets must be initialized
......
hb_GetAdoConnection():Execute("ALTER TABLE sqltable_name CHANGE ID WHATEVER_ID")
//the data type for this field should match a compatible data type for the value stored in dbf
//if it is autoinc should be INT with the same length of the dbf.
hb_GetAdoConnection():Execute("ALTER TABLE sqltable_name ADD COLUMN ID VARCHAR(10)")
//set again field recno to WHATEVER_ID or it will not work.
SET ADO DEFAULT RECNO FIELD TO "WHATEVER_ID"
SELE 0
USE table_name ALIAS "DBF" VIA "DBFCDX"
SELE 0
USE sqltable_name ALIAS "SQL" //assuming adordd its default rdd
SELE DBF
DO WHILE !EOF()
sql->(dbappend())
for n := 1 to dbf->( fcount() )
sql->( fieldput( sql->( fieldpos( dbf->( fieldname( n ) ), dbf->( fieldget( n ) ) ) )
next
DBSKIP()
ENDDO
SELE SQL
BROWSE()
I didn't try it but it should work.
Mysql will not consider ID as autoinc field if you defined for it a different datatype.
I think FW_AdoImportFromDBF its doing that auto because the ID field in the DBF its autoinc.
Remember this will take sometime to execute with thousands of records.
Did you check LOAD DATA LOCAL INFILE use?
You can even change field types , exclude fields while importing it and its very fast.
In this case you would use COPY TO .... DELIMITED and then use that file to build the LOAD DATA LOCAL INIFILE statement.
Hope this will help.