HTML5 web SQL dynamically creates database tables
SmcsServices. service ('visitinstitutioncacheservice ', [' $ rootScope ',' $ http', 'baseurl', 'cesceservice ', function ($ rootScope, $ http, BaseURL, DataSourceService) {var service = {synVisit: function (synvtdatetime) {$ http ({method: 'post', cache: false, url: BaseURL + 'syscommoncodetransform/findVisitInstitution. do ', params: {datetime: synvtdatetime }}). success (function (response, status, headers, config) {try {var obj = response. visitInstitution; var synobj = response. synvisitlist; // optimized for dynamic table var objstr = JSON after test and development. stringify (obj [0]); console. log (obj [0] ===+ objstr); var objjson = JSON. parse (objstr); for (var key in objjson) {console. log (the key of objjson is ===+ key);} // after testing and development, optimize the dynamic creation of the table var db = DataSourceService. getConnection (); // console. log (synvisitlist synobj [0]. syndatetime = + synobj [0]. syndatetime); // var db = openDatabase ('mydb14', '1. 0', 'test db', 6*1024*1024); DB. transaction (function (tx) using tx.exe cuteSql ('create Table If Not Exists VisitInstitution (id, AKB020, AKB021, AKA020, AKA101 )'); tx.exe cuteSql ('delete FROM syncachecode WHERE inserting cuteSql ('insert INTO syncachecode (syntablename, syndatetime) VALUES (VisitInstitution, '+ synobj [0]. syndatetime + '); for (var I = 0; I
Console:
Obj [0] ==={ AKA101: 11, AKB020: 02162001, AKB021: lingjing community health service station, West chang'an Street, Xicheng district, ID: 11010602162001, AKA020: required} the key of objjson is ==== AKA101objjson's key is ==== AKB020objjson's key is ==== AKB021objjson's key is ==== IDobjjson's key = = AKA020
Dynamic table creation in web db
Web SQL dynamically creates database tables and synchronizes them with backend databases.
When a table is created for the first time, mydatetime = "1970", and the date and time returned by the background in the future are used as the synchronization time.