Results 1 to 4 of 4

Thread: Create DB & Write to DB

  1. #1

    Default Create DB & Write to DB

    I am trying to create a database locally (right now on desktop and later to a phone)

    Using this website: https://mimecar.gitbook.io/qt-course...chapter-05-s01

    I understand the SQL statements create table, INSERT, FOR loop etc....
    My issue is I cant see where the database is being created. I need a physical DB on my devise that I can write too....Eventually using those records to update a database on my server.

    Right now I just need help:
    1. creating a Database IF NOT THERE and creating it in a specific location
    2. The ability to write records to that database
    3. And view the database records


    Can anyone please help....


    Qt Code:
    1. // SNIP
    2.  
    3. import QtQuick.LocalStorage 2.0
    4.  
    5. // SNIP
    6.  
    7. var db = LocalStorage.openDatabaseSync(weatherRecorder_db, "1.0", "StorageDatabase", 1000000);
    8. db.transaction(
    9. function(tx) {
    10. // Create the database if it doesn't already exist
    11. tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
    12.  
    13. // Add (another) greeting row
    14. tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
    15.  
    16. // Show all added greetings
    17. var rs = tx.executeSql('SELECT * FROM Greeting');
    18.  
    19. var r = ""
    20. for(var i = 0; i < rs.rows.length; i++) {
    21. r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n"
    22. }
    23. text = r
    24. console.log(text);
    25. }
    26. )
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create DB & Write to DB

    According to the docs for QtQuick LocalStorage:

    These databases are user-specific and QML-specific, but accessible to all QML applications. They are stored in the Databases subdirectory of QQmlEngine:: offlineStoragePath(), currently as SQLite databases.
    So examine the contents of that variable to see where the DB is physically located. If the DB is actually in SQLite format, then you can use any SQLite-based reader app to read / write them.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3

    Default Re: Create DB & Write to DB

    Can I specify where I want it to go?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create DB & Write to DB

    Why don't you read the documentation for QQmlEngine and find the answer?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 7
    Last Post: 5th February 2014, 12:20
  2. Replies: 0
    Last Post: 15th October 2013, 10:32
  3. Replies: 2
    Last Post: 2nd November 2010, 06:15
  4. QTcpSocket Write & \0 \x00
    By NewGuy5800 in forum Newbie
    Replies: 1
    Last Post: 25th April 2010, 11:23
  5. Replies: 4
    Last Post: 1st May 2009, 12:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.