postgresql :: NativePostgres :: connectdb
Connect to a new database using the conninfo string as a parameterpostgresql :: NativePostgres :: error
Returns the error message of the last operation on the connectionpostgresql :: NativePostgres :: exec
Submits a query to the server and waits for the result returns the ExecStatustype of the querypostgresql :: NativePostgres :: prepare
Prepares a statement with the given parameterspostgresql :: NativePostgres :: reset
Closes the connection to the server and attempts to reconnect with the previously used paramspostgresql :: NativePostgres :: status
Returns the status of this connectionpostgresql $ NativePostgres :: SELF
Type of this instance, automatically specialized in every classcore :: Pointer :: address_is_null
Is the address behind this Object at NULL?core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
postgresql :: NativePostgres :: connectdb
Connect to a new database using the conninfo string as a parametercore :: Pointer :: defaultinit
core :: Object :: defaultinit
postgresql :: NativePostgres :: error
Returns the error message of the last operation on the connectionpostgresql :: NativePostgres :: exec
Submits a query to the server and waits for the result returns the ExecStatustype of the querycore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).postgresql :: NativePostgres :: prepare
Prepares a statement with the given parameterspostgresql :: NativePostgres :: reset
Closes the connection to the server and attempts to reconnect with the previously used paramspostgresql :: NativePostgres :: status
Returns the status of this connection
extern class NativePostgres `{PGconn *`}
# Connect to a new database using the conninfo string as a parameter
new connectdb(conninfo: Text) import Text.to_cstring `{
PGconn * self = NULL;
self = PQconnectdb(Text_to_cstring(conninfo));
return self;
`}
# Submits a query to the server and waits for the result returns the ExecStatustype of the query
fun exec(query: Text): NativePGResult import Text.to_cstring `{
PGresult *res = PQexec(self, Text_to_cstring(query));
return res;
`}
# Prepares a statement with the given parameters
fun prepare(stmt: String, query: String, nParams: Int): NativePGResult import String.to_cstring `{
const char * stmtName = String_to_cstring(stmt);
const char * queryStr = String_to_cstring(query);
PGresult * res = PQprepare(self, stmtName, queryStr, nParams, NULL);
return res;
`}
fun exec_prepared(stmt: String, nParams: Int, values: Array[String], pLengths: Array[Int], pFormats: Array[Int], resultFormat: Int): NativePGResult import String.to_cstring, Array[String].[], Array[Int].[] `{
const char * stmtName = String_to_cstring(stmt);
const char * paramValues[nParams];
int paramLengths[nParams];
int paramFormats[nParams];
int i;
for(i = 0; i < nParams; i++)
paramValues[i] = String_to_cstring(Array_of_String__index(values, i));
for(i = 0; i < nParams; i++)
paramLengths[i] = Array_of_Int__index(pLengths, i);
for(i = 0; i < nParams; i++)
paramFormats[i] = Array_of_Int__index(pFormats, i);
PGresult * res = PQexecPrepared(self, stmtName, nParams, paramValues, paramLengths, paramFormats, resultFormat);
return res;
`}
# Returns the error message of the last operation on the connection
fun error: String import CString.to_s `{
char * error = PQerrorMessage(self);
return CString_to_s(error);
`}
# Returns the status of this connection
fun status: ConnStatusType `{
return PQstatus(self);
`}
# Closes the connection to the server
fun finish `{
PQfinish(self);
`}
# Closes the connection to the server and attempts to reconnect with the previously used params
fun reset `{
PQreset(self);
`}
end
lib/postgresql/native_postgres.nit:86,1--145,3