a lot of work

This commit is contained in:
2019-01-19 13:44:30 -03:00
parent 404b68b791
commit 3aaf811190
50 changed files with 1959 additions and 378 deletions

View File

@@ -29,7 +29,11 @@ namespace LibSernatur {
/**
* Connection error
*/
CONNECT
CONNECT,
/**
* Escape error
*/
ESCAPE
}
/**
@@ -49,7 +53,7 @@ namespace LibSernatur {
/**
* Class to handle database connections
*/
public class Connection : GLib.Object {
public class Connection : Object {
/**
* The database connection
*/
@@ -71,7 +75,26 @@ namespace LibSernatur {
if (db.get_status () != Postgres.ConnectionStatus.OK) {
throw new PostgresError.CONNECT (db.get_error_message ());
}
GLib.print (dgettext (null, "Postgresql server version:") + " %d\n", db.get_server_version ());
GLib.print (_ ("Postgresql server version:") + " %d\n", db.get_server_version ());
}
/**
* Escape a string to be safe to use in Postgresql queries
* @param str The string to escape
* @return Returns the escaped string
* @throws PostgresError Thrown if there was some problem escaping the string
*/
public string escape (string str) throws PostgresError {
string* to = malloc ((sizeof (string) * str.length * 2) + 1); // to has to be double the size of str + 1
int error_code;
db.escape_string_conn (to, str, str.length, out error_code);
if (error_code != 0) {
throw new PostgresError.ESCAPE (db.get_error_message ());
}
string result = to;
free (to);
return result;
}
}
}