0

I have created a table in my websql using Sencha. Adding values to table works fine, but removing doesn't work.

I've tried

getStore('favorite').removeAt(1);

but it gave no result. Are there are ways to handle sql requests like

"Delete from favorite where id = 1" 

I've been Googling all day long. Any ideas? the code is below:

dockedItems: [
    {
        xtype: 'toolbar',
        dock: 'top',
        items: [
            {   

                text: '+',
                ui: 'decline',
                handler: function(){ 
                    var s_name = post.get('list');
                    var s_image = post.get('image');
                    //var s_type = record.get('code');
                    //var c_content = post.get('filmpage');
                    //alert('РаботаетЬ');

                    Ext.require(['Ext.data.proxy.SQL']);
                    Ext.define("Favorite", {
                        extend: "Ext.data.Model",
                        config: {
                        fields: ["id","name","ftype","image","link","res"]
                    }
                    });

                    Ext.create("Ext.data.Store", {
                    model: "Favorite",
                        storeId: 'Favorite',
                        proxy: {
                        type: "sql"
                        }
                    });

                    var store = Ext.getStore('Favorite');
                    Ext.getStore('Favorite').removeAt(1);
                    Ext.getStore('Favorite').sync();

                    var record = Ext.getStore('Favorite').findExact('id', 1);
                    Ext.getStore('Favorite').remove(record);
                    Ext.getStore('Favorite').sync();



                    /*Ext.getStore('Favorite').add([{
                        name: s_name,
                        ftype: cat,
                        image: s_image,
                        link: '',
                        res : '',
                    }]);


                    Ext.getStore('Favorite').sync();*/

                    //Ext.getStore("Users").getModel("Users").getProxy("Users").dropTable("Favorite");
                    //Ext.getStore("Favorite").getModel("Ext.data.Model").getProxy().dropTable();

                    }
            }
        ]
    }
]
trial4life
  • 21
  • 8
  • What exactly you want to do with removeAt() method – Viswa Aug 19 '13 at 10:36
  • i want to remove a field with a certain id in the table "Favorite" in the WebSql database "Sencha". sorry if ive described problem not clear enought – trial4life Aug 19 '13 at 13:56
  • sorry.. findExact will returning index not the record.. see update – Viswa Aug 19 '13 at 16:28
  • still the same, i tried to console.log(index) and it returned -1 I think this is not proper reply, though i have my table displaing in the websql of chrome with a lot of fieled, still maybe there is smth similar in sencha for hadling add/remove to favorite functiuons? – trial4life Aug 19 '13 at 16:44
  • do you have record with id 1 in the table ? also post the screen shot of web sql table. – Viswa Aug 19 '13 at 17:40
  • Yes i have it, but it isnt found though when i tried to finf ftype: 'cinema' it returned the value 0 and i logged console.log(store.getAt(index)); and get this Class {modified: Object, raw: Object, stores: Array[1], data: Object, _data: Object…} _data: Object data: Object dirty: false editing: false id: "ext-record-23" internalId: 11 modified: Object phantom: false raw: Object stores: Array[0] __proto__: Object – trial4life Aug 19 '13 at 17:57
  • also this result was even when i droped the table – trial4life Aug 19 '13 at 17:57
  • the screenshot – trial4life Aug 19 '13 at 17:59
  • try find method like this console.log(store.find('id', 1)); – Viswa Aug 19 '13 at 18:13
  • one more thing do you following MVC ? – Viswa Aug 19 '13 at 18:20
  • i ve tried it but it returned -1 . right now not at first i want to make the basic fuctional and than to structurize it. – trial4life Aug 19 '13 at 18:30

2 Answers2

1

find solution using js that works, still thank you very much for your help.

db = openDatabase("Sencha", "1.0", "Sencha", 200000);

if(!db)                                                                                         
   alert("Failed to connect to database.");   
else                      
  alert('yeah');

db.transaction(function(tx) {
 tx.executeSql("DELETE FROM Favorite WhERE id = 3 ", [], function(result){}, function(tx, error){});
});
Viswa
  • 3,211
  • 5
  • 34
  • 65
trial4life
  • 21
  • 8
0

You should sync after removing record

var store = Ext.getStore('favorite');
store.removeAt(1);
store.sync();

Update

var index = store.findExact('id', 1);       
store.remove(store.getAt(index));
store.sync();

How to debug

console.log(index); // Should return value 0 if there is a match else returns -1.

console.log(store.getAt(index)); // Should return the record with id value 1.

Viswa
  • 3,211
  • 5
  • 34
  • 65
  • thanks for your reply , but this gave no result. do i understand right that this code should remove row with id 1 ? and it doesnt – trial4life Aug 19 '13 at 10:16
  • @trial4life No, it removes the record at the given index. 1 is the index in the store data. – Viswa Aug 19 '13 at 10:23
  • ok. are there any ideas of how to remove from the websql table with a certain id, i v tried like this var index = Ext.getStore('Favorite').getRecordData(); Ext.getStore('Favorite').removeAt(index); Ext.getStore('Favorite').sync(); but that didnt work – trial4life Aug 19 '13 at 12:35
  • thanx but still have no result, maybe smth is wrong with the code? i ve posted it – trial4life Aug 19 '13 at 13:46
  • @trial4life sorry.. findExact will returning index not the record.. see update – Viswa Aug 19 '13 at 16:27
  • found this answer that says it is impossible to remove fields in web sql http://stackoverflow.com/questions/15108204/websql-drop-column-with-javascript is that true now& – trial4life Aug 20 '13 at 05:44
  • @trial4life it's not possible to alter table or change fields in a table. This is what they are saying. i posted the tested code.. i tied to delete the row using above code and it worked for me. – Viswa Aug 20 '13 at 05:53
  • thanx for ur help. i found solution that worked for me. see update if interested_\) – trial4life Aug 20 '13 at 06:31