android - SQLite - add new itens to result -
i'm using cordova sqlite storage plugin in application android. need result 2 tables display in view, tables "posts" , "metas"...
so can publish 'products' (posts table) , informations price , color save in metas table. problem when need show metas products, need list , after information table metas, need add metas in principal result (from first query).
actually returned
results.rows.item(i).id results.rows.item(i).title results.rows.item(i).date
and want add others items this
results.rows.item(i).id results.rows.item(i).title results.rows.item(i).date results.rows.item(i).price results.rows.item(i).color
but don't know how this, can me?
this functions...
function query( sql, callback ){ db.transaction(function(transaction) { var executequery = sql; transaction.executesql(executequery, [ ], function(tx, result) { //success if( typeof( callback ) == 'function' ){ callback( result ); } }, function(error){ // error }); } } function get_meta( data, strmetakey, callback ){ for( i=0; < data.length; i++ ){ // query query( /* sql id = i.id , meta_key = strmetakey*/, function( result ){ // here problem, can't add 'price' data data.rows.item( ).price = result.rows.item(0).meta_value; }); } if( typeof( callback ) == 'function' ){ callback( data ); } } new_data = ''; // getting products query( /* query */, function( result ){ // getting price get_meta( result, 'price', function( result ){ new_data = result; }); // getting color get_meta( result, 'color', function( result ){ new_data = result; }); });
database schema
posts id title date type metas id meta_key meta_value
to add specific meta keys query on main table, can use correlated subqueries values up:
select id, title, date, (select meta_value metas id = posts.id , meta_key = 'price' ) price, (select meta_value metas id = posts.id , meta_key = 'color' ) color posts;
Comments
Post a Comment