0

I'm trying to apply my entry in the lua in a code for sql in C.

My lua file has the following code:

prepare_sql = {
    flvdb = "flv_database";
};

My lua code is as follows:

lua_getglobal(L, "prepare_sql");
lua_getfield(L, -1, "flvdb");
p->flvdb = lua_tostring(L, -1);

My C code before applying lua code worked normally:

sql_prepare(SqlPrepare *stax, const char *qry, ...);

Before:

if(SQLPASS != sql_prepare(sqltp, "INSERT INTO `flv_database` (`date`, `value`, `count`) VALUES (NOW(), '%d', '%d')", p->value, p->cnt))

After:

if(SQLPASS != sql_prepare(sqltp, "INSERT INTO `%s` (`date`, `value`, `count`) VALUES (NOW(), '%d', '%d')", p->flvdb, p->value, p->cnt))

Before the code worked well, after applying lua he can't capture the name that is in the file. Does anyone have an idea of what can be?

Chozie
  • 73
  • 1
  • 9
  • try `printf("%s", p->flvdb)` to see what's in there – nonchip Nov 29 '15 at 21:51
  • I forgot to mention this, but I did it and it returns the correct name, equal is in the file, but when you apply sql function does not work – Chozie Nov 29 '15 at 22:38
  • Don't you need to do "`prepare_sql = {`" instead of "`prepare_sql {`"? Is it a typo in your question only? – Niccolo M. Nov 29 '15 at 22:52
  • Sorry the file is correct, my mistake when creating the topic. – Chozie Nov 29 '15 at 22:57
  • Define "doesn't work" at this point? What isn't working? Can you use a debugger or other tool to see exactly what is being passed into `sql_prepare` at that point? – Etan Reisner Nov 30 '15 at 02:22

1 Answers1

2

Because you cannot prepare a query with a variable table name. Your Lua code is ok.

marsgpl
  • 552
  • 2
  • 12