odbx_query(3)

NAME
odbx_query - Send a statement to the database server

SYNOPSIS
\FC#include <opendbx/api.h>\F[]

\FCint odbx_query\F[]
\FC(odbx_t* handle, const char* stmt, unsigned long length);\F[]

DESCRIPTION
Sends the given statement to the database server associated to \FChandle\F[] by \FCodbx_init\F[]() for execution. The statement can contain non-displayable characters as arguments in conditions but they have to be escaped via \FCodbx_escape\F[]() before adding them to the statement. Even more, every argument whose source is not controlled by the programmer must be escaped first to avoid SQL injection attacks to avoid serious harm!

After invoking \FCodbx_query\F[](), one or more result sets will be sent back by the server and are available via \FCodbx_result\F[](). Before these sets aren't processed by calling \FCodbx_row_fetch\F[](), no other queries can be sent to the database server. Otherwise, \FCodbx_query\F[]() will return a backend error from the native database library.

The first parameter \FChandle\F[] is the connection object created and returned by \FCodbx_init\F[]() which becomes invalid as soon as it was supplied to \FCodbx_finish\F[]().

The statement stored in the \FCstmt\F[] parameter must be a valid statement understood by the receiving database server and it should be terminated by a \0 character. Some backends support multiple statements per query, which can be tested by calling \FCodbx_get_option\F[]().

The \FClength\F[] parameter must contain the length of the statement in bytes without the terminating \0 character. If variable sized character sets like UTF-8 are used, the same rule applies. This function doesn't support the wide character type (wchar_t) which uses two or four bytes per character. If you feed 0 (zero) as \FClength\F[] parameter to the function, it will calculate the size of the statement on its own.

RETURN VALUE
\FCodbx_query\F[]() returns \FCODBX_ERR_SUCCESS\F[], or an error code whose value is less than zero if one of the operations couldn't be completed successfully. Possible error codes are listed in the error section and they can be feed to \FCodbx_error\F[]() and \FCodbx_error_type\F[]() to get further details.

ERRORS

-\FCODBX_ERR_BACKEND\F[]
    The native database library returned an error because it wasn't able to handle the statement correctly

-\FCODBX_ERR_PARAM\F[]
    Either \FChandle\F[] or \FCstmt\F[] are NULL or \FChandle\F[] is invalid

-\FCODBX_ERR_NOMEM\F[]
    Allocating the required memory for the statement failed

SEE ALSO
\FCodbx_error\F[](), \FCodbx_error_type\F[](), \FCodbx_escape\F[](), \FCodbx_result\F[]()