-
19 Apr 2011 11:17 PM #1
SQLIteStore LEFT JOIN and add new fields to select
SQLIteStore LEFT JOIN and add new fields to select
Hi !
this my store:
How can I add LEFT JOIN and new columns to SQL.PHP Code:this.store = new Ext.data.SQLiteStore ({
dbFile : 'data/unitech.db',
tableName : Unitech.Tables.Product,
baseParams : { start: 0, limit: this.pageSize },
idProperty : 'id',
autoLoad : true,
remoteSort : true,
sortInfo : { field: 'date_added', direction: 'DESC' },
fields : [
{ type: 'int', name: 'id' },
{ type: 'string', name: 'barcode' },
{ type: 'string', name: 'name' },
{ type: 'int', name: 'category_id' },
{ type: 'float', name: 'price' },
{ type: 'int', name: 'unit' },
{ type: 'int', name: 'date_added' },
{ type: 'int', name: 'date_modified' },
{ type: 'int', name: 'total' },
{ type: 'int', name: 'available' }
],
});
Thanks
-
20 Apr 2011 7:03 AM #2
Create a view and use it as tableName.
Programming today is a race between software engineers striving to build bigger and better іdiot-proof programs, and the universe striving to produce bigger and better idiots. So far, the universe is winning. (Rick Cook)
Enhanced ExtJS adapter for Adobe AIR
-
21 Apr 2011 1:20 AM #3
Can you show me an example ? I am newbe.
Thank you very much!
-
21 Apr 2011 11:44 PM #4
Hi!
Use a database management tool, like the SQLiteManager addon for firefox, and open your database with it.
Then create a view like:
and apply the view's name (here "myView") to the tableName config option of the store:Code:CREATE VIEW myView AS SELECT t1.field1, t1.field2, t2.field3, t2.field4 FROM myTable1 t1 LEFT JOIN myTable2 t2 ON t1.foreignKeyToT2Column = t2.primaryKeyColumn
You can then use the view to make reading requests to the database via the store.Code:this.store = new Ext.data.SQLiteStore ({ dbFile : 'data/unitech.db', tableName : Unitech.Tables.Product, tableName : 'myView', baseParams : { start: 0, limit: this.pageSize }, idProperty : 'id', autoLoad : true, remoteSort : true, sortInfo : { field: 'date_added', direction: 'DESC' }, fields : [ { type: 'int', name: 'id' }, { type: 'string', name: 'barcode' }, { type: 'string', name: 'name' }, { type: 'int', name: 'category_id' }, { type: 'float', name: 'price' }, { type: 'int', name: 'unit' }, { type: 'int', name: 'date_added' }, { type: 'int', name: 'date_modified' }, { type: 'int', name: 'total' }, { type: 'int', name: 'available' } ], });
If you want to do insert, update or delete operations on the store, too, you have to create triggers on your view. E.g.
See http://www.sqlite.org/lang_createtrigger.html for more information.Code:CREATE TRIGGER myViewTriggerInsert INSTEAD OF INSERT ON myView FOR EACH ROW BEGIN INSERT OR REPLACE INTO myTable2 (field3, field4) VALUES (new.field3, new.field4); INSERT INTO myTable1 (field1, field2, foreignKeyToT2Column) VALUES (new.field1, new.field2, (SELECT primaryKeyColumn FROM myTable2 WHERE field3 = new.field3 AND field4 = new.field4)); END
Cheers,
makanaProgramming today is a race between software engineers striving to build bigger and better іdiot-proof programs, and the universe striving to produce bigger and better idiots. So far, the universe is winning. (Rick Cook)
Enhanced ExtJS adapter for Adobe AIR
Similar Threads
-
Rowexp + json, left outer join
By RedJane in forum Ext 3.x: Help & DiscussionReplies: 3Last Post: 10 Dec 2009, 7:57 AM -
[Solved]Left align form fields
By yuiman in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 19 Feb 2009, 4:16 PM -
How to use Select with inner join in Short Colunm Grid
By Rafael in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 19 Dec 2008, 8:58 AM


Reply With Quote