Do I manually have to read the blob into a buffer and then write it to the new table from the buffer or can a blob field be copied much simpler than that between tables?
If nobody knows, I will use the old way.
Just to make your eyes bleed, here is the bulk of my conversion code (With lots of custom stuff in it obviously)
Code: Select all
Procedure ConvertDatabaseNow()
Structure RecordNumbers
OldRecordNumber.s
NewRecordNumber.s
EndStructure
NewList LinkedRecord.s()
If Program\AttachedDatabase <> #Empty$
SetInfoBarArea("Headings", "Info", "Starting to convert and import the attached database, please wait a while", #PB_Compiler_Procedure)
AttachedDatabaseQuery.s +
"SELECT * FROM RemoteDatabase " +
"ORDER BY Title " +
"ASC"
If DatabaseQuery(Program\DatabaseHandle, AttachedDatabaseQuery.s) <> #DatabaseQueryFail
While NextDatabaseRow(Program\DatabaseHandle)
AttachedDatabaseQuery.s = #Empty$
MyInfo\Title = KillQuote(GetDatabaseString(Program\DatabaseHandle, 0)) ;
MyInfo\Information = KillQuote(GetDatabaseString(Program\DatabaseHandle, 1)) ;
MyInfo\Category = KillQuote(GetDatabaseString(Program\DatabaseHandle, 2)) ;
MyInfo\Archived = GetDatabaseString(Program\DatabaseHandle, 3) ;
MyInfo\Favourite = GetDatabaseString(Program\DatabaseHandle, 4) ;
MyInfo\Locked = GetDatabaseString(Program\DatabaseHandle, 5) ;
MyInfo\Deleted = GetDatabaseString(Program\DatabaseHandle, 6) ;
MyInfo\Updated = GetDatabaseString(Program\DatabaseHandle, 7) ;
MyInfo\Owner = KillQuote(GetDatabaseString(Program\DatabaseHandle, 8)) ;
MyInfo\Attachments = GetDatabaseString(Program\DatabaseHandle, 9) ;
MyInfo\Recordid = GetDatabaseString(Program\DatabaseHandle, 10) ;
MyInfoInsertString.s +
"INSERT INTO MyInfo(" +
"Title, " +
"Information, " +
"Category, " +
"Archived, " +
"Favourite, " +
"Locked, " +
"Deleted, " +
"Updated, " +
"Owner, " +
"Attachments) " +
"VALUES(" +
"'" + RepQuote(MyInfo\Title) + "'" +
", '" + RepQuote(MyInfo\Information) + "'" +
", '" + RepQuote(MyInfo\Category) + "'" +
", '" + RepQuote(MyInfo\Archived) + "'" +
", '" + RepQuote(MyInfo\Favourite) + "'" +
", '" + RepQuote(MyInfo\Locked) + "'" +
", '" + RepQuote(MyInfo\Deleted) + "'" +
", '" + RepQuote(MyInfo\Updated) + "'" +
", '" + RepQuote(MyInfo\Owner) + "'" +
", '" + "0" + "'" +
")"
If DatabaseUpdate(Program\DatabaseHandle, MyInfoInsertString.s) <> #DatabaseUpdateFail
NewRecordid.s = DatabaseLastInsertRowId()
If NewRecordId.s <> #Empty$
AddGadgetItem(#Gadget_Convert_Titles, #AtTheEndOfTheList, KillQuote(MyInfo\Title) + #LF$ + "Added" + #LF$ + NewRecordId.s)
LastLine(#Gadget_Convert_Titles, NewNumberOfItems.i - 1)
If MyInfo\Attachments <> #Empty$
AddElement(LinkedRecord.s())
LinkedRecord.s()\OldRecordNumber = MyInfo\Recordid
LinkedRecord.s()\NewRecordNumber = NewRecordId.s
EndIf
If Toggle\MessageSave = #True
MessageRequesterEBS("New Item", "New item: " + KillQuote(MyInfo\Title) + " has been saved to the database", #MB_ICONINFORMATION | #PB_MessageRequester_Ok)
;MessageRequester("New Item", "New item: " + KillQuote(MyInfo\Title) + " has been saved to the database", #PB_MessageRequester_Ok)
EndIf
Else
SetInfoBarArea("Headings", "Error", "No record number created " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
Else
SetInfoBarArea("Headings", "Error", "Database table failed to be updated " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
; Update the category table now
NewCategoryInsert.s +
"INSERT INTO Categories(" +
"Category, " +
"ItemCount, " +
"Iconname) " +
"VALUES(" +
"'" +
RepQuote(MyInfo\Category) +
"', '" +
"0" +
"', '" +
#Empty$ +
"')"
If DatabaseUpdate(Program\DatabaseHandle, NewCategoryInsert.s) <> #DatabaseUpdateFail
UpdateCategoryItemCount(MyInfo\Category)
Else
SetInfoBarArea("Headings", "Error", "Database table 'Categories' failed to be updated " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
; Update the Owners table now
NewOwnerInsert.s +
"INSERT INTO Owners(" +
"Owner, " +
"Iconname, " +
"Itemcount) " +
"VALUES(" +
"'" +
RepQuote(MyInfo\Owner +
"', " +
"'" +
#Empty$ +
"', " +
"'0')"
If DatabaseUpdate(Program\DatabaseHandle, NewOwnerInsert.s) <> #DatabaseUpdateFail
UpdateOwnerItemCount(MyInfo\Owner)
Else
SetInfoBarArea("Headings", "Error", "Database table 'Owners' failed to be updated " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
; Update the attachments table now
ForEach LinkedRecord.s()
; Grab the old blob from attachments table, save it to new table linking it to the new
; Record number by knowing the old record number
Next
; Clean out all the variables
AttachedDatabaseQuery.s = #Empty$
MyInfoInsertString.s = #Empty$
NewCategoryInsert.s = #Empty$
NewOwnerInsert.s = #Empty$
MyInfo\Title = #Empty$
MyInfo\Information = #Empty$
MyInfo\Category = #Empty$
MyInfo\Archived = #Empty$
MyInfo\Favourite = #Empty$
MyInfo\Locked = #Empty$
MyInfo\Deleted = #Empty$
MyInfo\Updated = #Empty$
MyInfo\Owner = #Empty$
MyInfo\Recordid = #Empty$
Wend
FinishDatabaseQuery(Program\DatabaseHandle)
Else
SetInfoBarArea("Headings", "Error", "The database query failed or was empty", #PB_Compiler_Procedure)
EndIf
Else
SetInfoBarArea("Headings", "Error", "There is currently no attached database selected for conversion", #PB_Compiler_Procedure)
MessageRequesterEBS("No database attached", "There is currently no attached database selected for conversion", #MB_ICONINFORMATION | #PB_MessageRequester_Ok)
EndIf
EndProcedure