//Called when application is started. It works on Droidscript, it is tested function OnStart() { //Create a layout with objects vertically centered. lay = app.CreateLayout( "linear", "VCenter,FillXY" ); //Create a text label and add it to layout. txt = app.CreateText( "", 0.9, 0.4, "multiline" ) lay.AddChild( txt ); app.AddLayout(lay); db = app.OpenDatabase( "MyData" ) //Create a table (if it does not exist already). db.ExecuteSql( "drop table if exists test_table" ) db.ExecuteSql( "CREATE TABLE IF NOT EXISTS test_table " + "(id integer primary key, data text, num integer)",[],null, OnError ) db.ExecuteSql( "insert into test_table values (1,'data10',100), (2,'data20',200),(3,'data30',300)") //Get all the table rows. DisplayAllRows("SELECT * FROM test_table"); DisplayAllRows("select *, id+100 as idplus, 'hahaha' as blabla from test_table order by id desc;") } //function to display all records function DisplayAllRows(sqlstring) // <-- can you use for any table not need to // know column names, just use a * // example: { //Use all rows what is in ExecuteSql (try any, it will works fine) db.ExecuteSql( sqlstring, [], OnResult, OnError ) } //Callback to show query results in debug. function OnResult( res ) { var len = res.rows.length; var s = txt.GetText(); // *********************************************************************** // This is the answer how to read column names from table: for(var ColumnNames in res.rows.item(0)) s += " [ "+ ColumnNames +" ] "; // "[" & "]" optional, i use only in this demo // *********************************************************************** //app.Alert("Here is all Column names what Select from your table:\n"+s); s+="\n"; for(var i = 0; i < len; i++ ) { var rows = res.rows.item(i) for (var item in rows) { s += " " + rows[item] + " "; } s+="\n\n"; } //app.Alert(s); txt.SetText( s ) } //Callback to show errors. function OnError( msg ) { app.Alert( "Error: " + msg ) } //Called when application is started. It works on Droidscript, it is tested function OnStart() { //Create a layout with objects vertically centered. lay = app.CreateLayout( "linear", "VCenter,FillXY" ); //Create a text label and add it to layout. txt = app.CreateText( "", 0.9, 0.4, "multiline" ) lay.AddChild( txt ); app.AddLayout(lay); db = app.OpenDatabase( "MyData" ) //Create a table (if it does not exist already). db.ExecuteSql( "drop table if exists test_table" ) db.ExecuteSql( "CREATE TABLE IF NOT EXISTS test_table " + "(id integer primary key, data text, num integer)",[],null, OnError ) db.ExecuteSql( "insert into test_table values (1,'data10',100), (2,'data20',200),(3,'data30',300)") //Get all the table rows. DisplayAllRows("SELECT * FROM test_table"); DisplayAllRows("select *, id+100 as idplus, 'hahaha' as blabla from test_table order by id desc;") } //function to display all records function DisplayAllRows(sqlstring) // <-- can you use for any table not need to // know column names, just use a * // example: { //Use all rows what is in ExecuteSql (try any, it will works fine) db.ExecuteSql( sqlstring, [], OnResult, OnError ) } //Callback to show query results in debug. function OnResult( res ) { var len = res.rows.length; var s = txt.GetText(); // *********************************************************************** // This is the answer how to read column names from table: for(var ColumnNames in res.rows.item(0)) s += " [ "+ ColumnNames +" ] "; // *********************************************************************** //app.Alert("Here is all Column names what Select from your table:\n"+s); s+="\n"; for(var i = 0; i < len; i++ ) { var rows = res.rows.item(i) for (var item in rows) { s += " " + rows[item] + " "; } s+="\n\n"; } //app.Alert(s); txt.SetText( s ) } //Callback to show errors. function OnError( msg ) { app.Alert( "Error: " + msg ) } //Called when application is started. It works on Droidscript, it is tested function OnStart() { //Create a layout with objects vertically centered. lay = app.CreateLayout( "linear", "VCenter,FillXY" ); //Create a text label and add it to layout. txt = app.CreateText( "", 0.9, 0.4, "multiline" ) lay.AddChild( txt ); app.AddLayout(lay); db = app.OpenDatabase( "MyData" ) //Create a table (if it does not exist already). db.ExecuteSql( "drop table if exists test_table" ) db.ExecuteSql( "CREATE TABLE IF NOT EXISTS test_table " + "(id integer primary key, data text, num integer)",[],null, OnError ) db.ExecuteSql( "insert into test_table values (1,'data10',100), (2,'data20',200),(3,'data30',300)") //Get all the table rows. DisplayAllRows("SELECT * FROM test_table"); DisplayAllRows("select *, id+100 as idplus, 'hahaha' as blabla from test_table order by id desc;") } //function to display all records function DisplayAllRows(sqlstring) // <-- can you use for any table not need to // know column names, just use a * // example: { //Use all rows what is in ExecuteSql (try any, it will works fine) db.ExecuteSql( sqlstring, [], OnResult, OnError ) } //Callback to show query results in debug. function OnResult( res ) { var len = res.rows.length; var s = txt.GetText(); // *********************************************************************** // This is the answer how to read column names from table: for(var ColumnNames in res.rows.item(0)) s += " [ "+ ColumnNames +" ] "; // "[" & "]" optional, i use only in this demo // *********************************************************************** //app.Alert("Here is all Column names what Select from your table:\n"+s); s+="\n"; for(var i = 0; i < len; i++ ) { var rows = res.rows.item(i) for (var item in rows) { s += " " + rows[item] + " "; } s+="\n\n"; } //app.Alert(s); txt.SetText( s ) } //Callback to show errors. function OnError( msg ) { app.Alert( "Error: " + msg ) } //Called when application is started. It works on Droidscript, it is tested function OnStart() { //Create a layout with objects vertically centered. lay = app.CreateLayout( "linear", "VCenter,FillXY" ); //Create a text label and add it to layout. txt = app.CreateText( "", 0.9, 0.4, "multiline" ) lay.AddChild( txt ); app.AddLayout(lay); db = app.OpenDatabase( "MyData" ) //Create a table (if it does not exist already). db.ExecuteSql( "drop table if exists test_table" ) db.ExecuteSql( "CREATE TABLE IF NOT EXISTS test_table " + "(id integer primary key, data text, num integer)",[],null, OnError ) db.ExecuteSql( "insert into test_table values (1,'data10',100), (2,'data20',200),(3,'data30',300)") //Get all the table rows. DisplayAllRows("SELECT * FROM test_table"); DisplayAllRows("select *, id+100 as idplus, 'hahaha' as blabla from test_table order by id desc;") } //function to display all records function DisplayAllRows(sqlstring) // <-- can you use for any table not need to // know column names, just use a * // example: { //Use all rows what is in ExecuteSql (try any, it will works fine) db.ExecuteSql( sqlstring, [], OnResult, OnError ) } //Callback to show query results in debug. function OnResult( res ) { var len = res.rows.length; var s = txt.GetText(); // *********************************************************************** // This is the answer how to read column names from table: for(var ColumnNames in res.rows.item(0)) s += " [ "+ ColumnNames +" ] "; // *********************************************************************** //app.Alert("Here is all Column names what Select from your table:\n"+s); s+="\n"; for(var i = 0; i < len; i++ ) { var rows = res.rows.item(i) for (var item in rows) { s += " " + rows[item] + " "; } s+="\n\n"; } //app.Alert(s); txt.SetText( s ) } //Callback to show errors. function OnError( msg ) { app.Alert( "Error: " + msg ) } lang-sql