SQLImport with result 'undefined'

I successfully exported my sqlDB to a JSON string in a text field. I want to import the database from the same text field, but it results in ‘result = undefined’.

You’ll need to dig into this some more. Are you referring to the contents of the text field properly?

I think so, this is my code:

Function ExportDB()
  NSB.ShowProgress("Exporting database...")
  DBjson=SQLExport(DB, DBBil, exportComplete)    'DBBil = "DBBil.db"
End Function
 
Function exportComplete()
  NSB.ShowProgress(False)
  txtaImEx.value = JSON.stringify(DBjson)    'txtaImEx is jQuery Mobile text are
  msgbil("exportComplete")   'Message Funcion of my own
End Function

Function ImportDB()
  debugger
  result = SQLImport(JSON.parse(txtaImEx.value), DB, ImportCallback, ImpErr)
  'DB = SqlOpenDatabase(DBBil,"1.0",DBBil)
  msgbil("ImportDB result: " & result)
End Function

Function ImportCallback(event)
  msgbil("Import complete, Callback")   'reached
End Function

Function ImpErr(event)
  msgbil("Import with ERR: " & event)    ' never reached
End Function

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly. (We fixed it for you this time)

Does the JSON show up in txtaImEx?

What line gets the message? What is the exact error message?

Thank for the formatting hint, I will do this in the future.

The JSON string is shown after the Export in txtaImEx.
After the line
result = SQLImport(JSON.parse(txtaImEx.value), DB, ImportCallback, ImpErr)
result = undefined
is shown, no other error code.

Now I changed the following 2 lines:
DBjson=SQLExport(DB, "customer.db", exportComplete)
result = SQLImport(JSON.parse(txtaImEx.value), "customer.db", ImportCallback, ImpErr)
Now the text Importing database ... is shown, but never ends!

I dropped all tables after the export and got success hopefully with the import, but not shure. I will test furthermore. Is there a command to delete a database?

If you are running in the browser, you can see the databases in the Chrome Debugger, in the Application tab. Check out Local Storage.

It’s working for me now (after dropping tables), but there’s some strange behavior:
On the first attempt to export, the textarea is empty (undefined); on the second attempt, it’s filled as expected. Timing problem? Do I have to create DJason as an object? Dim…
This behavior is similar to the behavior in the SQLExpImp example. I have to press the Export button twice

How can I create an object ? DBJason = new Object() doesn’t work.

Not sure why you’re asking this question, so I’m not sure how to best answer it.

DBJason = new Object()

works fine, but I gather it does not solve the problem for you.

Can you explain more?

After this definition I call DBjson=SQLExport(DB, "DBBil.db", exportComplete) and after that statement DBJason is undefined !? in remote debugger and then txtaImEx.value = JSON.stringify(DBjson) gives an empty result. After a second attempt immediately afterwards I get a good, expected result.
the following code passage is successful, but unsatisfactory:

ExportDB()
If Len(txtaImEx.value) < 20 Then '1.Versuch fehlgeschlagen  
   ExportDB()
End If

Function ExportDB()
  NSB.ShowProgress("Exporting database...")
  DBjson=SQLExport(DB, "DBBil.db", exportComplete)
End Function

DBjson or DBJason?

I think I have a naming problem, I’ll check that

I have fixed the name problem, but it still takes the second attempt to succeed

Does exportComplete get call both times?