1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include "dbmi.h"
#include "globals.h"
#include "proto.h"
int
db__driver_create_table (dbTable *table)
{
PGresult *res;
dbString sql;
dbConnection connection;
G_debug (3, "db__driver_create_table()");
db_init_string (&sql);
db_table_to_sql ( table, &sql );
init_error();
G_debug (3, " SQL: %s", db_get_string(&sql) );
res = PQexec(pg_conn, db_get_string(&sql) );
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
append_error( "Cannot create table:\n");
append_error( db_get_string(&sql) );
append_error( "\n" );
append_error(PQerrorMessage(pg_conn));
report_error();
PQclear(res);
db_free_string ( &sql);
return DB_FAILED;
}
PQclear(res);
/* Grant privileges */
db_get_connection(&connection);
db_set_string ( &sql, "grant select on " );
db_append_string ( &sql, db_get_table_name ( table ) );
db_append_string ( &sql, " to public" );
if ( connection.group ) {
db_append_string ( &sql, ", group " );
db_append_string ( &sql, connection.group );
}
G_debug (3, " SQL: %s", db_get_string(&sql) );
res = PQexec(pg_conn, db_get_string(&sql) );
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
append_error( "Cannot grant select on table:\n");
append_error( db_get_string(&sql) );
append_error( "\n" );
append_error(PQerrorMessage(pg_conn));
report_error();
PQclear(res);
db_free_string ( &sql);
return DB_FAILED;
}
PQclear(res);
db_free_string ( &sql);
return DB_OK;
}
|