It is safer to use full "HH:MM:SS" in FW_AddTime() function.
Your code above works, where we open the table "reservations" as rowset oRs and append record by record.
Recommended alternative, without opening the table as rowset, is to insert one or more records directly into the table using:
- Code: Select all Expand view RUN
oCn:Insert( cTable, acFields, aData, [lUpdate] )
aData can be one record or multiple records.
Example:
- Code: Select all Expand view RUN
PLANNER->(DBGOTOP())
aData := PLANNER->( FW_DbfToArray( ;
"FW_ADDTIME(START,'12:00:00'),FW_ADDTIME(ENDE,'12:00:00'),TEXT,ROOM,STATUS,IS_PAID" ) )
oCn:Insert( "reservations", "start,end,name,room_id,status,paid", aData )
This method can be used not only to insert new records (single or bulk), but also for updating existing records with latest information as well as insert-cum-update.
For example, let us assume that "room_id" is either primary key or Unique key field in the "reservation" table. Then,
- Code: Select all Expand view RUN
oCn:Insert( "reservations", "start,end,name,room_id,status,paid", aData, .T. )
// OR
oCn:Upsert( "reservations", "start,end,name,room_id,status,paid", aData )
updates the data where room_id already exists and inserts where room_id does not already exist.
This is very useful for refreshing the data on the mysql server with latest additions and modifications in the dbf table.
The Insert/Upsert method is generic. There is a specific method for uploading data from dbf to mysql table.
- Code: Select all Expand view RUN
oCn:UploadFromAlias( cSqlTable, cDbfFieldList, cSqlFieldList )
In the above case of reservations, we can export the data with one single statement:
- Code: Select all Expand view RUN
PLANNER->(DBGOTOP())
PLANNER->( oCn:UploadFromAlias( "reservations", ;
"FW_ADDTIME(START,'12:00:00'),FW_ADDTIME(ENDE,'12:00:00'),TEXT,ROOM,STATUS,IS_PAID" ), ;
"start,end,name,room_id,status,paid" ) )
In case "room_id" is a primary key or unique key, the data will be updated or inserted as required.