char *sqlite3_mprintf(const char*,...); char *sqlite3_vmprintf(const char*, va_list); char *sqlite3_snprintf(int,char*,const char*, ...); char *sqlite3_vsnprintf(int,char*,const char*, va_list);
These routines are work-alikes of the "printf()" family of functions from the standard C library. These routines understand most of the common formatting options from the standard library printf() plus some additional non-standard formats (%q, %Q, %w, and %z). See the built-in printf() documentation for details.
R-25638-20415:[The sqlite3_mprintf() and sqlite3_vmprintf() routines write their results into memory obtained from sqlite3_malloc64(). ] The strings returned by these two routines should be released by sqlite3_free(). R-50083-49187:[Both routines return a NULL pointer if sqlite3_malloc64() is unable to allocate enough memory to hold the resulting string. ]
R-36610-45292:[The sqlite3_snprintf() routine is similar to "snprintf()" from the standard C library. The result is written into the buffer supplied as the second parameter whose size is given by the first parameter. Note that the order of the first two parameters is reversed from snprintf(). ] This is an historical accident that cannot be fixed without breaking backwards compatibility. R-45725-33143:[Note also that sqlite3_snprintf() returns a pointer to its buffer instead of the number of characters actually written into the buffer. ] We admit that the number of characters written would be a more useful return value but we cannot change the implementation of sqlite3_snprintf() now without breaking compatibility.
R-09798-06276:[As long as the buffer size is greater than zero, sqlite3_snprintf() guarantees that the buffer is always zero-terminated. ] R-04304-33529:[The first parameter "n" is the total size of the buffer, including space for the zero terminator. ] So the longest string that can be completely written will be n-1 characters.
R-34407-33329:[The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). ]
See also: built-in printf(), printf() SQL function
See also lists of Objects, Constants, and Functions.