开发者

parameters to Ellipses in C++

Is 开发者_运维知识库it possible to pass parameters of different types in Ellipses(...)? I am writing a function to make the SQL query, where I want to add values to the Insert statement through Ellipse and my values are of different type.


As a word of warning, don't be too clever with this. Not that I've suffered greatly for similar endeavors. :))

Sqlite has built in query builders, check those first. What they wont let you do is specify a table name, which is probably what your problem is.

boost::format is a good option for this. It's type safe and less likely to segfault on you like C's variadic arguments.

std::string statement = boost::str( 
    boost::format("SELECT tab.* FROM %1% as tab")
        % "my_table_name"
  );

EDIT:

Sqlite handles parameter binding on its own, you shouldn't need any variadic aruments for that.

The sqlite3_bind_* functions provide access.

You might use something like this:

const char *sql = "INSERT INTO tab (a,b) VALUES (?1,?2);";
// create statement
sqlite3_bind_int(stmt, 1, 43);
sqlite3_bind_int(stmt, 2, 40000);

These bind functions have return values which you must check, I'll leave that to you.


It's possible. You'd need some mechanism for determining the number and types of the parameters (such as printf's format string).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜