SqlImport: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 9: Line 9:
''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.
''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.
''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. If you do not have a callback function, put "" in this parameter.


''overwrite'' can have the following values:
''overwrite'' can have the following values:
Line 16: Line 16:
! Value !! Action
! Value !! Action
|-
|-
| true || overwrite the existing database (default).
| NSB.overwriteAlways || overwrite the existing database (default).
|-
|-
| false || only write out database if it does not exist yet.
| NSB.overwriteNever || only write out database if it does not exist yet.
|-
|-
| overwriteDifferent || overwrite if the version number of the database has changed.
| NSB.overwriteIfVersionDifferent || overwrite if the version number of the database has changed.
|-
|-
| overwriteSame || overwrite if the version number of the database is the same.
| NSB.overwriteIfVersionSame || overwrite if the version number of the database is the same.
|}
|}


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


To get the version of a database, use DB.version. To change the version of a database, use the command DB.changeVersion(''oldVersionString'', ''newVersionString'').
To get the version of a database, use DB.version(). To change the version of a database, use the command DB.changeVersion(''oldVersionString'', ''newVersionString''). changeVersion() will not work on iOS before version 5.
 
To deploy a database with your app, simply [[Distributing your App|add its name to ''extraFiles'' in Project Properties]]. An SQLImport() function will be automatically be invoked when you start your app to load the database the first time.
<pre>
customers.db,DB,loadComplete,NSB.overwriteAlways
</pre>


For more information on SQLite, see [[Using SQLite]].
For more information on SQLite, see [[Using SQLite]].

Latest revision as of 19:06, 2 November 2020

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 any code which generates a valid JSON object.

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. If you do not have a callback function, put "" in this parameter.

overwrite can have the following values:

Value Action
NSB.overwriteAlways overwrite the existing database (default).
NSB.overwriteNever only write out database if it does not exist yet.
NSB.overwriteIfVersionDifferent overwrite if the version number of the database has changed.
NSB.overwriteIfVersionSame overwrite if the version number of the database is the same.

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

To get the version of a database, use DB.version(). To change the version of a database, use the command DB.changeVersion(oldVersionString, newVersionString). changeVersion() will not work on iOS before version 5.

To deploy a database with your app, simply add its name to extraFiles in Project Properties. An SQLImport() function will be automatically be invoked when you start your app to load the database the first time.

customers.db,DB,loadComplete,NSB.overwriteAlways

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