Skip to Main Content
Using SQLite
book

Using SQLite

by Jay A. Kreibich
August 2010
Intermediate to advanced content levelIntermediate to advanced
526 pages
23h 39m
English
O'Reilly Media, Inc.
Content preview from Using SQLite

Name

sqlite3_snprintf() — Format a string

Definition

char* sqlite3_snprintf( int bytes, char* buf, const char* format, ... );
bytes

The number of bytes available in the output buffer.

buf

A pre-allocated buffer to receive the formatted string.

format

The format string used to build the output string. This is similar to the standard printf() style formatted string, but it supports a few extra formatting flags.

Additional parameters

Message formatting parameters.

Returns

A pointer to the formatted string buffer.

Description

This function formats and builds a UTF-8 string in the provided buffer. It is designed to mimic the standard snprintf() function. Assuming the provided buffer is one byte or larger, the string will always be null-terminated.

Note that the first two parameters of sqlite3_snprintf() are reversed from the standard snprintf(). Also, snprintf() returns the number of characters in the output string, while sqlite3_snprintf() returns a pointer to the buffer passed in by the application.

In addition to the standard %s, %c, %d, %i, %o, %u, %x, %X, %f, %e, %E, %g, %G, and %% formatting flags, all SQLite printf() style functions also support the %q, %Q, %z, %w, and %p flags.

The %q flag is similar to %s, only it will sanitize the string for use as an SQL string literal. Mostly, this consists of doubling all the single quote characters (') to form a proper SQL escape (''). Thus, %q will take the input string O'Reilly and output O''Reilly. The formatted string should contain enclosing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning SQL, 3rd Edition

Learning SQL, 3rd Edition

Alan Beaulieu
High Performance MySQL, 4th Edition

High Performance MySQL, 4th Edition

Silvia Botros, Jeremy Tinley

Publisher Resources

ISBN: 9781449394592Errata PageSupplemental Content