[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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please post code that shows how you're calling this function.
G00fyAuthor Commented:
   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),
G00fyAuthor Commented:
f1 = int,
f2->5 = wxString (converted to multi-byte string (char*) by the function .mb_str(wxConvUTF8)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Are you compiling this in a UNICODE project?

If it's not a UNICODE project, the above Format will fail with wide string.
For wide strings, the code should be using one of the following:


It will fail to work if it uses
G00fyAuthor Commented:
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?
G00fyAuthor Commented:
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!
PAQd, 300 points refunded.

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.