00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00039
00040 #ifndef ALP_SAL_H_
00041 #define ALP_SAL_H_ 1
00042
00043 #include <stdio.h>
00044 #include <string.h>
00045 #include <stdlib.h>
00046 #include <sqlite3.h>
00047 #include <hiker/types.h>
00048 #include <hiker/sysclass.h>
00049
00050
00051
00058 #define ALP_STATUS_SAL_BUSY (ALP_CLASS_SAL | 0x00010000)
00059 #define ALP_STATUS_SAL_LOCKED (ALP_CLASS_SAL | 0x00020000)
00060 #define ALP_STATUS_SAL_NOMEM (ALP_CLASS_SAL | 0x00030000)
00061 #define ALP_STATUS_SAL_READONLY (ALP_CLASS_SAL | 0x00040000)
00062 #define ALP_STATUS_SAL_INTERRUPT (ALP_CLASS_SAL | 0x00050000)
00063 #define ALP_STATUS_SAL_IOERR (ALP_CLASS_SAL | 0x00060000)
00064 #define ALP_STATUS_SAL_CORRUPT (ALP_CLASS_SAL | 0x00070000)
00065 #define ALP_STATUS_SAL_FULL (ALP_CLASS_SAL | 0x00080000)
00066 #define ALP_STATUS_SAL_CANTOPEN (ALP_CLASS_SAL | 0x00090000)
00067 #define ALP_STATUS_SAL_TOOBIG (ALP_CLASS_SAL | 0x000A0000)
00068 #define ALP_STATUS_SAL_CONSTRAINT (ALP_CLASS_SAL | 0x000B0000)
00069 #define ALP_STATUS_SAL_MISMATCH (ALP_CLASS_SAL | 0x000C0000)
00070 #define ALP_STATUS_SAL_AUTH (ALP_CLASS_SAL | 0x000D0000)
00071 #define ALP_STATUS_SAL_ERROR (ALP_CLASS_SAL | 0x000E0000)
00072 #define ALP_STATUS_SAL_MISUSE (ALP_CLASS_SAL | 0x000F0000)
00073 #define ALP_STATUS_SAL_NOLFS (ALP_CLASS_SAL | 0x00100000)
00074 #define ALP_STATUS_SAL_PROTOCOL (ALP_CLASS_SAL | 0x00110000)
00075 #define ALP_STATUS_SAL_EMPTY (ALP_CLASS_SAL | 0x00120000)
00076 #define ALP_STATUS_SAL_SCHEMA (ALP_CLASS_SAL | 0x00130000)
00077 #define ALP_STATUS_SAL_NOTFOUND (ALP_CLASS_SAL | 0x00140000)
00078 #define ALP_STATUS_SAL_INTERNAL (ALP_CLASS_SAL | 0x00150000)
00079 #define ALP_STATUS_SAL_PERM (ALP_CLASS_SAL | 0x00160000)
00080 #define ALP_STATUS_SAL_ABORT (ALP_CLASS_SAL | 0x00170000)
00081 #define ALP_STATUS_SAL_UNKNOWN (ALP_CLASS_SAL | 0x00180000)
00082 #define ALP_STATUS_SAL_BADPARAM (ALP_CLASS_SAL | 0x00190000)
00083 #define ALP_STATUS_SAL_NORECORDS (ALP_CLASS_SAL | 0x001A0000)
00084 #define ALP_STATUS_SAL_DMLEXISTS (ALP_CLASS_SAL | 0x001B0000)
00085
00088
00090 typedef void *AlpSALHandle;
00091
00096 typedef void *AlpSALStatement;
00097
00098
00099
00100 #ifdef __cplusplus
00101 extern "C" {
00102 #endif
00103
00111 extern alp_status_t alp_sal_database_open(AlpSALHandle *sal,
00112 const char *dbName);
00113 extern alp_status_t alp_sal_database_close(AlpSALHandle sal);
00114 extern alp_status_t alp_sal_database_create(const char *dbFileName,
00115 const char *schemaFileName);
00116
00117 extern alp_status_t alp_sal_transaction_commit(AlpSALHandle sal);
00118 extern alp_status_t alp_sal_transaction_begin(AlpSALHandle sal,
00119 char exclusive);
00120 extern alp_status_t alp_sal_transaction_rollback(AlpSALHandle sal);
00121
00122 extern alp_status_t alp_sal_sql_execute(AlpSALHandle sal, const char *sql, ...);
00123 extern alp_status_t alp_sal_last_insert_rowid(AlpSALHandle sal,
00124 uint32_t *rowID);
00125 extern alp_status_t alp_sal_execute_sql_script(AlpSALHandle sal, FILE *fd);
00126 extern alp_status_t alp_sal_sql_get_value(AlpSALHandle sal, int32_t
00127 *value, const char *sql, ...);
00128
00129 extern const char *alp_sal_get_error_message(AlpSALHandle sal);
00130
00131 extern alp_status_t alp_sal_string_build(char **combined,
00132 const char *sql, ...);
00133 extern void alp_sal_string_destroy(char *s);
00142
00143 extern alp_status_t alp_sal_statement_initialize(AlpSALHandle sal,
00144 AlpSALStatement **stmt, const char *sql);
00145 extern AlpSALHandle alp_sal_statement_get_handle(AlpSALStatement *stmt);
00146
00147 extern alp_status_t alp_sal_statement_set_text(AlpSALStatement *stmt,
00148 int16_t pos, const char *s, bool copy);
00149 extern alp_status_t alp_sal_statement_set_int(AlpSALStatement *stmt,
00150 int16_t pos, int32_t n);
00151 extern alp_status_t alp_sal_statement_set_int64(AlpSALStatement *stmt,
00152 int16_t pos, int64_t n);
00153 extern alp_status_t alp_sal_statement_set_blob(AlpSALStatement *stmt,
00154 int16_t pos, void *blob, int32_t size, bool copy);
00155 extern alp_status_t alp_sal_statement_set_float(AlpSALStatement *stmt,
00156 int16_t pos, float f);
00157
00158 extern int32_t alp_sal_statement_get_int(AlpSALStatement *stmt,
00159 int pos);
00160 extern int64_t alp_sal_statement_get_int64(AlpSALStatement *stmt,
00161 int pos);
00162 extern float alp_sal_statement_get_float(AlpSALStatement *stmt,
00163 int pos);
00164 extern char *alp_sal_statement_get_text(AlpSALStatement *stmt,
00165 int pos, bool copy);
00166 extern void *alp_sal_statement_get_blob(AlpSALStatement *stmt,
00167 int pos, int32_t *size, bool copy);
00168 extern bool alp_sal_statement_is_null(AlpSALStatement *stmt,
00169 int pos);
00170
00171 extern alp_status_t alp_sal_statement_execute(AlpSALStatement *stmt);
00172 extern alp_status_t alp_sal_statement_destroy(AlpSALStatement *stmt);
00173 extern alp_status_t alp_sal_statement_next_result(AlpSALStatement *stmt);
00174 extern alp_status_t alp_sal_statement_reset(AlpSALStatement *stmt);
00183 #ifdef __cplusplus
00184 }
00185 #endif
00186
00187 #endif
00188