---
name: "odbx_query"
section: "3"
platform: "linux"
package: "opendbx"
version: "1.4.6-13"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/odbx_query"
---

# odbx\_query(3)

Send a statement to the database server

## NAME

odbx\_query - Send a statement to the database server

## SYNOPSIS

```
FC#include <opendbx/api.h>F[0]
```

FCint **odbx\_query**F\[0\]  FC(odbx\_t\* *handle*, const char\* *stmt*, unsigned long *length*);F\[0\]

## DESCRIPTION

Sends the given statement to the database server associated to FChandleF\[0\] by FC**odbx\_init**F\[0\]() for execution. The statement can contain non-displayable characters as arguments in conditions but they have to be escaped via FC**odbx\_escape**F\[0\]() 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 FC**odbx\_query**F\[0\](), one or more result sets will be sent back by the server and are available via FC**odbx\_result**F\[0\](). Before these sets aren't processed by calling FC**odbx\_row\_fetch**F\[0\](), no other queries can be sent to the database server. Otherwise, FC**odbx\_query**F\[0\]() will return a backend error from the native database library.

The first parameter FChandleF\[0\] is the connection object created and returned by FC**odbx\_init**F\[0\]() which becomes invalid as soon as it was supplied to FC**odbx\_finish**F\[0\]().

The statement stored in the FCstmtF\[0\] 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 FC**odbx\_get\_option**F\[0\]().

The FClengthF\[0\] 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 FClengthF\[0\] parameter to the function, it will calculate the size of the statement on its own.

## RETURN VALUE

FC**odbx\_query**F\[0\]() returns FCODBX\_ERR\_SUCCESSF\[0\], 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 FC**odbx\_error**F\[0\]() and FC**odbx\_error\_type**F\[0\]() to get further details.

## ERRORS

- \-FCODBX\_ERR\_BACKENDF\[0\]

  The native database library returned an error because it wasn't able to handle the statement correctly

- \-FCODBX\_ERR\_PARAMF\[0\]

  Either FChandleF\[0\] or FCstmtF\[0\] are NULL or FChandleF\[0\] is invalid

- \-FCODBX\_ERR\_NOMEMF\[0\]

  Allocating the required memory for the statement failed

## SEE ALSO

FC**odbx\_error**F\[0\](), FC**odbx\_error\_type**F\[0\](), FC**odbx\_escape**F\[0\](), FC**odbx\_result**F\[0\]()
