123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #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 "wkbfuncs.c"
- void main (int argc, char **argv)
- {
- SQLHDBC hdbc;
- SQLHENV henv;
- SQLHSTMT hstmt;
- char sql_stmt[200];
- int rc;
- SDWORD pcbvalue1, pcbvalue2, pcbvalue3;
- Geometry geom = {0};
- Point pt[30];
- int max_alloced = 0;
- char *genus, *species;
- int genus_len, species_len;
- char *sitings_wkb_buf;
- int sitings_wkb_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");
- rc = SQLExecDirect (hstmt, (UCHAR *) "DROP TABLE species_sitings", SQL_NTS);
- rc = SQLExecDirect (hstmt, (UCHAR *) "CREATE TABLE species_sitings (id integer,genus varchar(128), species varchar(128), sitings ST_MultiPoint)", SQL_NTS);
- returncode_check (NULL, hstmt, rc, "SQLExecDirect");
-
- genus = "Falco"; genus_len = strlen(genus);
- species = "punctatus"; species_len = strlen(species);
-
- pt[0].x = 1; pt[0].y = 2;
- pt[1].x = 3; pt[1].y = 4;
- pt[2].x = 5; pt[2].y = 6;
- pt[3].x = 7; pt[3].y = 8;
- pt[4].x = 9; pt[4].y = 10;
-
- geom.type = geomMultiPoint;
- geom.num_points = 5;
- geom.num_parts = 5;
- geom.pt = pt;
-
- geom_to_wkb (&geom, &max_alloced, &sitings_wkb_len, &sitings_wkb_buf);
-
-
-
- sprintf(sql_stmt,
- "INSERT INTO species_sitings (species,genus,sitings) "
- "VALUES(?, ?, ST_MpointFromWKB(?, %d))", srid);
-
-
- rc = SQLPrepare (hstmt, (unsigned char *)sql_stmt, SQL_NTS);
- returncode_check (NULL, hstmt, rc, "SQLPrepare");
-
- pcbvalue1 = species_len;
- rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
- SQL_CHAR, species_len, 0,
- species, species_len, &pcbvalue1);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- pcbvalue2 = genus_len;
- rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
- SQL_CHAR, genus_len, 0,
- genus, genus_len, &pcbvalue2);
- returncode_check (NULL, hstmt, rc, "SQLBindParameter");
-
- pcbvalue3 = sitings_wkb_len;
- rc = SQLBindParameter (hstmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY,
- SQL_INFX_UDT_LVARCHAR, sitings_wkb_len, 0,
- sitings_wkb_buf, sitings_wkb_len, &pcbvalue3);
- 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");
- }
|