SqlImport: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
SQLImport(''JSON'', [''DB''], [''callback''], [''overwrite''])
result = SQLImport(''JSON'', [''DB''], [''callback''], [''overwrite''])


== Description ==
== Description ==
Line 11: Line 11:
''callback'' is the name of a function to be called when the import is complete. If it is not supplied,execution will be blocked until the import is completed.
''callback'' is the name of a function to be called when the import is complete. If it is not supplied,execution will be blocked until the import is completed.


''overwrite'' can be true or false. If it is not supplied, it defaults to true. When true, if the version of the database is the same as in the JSON object, nothing happens. Otherwise, the database is overwritten.  
''overwrite'' can have the following values:
{| class="wikitable"
|-
! Value !! Action
|-
| true || overwrite the existing database (default).
|-
| false || overwrite the existing database (default).
|-
| overwriteDifferent || overwrite if the version number of the database has changed.
|-
| overwriteSame || overwrite if the version number of the database is the same.
|}


If ''overwrite'' is false, the database is checked for a version number. If there is no version number, the database is presumed to be new and the data is written to the database.
result is a string which returns whether the operation was successful.


To change the version of a database, use the command DB.changeVersion(''oldVersionString'', ''newVersionString'').
To change the version of a database, use the command DB.changeVersion(''oldVersionString'', ''newVersionString'').

Revision as of 17:59, 14 November 2012

result = SQLImport(JSON, [DB], [callback], [overwrite])

Description

SqlImport converts a JSON object created using SqlExport into an SQLite database. The JSON object can come from an Ajax call or from an included JavaScript.

SqlImport may report errors if the database used by SqlExport has features that are not supported on the current platform, or if the syntax of the Json is invalid. For example, Safari (at the time of this writing) does not support timestamp in constraints, images or indexes. Embedded carriage returns in string fields will also cause errors.You will need to remove these items from the database before doing SqlExport.

DB is an optional argument. If supplied, the reference to the database is assigned to it. There is no need to do an SqlOpenDatabase. It can be left empty if not needed.

callback is the name of a function to be called when the import is complete. If it is not supplied,execution will be blocked until the import is completed.

overwrite can have the following values:

Value Action
true overwrite the existing database (default).
false overwrite the existing database (default).
overwriteDifferent overwrite if the version number of the database has changed.
overwriteSame overwrite if the version number of the database is the same.

result is a string which returns whether the operation was successful.

To change the version of a database, use the command DB.changeVersion(oldVersionString, newVersionString).

For more information on SQLite, see Using SQLite.

Example

Function btnSQLImport_onclick()
  SQLImport(DBjson, DB)
    
  'refresh the selection
  sqlList=Array(["SELECT * from customerData ORDER BY name;", dataHandler])
  Sql(DB, sqlList)
End Function

Output

(the database is imported and a selection is made)

Related Items

SQLExport