0
votes

Need to update database by new value (Name and Address) provided by the user.The error in query is that:

  1. error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive] sqlite3_bind_text(res, 2, *c2)

    1. error: too few arguments to function ‘int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int, void ()(void))’ sqlite3_bind_text(res, 2, *c2)

my code is:

        const char *c1 = updatedName.c_str();
        const char *c2 = updatedAdd.c_str();

char *sql = ("UPDATE RECORDS SET NAME = ? AND ADDRESS = ? WHERE ACCOUNT_No = ?");
        rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
        sqlite3_bind_text(res, 1, *c1);
        sqlite3_bind_text(res, 2, *c2);
        sqlite3_bind_int(res, 3, acc);
        rc = sqlite3_step(res);
        sqlite3_finalize(res);
1
2. The compiler is telling you that sqlite3_bind_text takes 5 arguments but you only provide 3, so 2 arguments are missing. - Weather Vane
@Jean-FrançoisFabre it is throwing too few arguments to function ‘int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int, void ()(void))’ sqlite3_bind_text(res, 1, c1, 0); this error - kulst
sorry, a function must be passed as last arg. Check the documentation... some example: stackoverflow.com/questions/19927188/… - Jean-François Fabre
1. This is perhaps because of argument mis-match, when not enough arguments were supplied. As Jean-François said, please read the man pages. - Weather Vane
also, *c1 and *c2 are of type const char and the function ask for const char*. - Roy Avidan

1 Answers

0
votes

sqlite3_bind_text() wants a pointer to the entire string, not only the first character. (You need to understand how C pointers and strings (character arrays) work.)

And the sqlite3_bind_text() documentation tells you to use five parameters:

sqlite3_bind_text(res, 1, updatedName.c_str(), -1, SQLITE_TRANSIENT);