[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now



Posted on 2004-10-28
Medium Priority
Last Modified: 2008-01-09
[code]wxString SQLite3_Db::Format( const wxString& format, ... )
  va_list marker;
  va_start(marker, format);
  char * t = sqlite3_vmprintf( format.mb_str(wxConvUTF8).data(), marker );


  wxString retVal( t, wxConvUTF8 );

  sqlite3_free( t );

  return retVal;

This is code I have to format a string. For some this might look Chinese, but let me explain.
I want to send something like 'printf('SELECT * FROM %s', 'tablename')'.
the sqlite3_vmprintf() function should do that (because it has the added value of having the '%q' which inserts a string, escaping the "dangerous" characters.

Now when I do this, the first va_arg that I got into the sqlite-function is the pointer of the second argument.

What I mean is:

::Format("%d %s %s", 1, "test", "test2");

In the sqlite3_ functions I receive the correct format, and then sqlite starts parsing. but in %d the va_arg() is taking from "test", so it displays the integer value of a pointer... Which is obviously not what I want to achieve.

I already asked on the sqlite mailing list, but they opt that it would be a problem in the va_* functions.

Can someone of you help me with this please?

Question by:G00fy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 30

Expert Comment

ID: 12433746
Please post code that shows how you're calling this function.

Author Comment

ID: 12456015
   SQLite3_Db::Format( wxT("INSERT INTO table(f1, f2, f3, f4, f5) ")
                        wxT("VALUES (        %ld, '%q',     '%q',      '%q',    '%q');"),
                        ID, name.mb_str(wxConvUTF8), group.mb_str(wxConvUTF8), section.mb_str(wxConvUTF8),

Author Comment

ID: 12456018
f1 = int,
f2->5 = wxString (converted to multi-byte string (char*) by the function .mb_str(wxConvUTF8)
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 30

Expert Comment

ID: 12456339
Are you compiling this in a UNICODE project?

If it's not a UNICODE project, the above Format will fail with wide string.
LVL 30

Expert Comment

ID: 12456348
For wide strings, the code should be using one of the following:


It will fail to work if it uses

Author Comment

ID: 12456718
It's not really a problem of widestrings and so on...

SQLite uses it's own v(w)printf-function.

The problem is that in the '%ld' variable, the pointer of 'f2' is put... So I think more of a var_list problem I did not spot?

Author Comment

ID: 12475826
I already found the solution to my problem.

It is because of the "wxString format" I pass... When I pass a char* and do exactly the same it works like a charm... So I changed the function header and it's ok.

Thanks for any help!

Accepted Solution

GhostMod earned 0 total points
ID: 12519785
PAQd, 300 points refunded.

Community Support Moderator

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question