#ifndef STOOLAP_H
#define STOOLAP_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct StoolapDB StoolapDB;
typedef struct StoolapStmt StoolapStmt;
typedef struct StoolapTx StoolapTx;
typedef struct StoolapRows StoolapRows;
#define STOOLAP_OK 0
#define STOOLAP_ERROR 1
#define STOOLAP_ROW 100
#define STOOLAP_DONE 101
#define STOOLAP_TYPE_NULL 0
#define STOOLAP_TYPE_INTEGER 1
#define STOOLAP_TYPE_FLOAT 2
#define STOOLAP_TYPE_TEXT 3
#define STOOLAP_TYPE_BOOLEAN 4
#define STOOLAP_TYPE_TIMESTAMP 5
#define STOOLAP_TYPE_JSON 6
#define STOOLAP_TYPE_BLOB 7
#define STOOLAP_ISOLATION_READ_COMMITTED 0
#define STOOLAP_ISOLATION_SNAPSHOT 1
typedef struct StoolapValue {
int32_t value_type;
int32_t _padding;
union {
int64_t integer;
double float64;
int32_t boolean;
struct { const char* ptr; int64_t len; } text;
struct { const uint8_t* ptr; int64_t len; } blob;
int64_t timestamp_nanos;
} v;
} StoolapValue;
const char* stoolap_version(void);
int32_t stoolap_open(const char* dsn, StoolapDB** out_db);
int32_t stoolap_open_in_memory(StoolapDB** out_db);
int32_t stoolap_clone(const StoolapDB* db, StoolapDB** out_db);
int32_t stoolap_close(StoolapDB* db);
const char* stoolap_errmsg(const StoolapDB* db);
int32_t stoolap_exec(StoolapDB* db, const char* sql, int64_t* rows_affected);
int32_t stoolap_exec_params(
StoolapDB* db,
const char* sql,
const StoolapValue* params,
int32_t params_len,
int64_t* rows_affected
);
int32_t stoolap_query(StoolapDB* db, const char* sql, StoolapRows** out_rows);
int32_t stoolap_query_params(
StoolapDB* db,
const char* sql,
const StoolapValue* params,
int32_t params_len,
StoolapRows** out_rows
);
int32_t stoolap_prepare(StoolapDB* db, const char* sql, StoolapStmt** out_stmt);
int32_t stoolap_stmt_exec(
StoolapStmt* stmt,
const StoolapValue* params,
int32_t params_len,
int64_t* rows_affected
);
int32_t stoolap_stmt_query(
StoolapStmt* stmt,
const StoolapValue* params,
int32_t params_len,
StoolapRows** out_rows
);
const char* stoolap_stmt_sql(const StoolapStmt* stmt);
void stoolap_stmt_finalize(StoolapStmt* stmt);
const char* stoolap_stmt_errmsg(const StoolapStmt* stmt);
int32_t stoolap_begin(StoolapDB* db, StoolapTx** out_tx);
int32_t stoolap_begin_with_isolation(
StoolapDB* db,
int32_t isolation,
StoolapTx** out_tx
);
int32_t stoolap_tx_exec(StoolapTx* tx, const char* sql, int64_t* rows_affected);
int32_t stoolap_tx_exec_params(
StoolapTx* tx,
const char* sql,
const StoolapValue* params,
int32_t params_len,
int64_t* rows_affected
);
int32_t stoolap_tx_query(StoolapTx* tx, const char* sql, StoolapRows** out_rows);
int32_t stoolap_tx_query_params(
StoolapTx* tx,
const char* sql,
const StoolapValue* params,
int32_t params_len,
StoolapRows** out_rows
);
int32_t stoolap_tx_stmt_exec(
StoolapTx* tx,
const StoolapStmt* stmt,
const StoolapValue* params,
int32_t params_len,
int64_t* rows_affected
);
int32_t stoolap_tx_stmt_query(
StoolapTx* tx,
const StoolapStmt* stmt,
const StoolapValue* params,
int32_t params_len,
StoolapRows** out_rows
);
int32_t stoolap_tx_commit(StoolapTx* tx);
int32_t stoolap_tx_rollback(StoolapTx* tx);
const char* stoolap_tx_errmsg(const StoolapTx* tx);
int32_t stoolap_rows_next(StoolapRows* rows);
int32_t stoolap_rows_column_count(const StoolapRows* rows);
const char* stoolap_rows_column_name(const StoolapRows* rows, int32_t index);
int32_t stoolap_rows_column_type(const StoolapRows* rows, int32_t index);
int64_t stoolap_rows_column_int64(const StoolapRows* rows, int32_t index);
double stoolap_rows_column_double(const StoolapRows* rows, int32_t index);
const char* stoolap_rows_column_text(StoolapRows* rows, int32_t index, int64_t* out_len);
int32_t stoolap_rows_column_bool(const StoolapRows* rows, int32_t index);
int64_t stoolap_rows_column_timestamp(const StoolapRows* rows, int32_t index);
const uint8_t* stoolap_rows_column_blob(const StoolapRows* rows, int32_t index, int64_t* out_len);
int32_t stoolap_rows_column_is_null(const StoolapRows* rows, int32_t index);
int64_t stoolap_rows_affected(const StoolapRows* rows);
void stoolap_rows_close(StoolapRows* rows);
const char* stoolap_rows_errmsg(const StoolapRows* rows);
int32_t stoolap_rows_fetch_all(
StoolapRows* rows,
uint8_t** out_buf,
int64_t* out_len
);
void stoolap_buffer_free(uint8_t* buf, int64_t len);
void stoolap_string_free(char* s);
#ifdef __cplusplus
}
#endif
#endif