1. #31
    Sencha User
    Join Date
    Mar 2012
    Posts
    3
    Vote Rating
    0
    Mika83AC is on a distinguished road

      0  

    Default


    Hello!

    How is it possible to connect to an existing sqlite db in the folder of the app? All my trys just resulted in an sqlite db created in the isolated storage of the browser, but it seem's not to be possible to connect to an existing sqlite db in the file system.

    Where is my mistake ?

    Regards,
    Michael

  2. #32
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  3. #33
    Sencha User
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    MauiRa is on a distinguished road

      0  

    Default


    Quote Originally Posted by Mika83AC View Post
    Hello!

    How is it possible to connect to an existing sqlite db in the folder of the app? All my trys just resulted in an sqlite db created in the isolated storage of the browser, but it seem's not to be possible to connect to an existing sqlite db in the file system.

    Where is my mistake ?

    Regards,
    Michael
    Is this on Android or on IOS?

    For Android, phonegap already has a way of using an external data source you simply must use it instead of the generic window.openDatabase.

    Here is what I have done:

    phonegap.1.4.1.js defines a DroidDB_opendatabase which can be used in place of the browsers implementation.

    In SQLConnection, I do this:

    Ext.ns('Ext.Sqlite');


    Ext.Sqlite.Connection = Ext.define('Ext.Sqlite.Connection', {
    extend: 'Ext.util.Observable',
    /**
    * @cfg {String} dbName
    * Name of database
    */
    dbName: undefined,

    /**
    * @cfg {String} version
    * database version. If different than current, use updatedb event to update database
    */
    dbVersion: '1.19',

    /**
    * @cfg {String} dbDescription
    * Description of the database
    */
    dbDescription: '',

    /**
    * @cfg {String} dbSize
    * Max storage size in bytes
    */
    dbSize: 5 * 1024 * 1024,

    /**
    * @cfg {String} dbConn
    * database connection object
    */
    dbConn : undefined,

    constructor : function(config) {
    config = config || {};

    Ext.apply(this, config);
    var me = this;

    me.callParent([this]);
    if(navigator.userAgent.toLowerCase().match(/android/)){
    window.droiddb = new DroidDB();
    me.dbConn = DroidDB_openDatabase(me.dbName, me.dbVersion, me.dbDescription, me.dbSize);
    } else {
    me.dbConn = openDatabase(me.dbName, me.dbVersion, me.dbDescription, me.dbSize);
    }
    return me;
    }
    });

    This uses the dbname in the app namespace /data/data/app.package.name/app_database:appname.db which is the default path used by Storage.java -> openOrCreateDatabase.

    Perhaps the same can be done for IOS with a SQLite plugin.

    My team is currently implementing davibe's plugin for IOS so that a second conditional may be used:

    if(navigator.userAgent.toLowerCase().match(/android/)){
    window.droiddb = new DroidDB();
    me.dbConn = DroidDB_openDatabase(me.dbName, me.dbVersion, me.dbDescription, me.dbSize);
    } else if (navigator.userAgent.toLowerCase().match(/ios/)){
    me.dbConn =PGSQLite_openDatabase(me.dbName, me.dbVersion, me.dbDescription, me.dbSize);

    } else{
    me.dbConn = openDatabase(me.dbName, me.dbVersion, me.dbDescription, me.dbSize);
    }

  4. #34
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    Thanks for the info regarding android sqlite plugin,

    Is that working fine ?, do let me know how ios phonegap works ?, we can include some config option in current proxy to prefer type of DB.
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  5. #35
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    508
    Vote Rating
    73
    shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough

      0  

    Default


    Being a nitpicker here as this work is great and looking forward to sticking my teeth into it - but could the classes be renamed so they work better with the loader? For the time being I have put the two files at:

    sdk/src/data/proxy/SqliteStorage.js, and
    sdk/src/sqlite/Connection.js

    So their paths match their class names - a small issue but makes it easier for people using the proxy for the first time!

  6. #36
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    Quote Originally Posted by shepsii View Post
    Being a nitpicker here as this work is great and looking forward to sticking my teeth into it - but could the classes be renamed so they work better with the loader? For the time being I have put the two files at:

    sdk/src/data/proxy/SqliteStorage.js, and
    sdk/src/sqlite/Connection.js

    So their paths match their class names - a small issue but makes it easier for people using the proxy for the first time!
    I haven't considered the loader scenario , thanks for the suggestions, this will be helpful for many others.
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  7. #37
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    508
    Vote Rating
    73
    shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough

      0  

    Default


    Hey Tom,

    Thanks again for this work, I can't tell you how useful it is to my project which really needs more than localstorage can provide. Saving me so much time!

    I just had a couple more suggestions for you, changes I've made to the SqliteStorage.js file, that again others might find useful.

    I put a debug config on the class and when this is set to false, no errors are logged to the console; useful when you trust that the proxy is doing what it should and want to debug other areas of your project without the console being swamped!

    I also had a case where I was trying to use a callback on record.save() to then use the record's id as a foreign key in another db table. The issue I ran into was that the operation of the create method on the Ext.data.proxy.SqliteStorage class sets the operation to completed and successful when the query has been sent to the db connection; not when the query has been successfully executed. Therefore, record.get('id'); as in the code below was returning undefined:

    Code:
    record.save(function() {
      record.get('id');
    });
    I put a workaround into the proxy that may be a bit hacky but it works; basically I added a callback to the setRecord function, and then inside the for loop of the create function I used this callback to count completed records. When completed records equals records.length, then I set the operation to completed and successful, and execute the callback to the create function. This works for me but may not be the best way of doing it!

    Thanks again for all the hard work, invaluable for those looking to leverage the advantages Sqlite can get them in ST2, particularly important with how awkward localstorage can be with ST2.

  8. #38
    Sencha User
    Join Date
    Mar 2012
    Posts
    5
    Vote Rating
    0
    daveik is on a distinguished road

      0  

    Default


    I'm trying to get it running with the loader. I'm now stuck with this error message:

    Code:
    
    Cannot read property 'dbConn' of undefined SqliteStorage.js:120
    Does anybody has a clue? I'm new to Sencha. Sorry.

  9. #39
    Sencha User
    Join Date
    Mar 2012
    Posts
    5
    Vote Rating
    0
    daveik is on a distinguished road

      0  

    Default


    found the problem. DBConnection need to be defined before the stores and models. I got the hint from here: http://www.sencha.com/forum/showthre...iteProxy/page3

    thanks

  10. #40
    Sencha User
    Join Date
    Mar 2012
    Posts
    1
    Vote Rating
    0
    nsicad is on a distinguished road

      0  

    Default Need a Simple ST2 Demo with SqliteProxy2 for PhoneGap SQLite-plugin testing

    Need a Simple ST2 Demo with SqliteProxy2 for PhoneGap SQLite-plugin testing


    Hi,

    (Edited).

    My mistake, the github has already the demo example.

    I need just to figure out how to work this demo in PhoneGap.

    Thanks.

    Noli