From 5f3ae65b17efe782ea5aef59c7814d5a3658e4da Mon Sep 17 00:00:00 2001 From: Udo Date: Thu, 20 Jan 2022 22:42:51 +0000 Subject: [PATCH] mysql docs --- doc/areas/session.txt | 5 +++++ doc/pages/make_session_id.txt | 2 +- doc/pages/mysql_connect.txt | 15 ++++++++++++++- doc/pages/mysql_disconnect.txt | 12 +++++++++++- doc/pages/mysql_error.txt | 13 ++++++++++++- doc/pages/mysql_escape.txt | 14 +++++++++++++- doc/pages/mysql_insert_id.txt | 13 ++++++++++++- doc/pages/mysql_query.txt | 18 +++++++++++++++++- doc/pages/session_destroy.txt | 11 +++++++++++ doc/pages/session_start.txt | 17 +++++++++++++++++ src/lib/mysql-connector.cpp | 6 ++++-- src/lib/uri.cpp | 1 + todo.txt | 4 ++-- 13 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 doc/areas/session.txt create mode 100644 doc/pages/session_destroy.txt create mode 100644 doc/pages/session_start.txt diff --git a/doc/areas/session.txt b/doc/areas/session.txt new file mode 100644 index 0000000..f19efc8 --- /dev/null +++ b/doc/areas/session.txt @@ -0,0 +1,5 @@ +Sessions + +make_session_id +session_destroy +session_start diff --git a/doc/pages/make_session_id.txt b/doc/pages/make_session_id.txt index 66f721f..755a06c 100644 --- a/doc/pages/make_session_id.txt +++ b/doc/pages/make_session_id.txt @@ -8,4 +8,4 @@ return value : a new session ID Creates a session ID :see ->uri +>session diff --git a/doc/pages/mysql_connect.txt b/doc/pages/mysql_connect.txt index 94327d4..d5811cc 100644 --- a/doc/pages/mysql_connect.txt +++ b/doc/pages/mysql_connect.txt @@ -1 +1,14 @@ -(not documented yet) +:sig +MySQL* mysql_connect(String host = "localhost", String username = "root", String password = "") + +:params +host : host name of the MySQL server +username : user name +password : password +return value : pointer to the MySQL connection struct + +:desc +Establishes a connection to a MySQL server. + +:see +>mysql diff --git a/doc/pages/mysql_disconnect.txt b/doc/pages/mysql_disconnect.txt index 94327d4..850c7b7 100644 --- a/doc/pages/mysql_disconnect.txt +++ b/doc/pages/mysql_disconnect.txt @@ -1 +1,11 @@ -(not documented yet) +:sig +void mysql_disconnect(MySQL* m) + +:params +m : pointer to an existing MySQL connection struct + +:desc +Closes a connection to a MySQL server. + +:see +>mysql diff --git a/doc/pages/mysql_error.txt b/doc/pages/mysql_error.txt index 94327d4..79ab117 100644 --- a/doc/pages/mysql_error.txt +++ b/doc/pages/mysql_error.txt @@ -1 +1,12 @@ -(not documented yet) +:sig +String mysql_error(MySQL* m) + +:params +m : pointer to a MySQL connection struct +return value : MySQL error message (if present, otherwise empty string) + +:desc +Returns the last error message from a connection to a MySQL server. + +:see +>mysql diff --git a/doc/pages/mysql_escape.txt b/doc/pages/mysql_escape.txt index 94327d4..dccb730 100644 --- a/doc/pages/mysql_escape.txt +++ b/doc/pages/mysql_escape.txt @@ -1 +1,13 @@ -(not documented yet) +:sig +String mysql_escape(String raw, char quote_char) + +:params +raw : the string to be escaped +quote_char : the character that should be used to wrap the string (pass NULL for no wrapping) +return value : the safe version of the 'raw' string + +:desc +Escapes a string such that it can be passed as a safe value into an SQL expression. + +:see +>mysql diff --git a/doc/pages/mysql_insert_id.txt b/doc/pages/mysql_insert_id.txt index 94327d4..b0b331c 100644 --- a/doc/pages/mysql_insert_id.txt +++ b/doc/pages/mysql_insert_id.txt @@ -1 +1,12 @@ -(not documented yet) +:sig +u64 mysql_insert_id(MySQL* m) + +:params +m : pointer to an active MySQL connection +return value : the last used automatic row ID + +:desc +This retrieves the last row ID that was used for a column with an AUTO_INCREMENT row key. + +:see +>mysql diff --git a/doc/pages/mysql_query.txt b/doc/pages/mysql_query.txt index 94327d4..89d2abb 100644 --- a/doc/pages/mysql_query.txt +++ b/doc/pages/mysql_query.txt @@ -1 +1,17 @@ -(not documented yet) +:sig +DTree mysql_query(MySQL* m, String q, StringMap params) + +:params +m : pointer to an active MySQL connection struct +q : a string containing a MySQL query +params : optional, a list of query parameter keys and values +return value : a list of rows returned from executing the query + +:desc +Executes a MySQL query and returns the resulting data (if any). + +:Examples +(tbd) + +:see +>mysql diff --git a/doc/pages/session_destroy.txt b/doc/pages/session_destroy.txt new file mode 100644 index 0000000..20c7c32 --- /dev/null +++ b/doc/pages/session_destroy.txt @@ -0,0 +1,11 @@ +:sig +void session_destroy(String session_name) + +:params +session_name : the name of the session + +:desc +Deletes the cookie specified by 'session_name' and clears the data stored under the session ID. This empties the 'context->session_id' and 'context->session' variables. + +:see +>session diff --git a/doc/pages/session_start.txt b/doc/pages/session_start.txt new file mode 100644 index 0000000..04465eb --- /dev/null +++ b/doc/pages/session_start.txt @@ -0,0 +1,17 @@ +:sig +String session_start(String session_name) + +:params +return value : the session ID, defaults to "uce-session" + +:desc +Starts session or connects to existing session. This function sets a cookie with the name contained in 'session_name' if it does not exist and fills that cookie with a new unique session ID. It then loads the session data for that session ID. Afterwards, the following fields are populated in the 'context' variable: + +context->session_id : the current session ID + +context->session_name : the current session cookie name + +context->session : the current session data. The session data is automatically saved after a request completes. + +:see +>session diff --git a/src/lib/mysql-connector.cpp b/src/lib/mysql-connector.cpp index 3c3e0e2..e32c17f 100644 --- a/src/lib/mysql-connector.cpp +++ b/src/lib/mysql-connector.cpp @@ -49,7 +49,8 @@ String MySQL::escape(String raw, char quote_char) String mysql_escape(String raw, char quote_char) { String result; - result.append(1, quote_char); + if(quote_char > 0) + result.append(1, quote_char); for(u32 i = 0; i < raw.length(); i++) { @@ -77,7 +78,8 @@ String mysql_escape(String raw, char quote_char) } } - result.append(1, quote_char); + if(quote_char > 0) + result.append(1, quote_char); return(result); } diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp index 0bcbfa4..8f258c4 100644 --- a/src/lib/uri.cpp +++ b/src/lib/uri.cpp @@ -315,6 +315,7 @@ void session_destroy(String session_name) { set_cookie(session_name, "", time() - context->server->config.SESSION_TIME); context->session.clear(); + save_session_data(context->session_id, context->session); context->session_id = ""; } } diff --git a/todo.txt b/todo.txt index 93a6fbd..1f8243d 100644 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,8 @@ Library ================================= -- sha1 / md5 / meow +- md5 / meow - fold StringList into DTree _OR_ make better StringList - +- make session data use DTree instead of StringList Bugs =================================