Mercurial
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deita/d_query.c Wed Dec 31 11:20:08 2025 -0800 @@ -0,0 +1,172 @@ +#include "deita_internal.h" +#include <stdio.h> + +Deita_Result_Set* Deita_Query_Execute( + Deita_Connection *p_connection, + const char *query, + Dowa_Arena *p_arena) +{ + if (!p_connection || !query) + return NULL; + + if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_query_execute(p_connection, query, p_arena); + + fprintf(stderr, "Deita_Query_Execute: Unsupported database type %d\n", p_connection->database_type); + return NULL; +} + +Deita_Result_Set* Deita_Query_Execute_Prepared( + Deita_Connection *p_connection, + const char *query, + int32 parameter_count, + const char **parameter_values, + Dowa_Arena *p_arena) +{ + if (!p_connection || !query) + return NULL; + + if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_query_execute_prepared(p_connection, query, parameter_count, parameter_values, p_arena); + + fprintf(stderr, "Deita_Query_Execute_Prepared: Unsupported database type %d\n", p_connection->database_type); + return NULL; +} + +int32 Deita_Query_Execute_Update( + Deita_Connection *p_connection, + const char *query) +{ + if (!p_connection || !query) + return -1; + + if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_query_execute_update(p_connection, query); + + fprintf(stderr, "Deita_Query_Execute_Update: Unsupported database type %d\n", p_connection->database_type); + return -1; +} + +int32 Deita_Query_Execute_Update_Prepared( + Deita_Connection *p_connection, + const char *query, + int32 parameter_count, + const char **parameter_values) +{ + if (!p_connection || !query) + return -1; + + if (p_connection->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_query_execute_update_prepared(p_connection, query, parameter_count, parameter_values); + + fprintf(stderr, "Deita_Query_Execute_Update_Prepared: Unsupported database type %d\n", p_connection->database_type); + return -1; +} + +boolean Deita_Result_Set_Next(Deita_Result_Set *p_result_set) +{ + if (!p_result_set) + return FALSE; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_next(p_result_set); + + fprintf(stderr, "Deita_Result_Set_Next: Unsupported database type %d\n", p_result_set->database_type); + return FALSE; +} + +int32 Deita_Result_Set_Get_Column_Count(Deita_Result_Set *p_result_set) +{ + if (!p_result_set) + return 0; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_get_column_count(p_result_set); + + fprintf(stderr, "Deita_Result_Set_Get_Column_Count: Unsupported database type %d\n", p_result_set->database_type); + return 0; +} + +const char* Deita_Result_Set_Get_Column_Name( + Deita_Result_Set *p_result_set, + int32 column_index) +{ + if (!p_result_set) + return NULL; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_get_column_name(p_result_set, column_index); + + fprintf(stderr, "Deita_Result_Set_Get_Column_Name: Unsupported database type %d\n", p_result_set->database_type); + return NULL; +} + +Deita_Column_Type Deita_Result_Set_Get_Column_Type( + Deita_Result_Set *p_result_set, + int32 column_index) +{ + if (!p_result_set) + return DEITA_COLUMN_TYPE_NULL; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_get_column_type(p_result_set, column_index); + + fprintf(stderr, "Deita_Result_Set_Get_Column_Type: Unsupported database type %d\n", p_result_set->database_type); + return DEITA_COLUMN_TYPE_NULL; +} + +const char* Deita_Result_Set_Get_Text( + Deita_Result_Set *p_result_set, + int32 column_index) +{ + if (!p_result_set) + return NULL; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_get_text(p_result_set, column_index); + + fprintf(stderr, "Deita_Result_Set_Get_Text: Unsupported database type %d\n", p_result_set->database_type); + return NULL; +} + +int64 Deita_Result_Set_Get_Integer( + Deita_Result_Set *p_result_set, + int32 column_index) +{ + if (!p_result_set) + return 0; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_get_integer(p_result_set, column_index); + + fprintf(stderr, "Deita_Result_Set_Get_Integer: Unsupported database type %d\n", p_result_set->database_type); + return 0; +} + +double Deita_Result_Set_Get_Real( + Deita_Result_Set *p_result_set, + int32 column_index) +{ + if (!p_result_set) + return 0.0; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + return deita__sqlite_result_set_get_real(p_result_set, column_index); + + fprintf(stderr, "Deita_Result_Set_Get_Real: Unsupported database type %d\n", p_result_set->database_type); + return 0.0; +} + +void Deita_Result_Set_Free(Deita_Result_Set *p_result_set) +{ + if (!p_result_set) + return; + + if (p_result_set->database_type == DEITA_DATABASE_TYPE_SQLITE3) + { + deita__sqlite_result_set_free(p_result_set); + return; + } + + fprintf(stderr, "Deita_Result_Set_Free: Unsupported database type %d\n", p_result_set->database_type); +}