Skip to content

Commit

Permalink
Implement all dummy functions when a database backend is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Mar 19, 2022
1 parent 527df5b commit 9e414f1
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 2 deletions.
44 changes: 44 additions & 0 deletions src/hoel-mariadb.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,48 @@ void h_close_mariadb(struct _h_connection * conn) {
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
}

char * h_escape_string_mariadb(const struct _h_connection * conn, const char * unsafe) {
UNUSED(conn);
UNUSED(unsafe);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
return NULL;
}

char * h_escape_string_with_quotes_mariadb(const struct _h_connection * conn, const char * unsafe) {
UNUSED(conn);
UNUSED(unsafe);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
return NULL;
}

long long int h_last_insert_id_mariadb(const struct _h_connection * conn) {
UNUSED(conn);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
return 0;
}

int h_execute_query_mariadb(const struct _h_connection * conn, const char * query, struct _h_result * h_result) {
UNUSED(conn);
UNUSED(query);
UNUSED(h_result);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
return H_ERROR;
}

int h_execute_query_json_mariadb(const struct _h_connection * conn, const char * query, json_t ** j_result) {
UNUSED(conn);
UNUSED(query);
UNUSED(j_result);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
return H_ERROR;
}

struct _h_data * h_get_mariadb_value(const char * value, const unsigned long length, const int m_type) {
UNUSED(value);
UNUSED(length);
UNUSED(m_type);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with MariaDB backend");
return NULL;
}

#endif
38 changes: 37 additions & 1 deletion src/hoel-pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct _h_connection * h_connect_pgsql(const char * conninfo) {
pthread_mutexattr_init ( &mutexattr );
pthread_mutexattr_settype( &mutexattr, PTHREAD_MUTEX_RECURSIVE );
if (pthread_mutex_init(&(((struct _h_pgsql *)conn->connection)->lock), &mutexattr) != 0) {
y_log_message(Y_LOG_LEVEL_ERROR, "Impossible to initialize Mutex Lock for MariaDB connection");
y_log_message(Y_LOG_LEVEL_ERROR, "Impossible to initialize Mutex Lock for PostgreSQL connection");
}
pthread_mutexattr_destroy( &mutexattr );
} else {
Expand Down Expand Up @@ -411,4 +411,40 @@ void h_close_pgsql(struct _h_connection * conn) {
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
}

char * h_escape_string_pgsql(const struct _h_connection * conn, const char * unsafe) {
UNUSED(conn);
UNUSED(unsafe);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
return NULL;
}

char * h_escape_string_with_quotes_pgsql(const struct _h_connection * conn, const char * unsafe) {
UNUSED(conn);
UNUSED(unsafe);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
return NULL;
}

long long int h_last_insert_id_pgsql(const struct _h_connection * conn) {
UNUSED(conn);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
return 0;
}

int h_execute_query_pgsql(const struct _h_connection * conn, const char * query, struct _h_result * h_result) {
UNUSED(conn);
UNUSED(query);
UNUSED(h_result);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
return H_ERROR;
}

int h_execute_query_json_pgsql(const struct _h_connection * conn, const char * query, json_t ** j_result) {
UNUSED(conn);
UNUSED(query);
UNUSED(j_result);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with PostgreSQL backend");
return H_ERROR;
}

#endif
57 changes: 56 additions & 1 deletion src/hoel-sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,20 @@ int h_select_query_sqlite(const struct _h_connection * conn, const char * query,
* return H_OK on success
*/
int h_exec_query_sqlite(const struct _h_connection * conn, const char * query) {
return h_execute_query_sqlite(conn, query);
}

/**
* h_execute_query_sqlite
* Execute a query on a sqlite connection
* This is an internal function, you should use h_exec_query instead
* Should not be executed by the user because all parameters are supposed to be correct
* No result is returned, useful for single INSERT, UPDATE or DELETE statements
* @param conn the connection to the database
* @param query the SQL query to execute
* @return H_OK on success
*/
int h_execute_query_sqlite(const struct _h_connection * conn, const char * query) {
if (sqlite3_exec(((struct _h_sqlite *)conn->connection)->db_handle, query, NULL, NULL, NULL) == SQLITE_OK) {
return H_OK;
} else {
Expand All @@ -229,7 +243,6 @@ int h_exec_query_sqlite(const struct _h_connection * conn, const char * query) {
y_log_message(Y_LOG_LEVEL_DEBUG, "Query: \"%s\"", query);
return H_ERROR_QUERY;
}

}

/**
Expand Down Expand Up @@ -318,4 +331,46 @@ void h_close_sqlite(struct _h_connection * conn) {
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
}

char * h_escape_string_sqlite(const struct _h_connection * conn, const char * unsafe) {
UNUSED(conn);
UNUSED(unsafe);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
return NULL;
}

char * h_escape_string_with_quotes_sqlite(const struct _h_connection * conn, const char * unsafe) {
UNUSED(conn);
UNUSED(unsafe);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
return NULL;
}

long long int h_last_insert_id_sqlite(const struct _h_connection * conn) {
UNUSED(conn);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
return 0;
}

int h_exec_query_sqlite(const struct _h_connection * conn, const char * query) {
UNUSED(conn);
UNUSED(query);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
return H_ERROR;
}

int h_execute_query_sqlite(const struct _h_connection * conn, const char * query) {
UNUSED(conn);
UNUSED(query);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
return H_ERROR;
}

int h_execute_query_json_sqlite(const struct _h_connection * conn, const char * query, json_t ** j_result) {
UNUSED(conn);
UNUSED(query);
UNUSED(j_result);
y_log_message(Y_LOG_LEVEL_ERROR, "Hoel was not compiled with SQLite backend");
return H_ERROR;
}

#endif

0 comments on commit 9e414f1

Please sign in to comment.