Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4321968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:48:49+00:00 2026-05-21T08:48:49+00:00

I’m working on a Titanium app and have build a function to run sqlite

  • 0

I’m working on a Titanium app and have build a function to run sqlite database queries and return a result set (array).

I’ll not bother going too far into Titaniums details as it shouldnt make too much difference to the issue I’m facing.

Basically any query can be executed using this function, so naturally once its executed you need an array of data which corresponds to certain database column names. This is where I’m having an issue. With the way the titanium system works, I need to push the results into a results array, like so:

var resultSet = conn.execute('SELECT * FROM some_table WHERE parent = ?', parent);
    if (resultSet.isValidRow()) {
        result = {
            id: resultSet.fieldByName('id'),
            name: resultSet.fieldByName('name'),
            parent: resultSet.fieldByName('parent'),
            order: resultSet.fieldByName('order')
        };
    }

Ok, so thats all ok. But its not dynamic enough. What happens when you want to select from a different table, with different fields. id, name, parent and order are obviously not going to work.

What I’m trying to do is take an array (which I’ve already got) and use the values as their names, like so:

var resultSet = conn.execute(<!-- SQL IS IN HERE -->);
var fieldCount = resultSet.fieldCount();
var fields = [];
for(i=0;i<fieldCount;i++) {
    fields.push(resultSet.fieldName(i));
};
// At this point we have an array 'fields' which contains all the field names.

var results = [];
    while (resultSet.isValidRow()) {
    results.push({
// START OF PROBLEM
        for(i=0; i < fields.length; i++)
        {
            fields[i]: resultSet.fieldByName(fields[i]);
        }
// END OF PROBLEM
    });
    resultSet.next();
};
resultSet.close();

The commented start/end above shows the problem code. I realise its wrong, however cant figure out how it should be. Lets say the field array contains ‘id’ and ‘name’, I need variables to cover the two of them, but they must be dynamic – I want to avoid having to create a new javascript function for every table.

I should point out that I’m a PHP guy and my experience in JS is very limited. I’ve been using this as an opportunity to learn but just cant get my head around this one! Really sorry if its not explained clearly enough and hope that a JS guru can lend a hand here!

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:48:50+00:00Added an answer on May 21, 2026 at 8:48 am

    You almost got it, except you were trying to iterate through the fields array within an object literal, which is completely invalid – you can only have key-value pairs within an object literal.

    var resultSet = conn.execute(<!-- SQL IS IN HERE -->);
    var fieldCount = resultSet.fieldCount;
    var fields = [];
    for(var i = 0; i < fieldCount;i++) {
        fields.push(resultSet.fieldName(i));
    };
    
    var results = [];
    while (resultSet.isValidRow()) {
        for(var i=0; i < fields.length; i++) {
           results[i] = {};
           results[i][fields[i]] = resultSet.fieldByName(fields[i]);
        }
        resultSet.next();
    };
    resultSet.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.