[fdo-commits] r674 - branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver

svn_fdo at osgeo.org svn_fdo at osgeo.org
Mon Jan 22 21:05:07 EST 2007


Author: mloskot
Date: 2007-01-22 21:05:07 -0500 (Mon, 22 Jan 2007)
New Revision: 674

Added:
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.h
Log:
Added postgis_get_gen_id() function.

Added: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.c	2007-01-23 02:04:35 UTC (rev 673)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.c	2007-01-23 02:05:07 UTC (rev 674)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2006 Refractions Research, Inc. 
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "stdafx.h"
+
+#include "get_gen_id.h"
+#include "est_cursor.h"
+#include "sql.h"
+#include "define.h"
+#include "execute.h"
+#include "fetch.h"
+#include "fre_cursor.h"
+
+#include <string.h> /*stricmp() */
+#include <assert.h>
+
+int postgis_get_gen_id(
+    postgis_context_def* context,
+	const char* table_name,
+    const char* column_name,
+	int* id)
+{
+    postgis_cursor_def* curs = NULL;
+    //const char* column_name = NULL;
+    int ret = RDBI_GENERIC_ERROR;
+
+    assert(NULL != context);
+    assert(NULL != table_name);
+    assert(NULL != id);
+    
+    if (0 == stricmp(table_name, "f_classdefinition"))
+        column_name = "classid";
+    else if (0 == stricmp(table_name, "f_spatialcontext"))
+        column_name = "scid";
+    else if (0 == stricmp(table_name, "f_spatialcontextgroup"))
+        column_name = "scid";
+    else if (0 == stricmp(table_name, "f_spatialcontextgeom"))
+        column_name = "scgid";
+    else 
+        assert(!"postgis_get_gen_id() - UNKNOWN TABLE");
+    
+
+	return ret;
+}
+
+/*
+	// establish cursor
+	if ( RDBI_SUCCESS != mysql_est_cursor(context, (char **)&c) )
+        goto the_exit;
+
+	sprintf(sql_buf, "select LAST_INSERT_ID()");
+
+	if ( RDBI_SUCCESS != mysql_sql( context, (char *)c, sql_buf, FALSE, (char *)NULL,
+								NULL, (char *) NULL) )
+        goto the_exit;
+
+	// define output locations
+	if ( RDBI_SUCCESS != mysql_define( context, (char *)c, "1", RDBI_LONG, sizeof(long),
+									(char *) id, (short *)NULL) )
+        goto the_exit;
+
+    // execute the SQL statement
+    if ( RDBI_SUCCESS != mysql_execute( context, (char *)c, 1, 0, &rows) )
+        goto the_exit;
+
+	// execute the SQL statement & fetch row
+	if ( RDBI_SUCCESS != mysql_fetch( context, (char *)c, 1, FALSE, FALSE, &rows) )
+        goto the_exit;
+
+    if (c != (mysql_cursor_def *)NULL)
+        mysql_fre_cursor (context, (char **)&c);
+
+    rdbi_status = RDBI_SUCCESS;
+*/
\ No newline at end of file

Added: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.h	2007-01-23 02:04:35 UTC (rev 673)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_gen_id.h	2007-01-23 02:05:07 UTC (rev 674)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2006 Refractions Research, Inc. 
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef POSTGIS_GET_GEN_ID_H
+#define POSTGIS_GET_GEN_ID_H
+
+#ifdef _WIN32
+#pragma once
+#endif // _WIN32
+
+#include "local.h"
+
+/** 
+ * Gets the last value generated with last insert for a SERIAL field
+ * in given table.
+ *
+ * @param context [in] - pointer to PostGIS session context.
+ * @param table_name [in] - 
+ * @param column_name [in] - 
+ * @param id [out] - Autogenerated value after last insert.
+ * @return RDBI error code of operation state.
+ */
+int postgis_get_gen_id(
+    postgis_context_def* context,
+    const char* table_name,
+    const char* column_name,
+    int* id);
+
+#endif /* POSTGIS_GET_GEN_ID_H */
\ No newline at end of file



More information about the fdo-commits mailing list