3 Replies Latest reply on Jul 6, 2011 4:14 PM by kokorito

    Flex + SQlite

    JasonBr42 Level 1

      Hey there, I am trying to figure out how to insert each row of my arraylist into a new SQLite table.

       

      I tried this =

      for each (var item in myArrayList)
      {
              dbStatement.execute("insert into Products values(?)", (item,));
      }

       

      but it gives me a missing parenthesis error....

       

      Any ideas?

       

      Thanks!

        • 1. Re: Flex + SQlite
          kokorito Level 4

          you need to put the sql in the text property and then execute

          also, I've not seen a sql statement like that before, I've always done it like this

           

          dbStatement.text = "insert into Products (col1,col2,col3) VALUES(:col1,:col2,:col3)";

          dbStatement.parameters['col1'] = item.prop1;

          dbStatement.parameters['col2'] = item.prop2;

          dbStatement.parameters['col3'] = item.prop3;

          dbStatement.execute();

           

           

          assuming of course that you've already connected to and created the Products table

          • 2. Re: Flex + SQlite
            JasonBr42 Level 1

            Yeah, I think I mis-read somewhere that flex was able to simply accept a complex object array and create a table with it.

             

            So in looking at your suggestion there can you explain the following statement?

             

            dbStatement.text = "insert into Products (col1,col2,col3) VALUES(:col1,:col2,:col3)";

             

             

            is  Products (col1,col2,col3)  the label for each column  

             

            and is VALUES(:col1,:col2,:col3)";   the arrays label for each colum to correlate the two?

            • 3. Re: Flex + SQlite
              kokorito Level 4

              sorry, yes the col1, col2 are the column names in the table, the values list :col1, :col2 are parameters that correspond to the columns

              then set their values in the dbStatement[':param_name'] =

               

              sql.text = "INSERT INTO Products (id,price) VALUES (:id,:price)";

              sql.parameters[":id"] = item.id;

              sql.parameters[":price"] = item.price;

              sql.execute();