123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <float.h>
- #ifdef WINNT
- #include <io.h>
- #include <windows.h>
- #include <conio.h>
- #endif
- #include <infxcli.h> /* ODBC typedefs and data structures */
- #include "odbcutils.c"
- #include "commfuncs.h"
- #include "commfuncs.c"
- #include "shapefuncs.c"
- void main (int argc, char **argv)
- {
- SQLHDBC hdbc;
- SQLHENV henv;
- SQLHSTMT hstmt;
- char sql_stmt[200];
- int rc;
- SDWORD pcbvalue1, pcbvalue2, pcbvalue3;
- SDWORD pcbvalue4, pcbvalue5;
- Geometry geom = {0};
- Point pt[30];
- int offsets[5];
- int max_alloced = 0;
- int id;
- int size;
- char *name, *type;
- int name_len, type_len;
- char *zone_shape_buf;
- int zone_shape_len;
- int srid;
-
-
- if (argc < 2)
- {
- printf ("Usage: %s <datasource> [<srid>]\n", argv[0]);
- exit (1);
- }
-
- server_connect ((UCHAR *) argv[1], &henv, &hdbc);
-
- srid = (argc > 2) ? atoi(argv[2]) : 0;
-
- rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
- returncode_check (hdbc, (SQLHSTMT)NULL, rc, "SQLAllocHandle");
- sprintf(sql_stmt,
- "DROP TABLE sensitive_areas");
- rc = SQLExecDirect (hstmt, (UCHAR *) sql_stmt, SQL_NTS);
- sprintf(sql_stmt,
- "CREATE TABLE sensitive_areas (id integer, name varchar(128), "
- "size float, type varchar(32), zone ST_Polygon)");
- rc = SQLExecDirect (hstmt, (UCHAR *) sql_stmt, SQL_NTS);
- returncode_check (NULL, hstmt, rc, "SQLExecDirect");
-
- id = 289;
- name = "Johnson County Hospital";
- name_len = strlen(name);
- size = 102281.91;
- type = "hospital";
- type_len = strlen(type);
-
- offsets[0] = 0;
- pt[0].x = 22000; pt[0].y = 45000;
- pt[1].x = 22000; pt[1].y = 58000;
- pt[2].x = 28000; pt[2].y = 58000;
- pt[3].x = 28000; pt[3].y = 42000;
- pt[4].x = 25000; pt[4].y = 42000;
- pt[5].x = 25000; pt[5].y = 45000;
- pt[6].x = 22000; pt[6].y = 45000;
- geom.type = geomPolygon;
- geom.num_points = 7;
- geom.num_parts = 1;
- geom.offsets = offsets;
- geom.pt = pt;
-
- geom_to_shape (&geom, &max_alloced, &zone_shape_len, &zone_shape_buf);
-
-
-
- sprintf(sql_stmt,
- "INSERT INTO sensitive_areas (id, name, size, type, zone) "
- "VALUES(?, ?, ?, ?, SE_PolyFromShape(?, %d))", srid);
-
- rc = SQLPrepare (hstmt, (unsigned char *)sql_stmt, SQL_NTS);
- returncode_check (NULL, hstmt, rc, "SQLPrepare");
-
- pcbvalue1 = 0;
- rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 0, 0,
- &id, 0, &pcbvalue1);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- pcbvalue2 = name_len;
- rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
- SQL_CHAR, name_len, 0,
- name, 0, &pcbvalue2);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- pcbvalue3 = 0;
- rc = SQLBindParameter (hstmt, 3, SQL_PARAM_INPUT, SQL_C_FLOAT,
- SQL_REAL, 0, 0,
- &size, 0, &pcbvalue3);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- pcbvalue4 = type_len;
- rc = SQLBindParameter (hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR,
- SQL_VARCHAR, type_len, 0,
- type, type_len, &pcbvalue4);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- pcbvalue5 = zone_shape_len;
- rc = SQLBindParameter (hstmt, 5, SQL_PARAM_INPUT, SQL_C_BINARY,
- SQL_INFX_UDT_LVARCHAR, zone_shape_len, 0,
- zone_shape_buf, zone_shape_len, &pcbvalue5);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- rc = SQLExecute (hstmt);
- returncode_check (NULL, hstmt, rc, "SQLExecute");
-
- SQLFreeStmt (hstmt, SQL_CLOSE);
- SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
- SQLDisconnect (hdbc);
- SQLFreeHandle (SQL_HANDLE_DBC, hdbc);
- SQLFreeHandle (SQL_HANDLE_ENV, henv);
- printf( "\nTest Complete\n");
- }
|