[Vala] Referencing GLib.List elements..



Hey All -- I know this is going to be a stupid answer, but for the
life of me, I can't figure out what I need to do. I'm basically trying
to copy data, in JSON format, into a Sqlite table. The insert itself
is working as I get a row with all null values for every row I'm
pulling out of JSON. I'm pretty sure it's the way I'm binding the
values and I'm guessing it's because the value's are getting copied
and not actually getting set in the bound list, or I'm not binding the
list correctly.

Here's my code:

        string[] bound_data = new string[ columns.length() ];

        for (var i = 0; i < columns.length(); i++) {
          var index = statement.bind_parameter_index(
":%s".printf(columns.nth(i).data) );
          Posix.stdout.printf("%s: %d> Binding %s\n", table_name, i,
":%s".printf( columns.nth(i).data ));

          if ( index > 0 ) {
            rc = statement.bind_text(index, bound_data[i]);
            if ( rc != Sqlite.OK ) {
              throw new Database.Error.SQLITE(
                "Bind error on %s: %d, %s\n",
                (string)columns.nth(i),
                db.errcode(),
                db.errmsg()
              );
            }
          } else {
            Posix.stdout.printf("%s> %s: not bound\n", table_name,
":%s".printf( columns.nth(i).data ));
          }
        }

        var ct = 0;
        foreach (var record in
table_object.get_array_member("records").get_elements()) {
          var row = record.get_array();

          for (var i = 0; i < columns.length(); i++) {
            bound_data[i]=row.get_string_element(i);
          }

          rc = statement.step();
          if ( rc != Sqlite.DONE ) {
            throw new Database.Error.SQLITE(
              "Execute error on %s: %d, %s\n",
              table_name,
              db.errcode(),
              db.errmsg()
            );
          } else {
            Posix.stdout.printf("%s> %d\n", table_name, ct++);
          }
        }
      }

The only reason I'm using a List is because I will be loading multiple
different tables, with varying number of columns. If there's a better
way to do this, I'm open to suggestions. Using bind variables are a
must though. (gotta keep it secure, since I wont have complete control
over the incoming data)

Thanks for any help.. I know I'm gonna feel like an idiot when I get the answer

Shawn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]