samedi 30 janvier 2016

Does sqlite bind by reference or by value?

When I bind in sqlite, what actually happens, or essentially am I passing by reference or by value? If I bind a variable, does sqlite see changes in the value of the variable or is it a one-shot deal? Binding within the loop tells me I'm misusing the library, even if I clear the bindings at the end of the loop contents with sqlite3_clear_bindings. Binding first gets me no rows at all, even though the bind returns SQLITE_OK. (Is it binding a 0?)

    int cat;
    sql = "select x,y,z from table where q = ?"
    bind cat (to ?) here
    for (cat=0; cat<topcat; cat++) {
      //  I want (multiple) results for each cat value here
      rslt = 0;
      while ((rslt != SQLITE_DONE) && (rslt != SQLITE_ERROR)) {
        rslt = sqlite3_step(stmt2);
        // do column stuff here to fetch values
      }
    }

Another part of the program fetches all the rows from another table OK with no where clause in the SQL. If I take the where and bind out of this I can get all the rows. If I bind to a constant value like 3 instead of cat, that works.

Aucun commentaire:

Enregistrer un commentaire