[GRASS-SVN] r65333 - grass/trunk/db/drivers/postgres

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 26 11:00:25 PDT 2015


Author: martinl
Date: 2015-05-26 11:00:25 -0700 (Tue, 26 May 2015)
New Revision: 65333

Added:
   grass/trunk/db/drivers/postgres/table.c
Modified:
   grass/trunk/db/drivers/postgres/dbdriver.h
Log:
pg driver: implement db__driver_drop_table


Modified: grass/trunk/db/drivers/postgres/dbdriver.h
===================================================================
--- grass/trunk/db/drivers/postgres/dbdriver.h	2015-05-26 17:08:06 UTC (rev 65332)
+++ grass/trunk/db/drivers/postgres/dbdriver.h	2015-05-26 18:00:25 UTC (rev 65333)
@@ -8,6 +8,8 @@
 int db__driver_close_cursor();
 int db__driver_open_database();
 int db__driver_close_database();
+int db__driver_create_database();
+int db__driver_delete_database();
 int db__driver_describe_table();
 int db__driver_init();
 int db__driver_finish();
@@ -21,12 +23,15 @@
 int db__driver_list_tables();
 int db__driver_grant_on_table();
 int db__driver_open_select_cursor();
+int db__driver_drop_table();
 
 #define	init_dbdriver() do{\
 db_driver_create_table = db__driver_create_table;\
 db_driver_close_cursor = db__driver_close_cursor;\
 db_driver_open_database = db__driver_open_database;\
 db_driver_close_database = db__driver_close_database;\
+db_driver_create_database = db__driver_create_database;\
+db_driver_delete_database = db__driver_delete_database;\
 db_driver_describe_table = db__driver_describe_table;\
 db_driver_init = db__driver_init;\
 db_driver_finish = db__driver_finish;\
@@ -40,6 +45,7 @@
 db_driver_list_tables = db__driver_list_tables;\
 db_driver_grant_on_table = db__driver_grant_on_table;\
 db_driver_open_select_cursor = db__driver_open_select_cursor;\
+db_driver_drop_table = db__driver_drop_table;\
 }while(0)
 
 #endif

Added: grass/trunk/db/drivers/postgres/table.c
===================================================================
--- grass/trunk/db/drivers/postgres/table.c	                        (rev 0)
+++ grass/trunk/db/drivers/postgres/table.c	2015-05-26 18:00:25 UTC (rev 65333)
@@ -0,0 +1,44 @@
+/*!
+ * \file table.c
+ *
+ * \brief Low level drop table function.
+ *
+ * This program is free software under the GNU General Public License
+ * (>=v2). Read the file COPYING that comes with GRASS for details.
+ *
+ * \author Martin Landa <landa.martin gmail.com>
+ *
+ * \date 2015
+ */
+
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+#include "globals.h"
+#include "proto.h"
+
+/*!
+ * \brief Low level driver drop table from database.
+ *
+ * \param name table name to drop
+ * \return DB_FAILED on error; DB_OK on success
+ */
+int db__driver_drop_table(dbString *name)
+{
+    PGresult *res;
+    char cmd[DB_SQL_MAX];
+
+    sprintf(cmd, "DROP TABLE %s", db_get_string(name));
+        
+    res = PQexec(pg_conn, cmd);
+
+    if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
+	db_d_append_error("%s\n%s",
+			  _("Unable to execute():"),
+			  PQerrorMessage(pg_conn));
+	db_d_report_error();
+	return DB_FAILED;
+    }
+
+    return DB_OK;
+}


Property changes on: grass/trunk/db/drivers/postgres/table.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native



More information about the grass-commit mailing list