examples/declarative/sqllocalstorage/hello.qml
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    38 **
    38 **
    39 ****************************************************************************/
    39 ****************************************************************************/
    40 //![0]
    40 //![0]
    41 import Qt 4.7
    41 import Qt 4.7
    42 
    42 
    43 Text {
    43 Rectangle {
    44     text: "?"
    44     color: "white"
       
    45     width: 200
       
    46     height: 100
       
    47     
       
    48     Text {
       
    49         text: "?"
       
    50         anchors.horizontalCenter: parent.horizontalCenter
       
    51         function findGreetings() {
       
    52             var db = openDatabaseSync("QDeclarativeExampleDB", "1.0", "The Example QML SQL!", 1000000);
    45 
    53 
    46     function findGreetings() {
    54             db.transaction(
    47         var db = openDatabaseSync("QDeclarativeExampleDB", "1.0", "The Example QML SQL!", 1000000);
    55                 function(tx) {
       
    56                     // Create the database if it doesn't already exist
       
    57                     tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
    48 
    58 
    49         db.transaction(
    59                     // Add (another) greeting row
    50             function(tx) {
    60                     tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
    51                 // Create the database if it doesn't already exist
       
    52                 tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
       
    53 
    61 
    54                 // Add (another) greeting row
    62                     // Show all added greetings
    55                 tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
    63                     var rs = tx.executeSql('SELECT * FROM Greeting');
    56 
    64 
    57                 // Show all added greetings
    65                     var r = ""
    58                 var rs = tx.executeSql('SELECT * FROM Greeting');
    66                     for(var i = 0; i < rs.rows.length; i++) {
       
    67                         r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n"
       
    68                     }
       
    69                     text = r
       
    70                 }
       
    71             )
       
    72         }
    59 
    73 
    60                 var r = ""
    74         Component.onCompleted: findGreetings()
    61                 for(var i = 0; i < rs.rows.length; i++) {
       
    62                     r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n"
       
    63                 }
       
    64                 text = r
       
    65             }
       
    66         )
       
    67     }
    75     }
    68 
       
    69     Component.onCompleted: findGreetings()
       
    70 }
    76 }
    71 //![0]
    77 //![0]