• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1163
  • Last Modified:

va_list/end/...

[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 );

  va_end(marker);

  wxString retVal( t, wxConvUTF8 );

  sqlite3_free( t );

  return retVal;
}[/code]

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:

Sending:
::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?

Thx
0
G00fy
Asked:
G00fy
  • 4
  • 3
1 Solution
 
AxterCommented:
Please post code that shows how you're calling this function.
0
 
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),
                        info.mb_str(wxConvUTF8)
                      )
0
 
G00fyAuthor Commented:
f1 = int,
f2->5 = wxString (converted to multi-byte string (char*) by the function .mb_str(wxConvUTF8)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AxterCommented:
Are you compiling this in a UNICODE project?

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

vwprintf
_vsnwprintf

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

GhostMod
Community Support Moderator
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now