Mercurial
comparison deita/d_query.c @ 75:ae6a88e6e484
[Deita] Simple DB connection lib.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 31 Dec 2025 11:20:08 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 74:4b96794c8d59 | 75:ae6a88e6e484 |
|---|---|
| 1 #include "deita_internal.h" | |
| 2 #include <stdio.h> | |
| 3 | |
| 4 Deita_Result_Set* Deita_Query_Execute( | |
| 5 Deita_Connection *p_connection, | |
| 6 const char *query, | |
| 7 Dowa_Arena *p_arena) | |
| 8 { | |
| 9 if (!p_connection || !query) | |
| 10 return NULL; | |
| 11 | |
| 12 if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 13 return deita__sqlite_query_execute(p_connection, query, p_arena); | |
| 14 | |
| 15 fprintf(stderr, "Deita_Query_Execute: Unsupported database type %d\n", p_connection->database_type); | |
| 16 return NULL; | |
| 17 } | |
| 18 | |
| 19 Deita_Result_Set* Deita_Query_Execute_Prepared( | |
| 20 Deita_Connection *p_connection, | |
| 21 const char *query, | |
| 22 int32 parameter_count, | |
| 23 const char **parameter_values, | |
| 24 Dowa_Arena *p_arena) | |
| 25 { | |
| 26 if (!p_connection || !query) | |
| 27 return NULL; | |
| 28 | |
| 29 if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 30 return deita__sqlite_query_execute_prepared(p_connection, query, parameter_count, parameter_values, p_arena); | |
| 31 | |
| 32 fprintf(stderr, "Deita_Query_Execute_Prepared: Unsupported database type %d\n", p_connection->database_type); | |
| 33 return NULL; | |
| 34 } | |
| 35 | |
| 36 int32 Deita_Query_Execute_Update( | |
| 37 Deita_Connection *p_connection, | |
| 38 const char *query) | |
| 39 { | |
| 40 if (!p_connection || !query) | |
| 41 return -1; | |
| 42 | |
| 43 if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 44 return deita__sqlite_query_execute_update(p_connection, query); | |
| 45 | |
| 46 fprintf(stderr, "Deita_Query_Execute_Update: Unsupported database type %d\n", p_connection->database_type); | |
| 47 return -1; | |
| 48 } | |
| 49 | |
| 50 int32 Deita_Query_Execute_Update_Prepared( | |
| 51 Deita_Connection *p_connection, | |
| 52 const char *query, | |
| 53 int32 parameter_count, | |
| 54 const char **parameter_values) | |
| 55 { | |
| 56 if (!p_connection || !query) | |
| 57 return -1; | |
| 58 | |
| 59 if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 60 return deita__sqlite_query_execute_update_prepared(p_connection, query, parameter_count, parameter_values); | |
| 61 | |
| 62 fprintf(stderr, "Deita_Query_Execute_Update_Prepared: Unsupported database type %d\n", p_connection->database_type); | |
| 63 return -1; | |
| 64 } | |
| 65 | |
| 66 boolean Deita_Result_Set_Next(Deita_Result_Set *p_result_set) | |
| 67 { | |
| 68 if (!p_result_set) | |
| 69 return FALSE; | |
| 70 | |
| 71 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 72 return deita__sqlite_result_set_next(p_result_set); | |
| 73 | |
| 74 fprintf(stderr, "Deita_Result_Set_Next: Unsupported database type %d\n", p_result_set->database_type); | |
| 75 return FALSE; | |
| 76 } | |
| 77 | |
| 78 int32 Deita_Result_Set_Get_Column_Count(Deita_Result_Set *p_result_set) | |
| 79 { | |
| 80 if (!p_result_set) | |
| 81 return 0; | |
| 82 | |
| 83 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 84 return deita__sqlite_result_set_get_column_count(p_result_set); | |
| 85 | |
| 86 fprintf(stderr, "Deita_Result_Set_Get_Column_Count: Unsupported database type %d\n", p_result_set->database_type); | |
| 87 return 0; | |
| 88 } | |
| 89 | |
| 90 const char* Deita_Result_Set_Get_Column_Name( | |
| 91 Deita_Result_Set *p_result_set, | |
| 92 int32 column_index) | |
| 93 { | |
| 94 if (!p_result_set) | |
| 95 return NULL; | |
| 96 | |
| 97 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 98 return deita__sqlite_result_set_get_column_name(p_result_set, column_index); | |
| 99 | |
| 100 fprintf(stderr, "Deita_Result_Set_Get_Column_Name: Unsupported database type %d\n", p_result_set->database_type); | |
| 101 return NULL; | |
| 102 } | |
| 103 | |
| 104 Deita_Column_Type Deita_Result_Set_Get_Column_Type( | |
| 105 Deita_Result_Set *p_result_set, | |
| 106 int32 column_index) | |
| 107 { | |
| 108 if (!p_result_set) | |
| 109 return DEITA_COLUMN_TYPE_NULL; | |
| 110 | |
| 111 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 112 return deita__sqlite_result_set_get_column_type(p_result_set, column_index); | |
| 113 | |
| 114 fprintf(stderr, "Deita_Result_Set_Get_Column_Type: Unsupported database type %d\n", p_result_set->database_type); | |
| 115 return DEITA_COLUMN_TYPE_NULL; | |
| 116 } | |
| 117 | |
| 118 const char* Deita_Result_Set_Get_Text( | |
| 119 Deita_Result_Set *p_result_set, | |
| 120 int32 column_index) | |
| 121 { | |
| 122 if (!p_result_set) | |
| 123 return NULL; | |
| 124 | |
| 125 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 126 return deita__sqlite_result_set_get_text(p_result_set, column_index); | |
| 127 | |
| 128 fprintf(stderr, "Deita_Result_Set_Get_Text: Unsupported database type %d\n", p_result_set->database_type); | |
| 129 return NULL; | |
| 130 } | |
| 131 | |
| 132 int64 Deita_Result_Set_Get_Integer( | |
| 133 Deita_Result_Set *p_result_set, | |
| 134 int32 column_index) | |
| 135 { | |
| 136 if (!p_result_set) | |
| 137 return 0; | |
| 138 | |
| 139 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 140 return deita__sqlite_result_set_get_integer(p_result_set, column_index); | |
| 141 | |
| 142 fprintf(stderr, "Deita_Result_Set_Get_Integer: Unsupported database type %d\n", p_result_set->database_type); | |
| 143 return 0; | |
| 144 } | |
| 145 | |
| 146 double Deita_Result_Set_Get_Real( | |
| 147 Deita_Result_Set *p_result_set, | |
| 148 int32 column_index) | |
| 149 { | |
| 150 if (!p_result_set) | |
| 151 return 0.0; | |
| 152 | |
| 153 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 154 return deita__sqlite_result_set_get_real(p_result_set, column_index); | |
| 155 | |
| 156 fprintf(stderr, "Deita_Result_Set_Get_Real: Unsupported database type %d\n", p_result_set->database_type); | |
| 157 return 0.0; | |
| 158 } | |
| 159 | |
| 160 void Deita_Result_Set_Free(Deita_Result_Set *p_result_set) | |
| 161 { | |
| 162 if (!p_result_set) | |
| 163 return; | |
| 164 | |
| 165 if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) | |
| 166 { | |
| 167 deita__sqlite_result_set_free(p_result_set); | |
| 168 return; | |
| 169 } | |
| 170 | |
| 171 fprintf(stderr, "Deita_Result_Set_Free: Unsupported database type %d\n", p_result_set->database_type); | |
| 172 } |