Changeset 1583:dad968d79e1d
- Timestamp:
- 02/18/10 10:59:01 (5 months ago)
- Branch:
- default
- Location:
- apps
- Files:
-
- 3 edited
-
las2oci.cpp (modified) (4 diffs)
-
oci_wrapper.cpp (modified) (10 diffs)
-
oci_wrapper.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/las2oci.cpp
r1582 r1583 319 319 } 320 320 321 sdo_geometry* MakeGeometry( SpatialIndex::Region* bounds, 322 int srid, 323 bool bUseSolidGeometry, 324 bool bUse3d) 325 { 326 sdo_geometry* output = (sdo_geometry* ) malloc (1 * sizeof(sdo_geometry)); 327 328 OCIArray* elem_info = (OCIArray* ) malloc (3 * sizeof(OCINumber)); 329 OCIArray* ordinates = 0;// = (OCIArray* ) malloc (3 * sizeof(OCINumber)); 330 331 // 332 // ostringstream oss_geom; 333 // 334 // ostringstream s_srid; 335 // ostringstream s_gtype; 336 // 337 // ostringstream s_eleminfo; 338 // bool bGeographic = false; 339 // 340 // if (srid == 0) { 341 // s_srid << "NULL"; 342 // // bUse3d = true; 343 // // bUseSolidGeometry = true; 344 // } 345 // else if (srid == 4326) { 346 // // bUse3d = true; 347 // // bUseSolidGeometry = true; 348 // bGeographic = true; 349 // s_srid << srid; 350 // // s_srid << "NULL"; 351 // } 352 // else { 353 // s_srid << srid; 354 // // bUse3d = false; 355 // // If the user set an srid and set it to solid, we're still 3d 356 // // if (bUseSolidGeometry == true) 357 // // bUse3d = true; 358 // } 359 // 360 // if (bUse3d) { 361 // if (bUseSolidGeometry == true) { 362 // ordinates = (OCIArray* ) malloc (6 * sizeof(OCINumber)); 363 // elem_info[0] = 1; 364 // elem_info[1] = 1007; 365 // elem_info[2] = 3; 366 // output->sdo_gtype = 3008; 367 // // s_gtype << "3008"; 368 // // s_eleminfo << "(1,1007,3)"; 369 // 370 // } else { 371 // ordinates = (OCIArray* ) malloc (6 * sizeof(OCINumber)); 372 // elem_info[0] = 1; 373 // elem_info[1] = 1003; 374 // elem_info[2] = 3; 375 // output->sdo_gtype = 3003; 376 // 377 // // s_gtype << "3003"; 378 // // s_eleminfo << "(1,1003,3)"; 379 // 380 // } 381 // } else { 382 // if (bUseSolidGeometry == true) { 383 // ordinates = (OCIArray* ) malloc (4 * sizeof(OCINumber)); 384 // elem_info[0] = 1; 385 // elem_info[1] = 1007; 386 // elem_info[2] = 3; 387 // output->sdo_gtype = 2008; 388 // 389 // // s_gtype << "2008"; 390 // // s_eleminfo << "(1,1007,3)"; 391 // 392 // } else { 393 // ordinates = (OCIArray* ) malloc (4 * sizeof(OCINumber)); 394 // elem_info[0] = 1; 395 // elem_info[1] = 1003; 396 // elem_info[2] = 3; 397 // output->sdo_gtype = 2003; 398 // // 399 // // 400 // // s_gtype << "2003"; 401 // // s_eleminfo << "(1,1003,3)"; 402 // 403 // } 404 // } 405 406 // 407 // double x0, x1, y0, y1, z0, z1; 408 // double tolerance = 0.05; 409 // 410 // 411 // x0 = b->getLow(0); 412 // x1 = b->getHigh(0); 413 // y0 = b->getLow(1); 414 // y1 = b->getHigh(1); 415 // 416 // if (bUse3d) { 417 // try { 418 // z0 = b->getLow(2); 419 // z1 = b->getHigh(2); 420 // } catch (Tools::IndexOutOfBoundsException& e) { 421 // z0 = 0; 422 // z1 = 20000; 423 // } 424 // } else if (bGeographic) { 425 // x0 = -180.0; 426 // x1 = 180.0; 427 // y0 = -90.0; 428 // y1 = 90.0; 429 // z0 = 0.0; 430 // z1 = 20000.0; 431 // tolerance = 0.000000005; 432 // } else { 433 // z0 = 0.0; 434 // z1 = 20000.0; 435 // } 436 // 437 // 438 // // std::cout << "use 3d?: " << bUse3d << " srid: " << s_srid.str() << std::endl; 439 // oss_geom.setf(std::ios_base::fixed, std::ios_base::floatfield); 440 // oss_geom.precision(precision); 441 // 442 // oss_geom << " mdsys.sdo_geometry("<<s_gtype.str() <<", "<<s_srid.str()<<", null,\n" 443 // " mdsys.sdo_elem_info_array"<< s_eleminfo.str() <<",\n" 444 // " mdsys.sdo_ordinate_array(\n"; 445 // 446 // oss_geom << x0 << ",\n" << y0 << ",\n"; 447 // 448 // if (bUse3d) { 449 // oss_geom << z0 << ",\n"; 450 // } 451 // 452 // oss_geom << x1 << ",\n" << y1 << "\n"; 453 // 454 // if (bUse3d) { 455 // oss_geom << ",\n"; 456 // oss_geom << z1; 457 // } 458 // 459 return output; 321 void GetElements( OWStatement* statement, 322 OCIArray* sdo_elem_info, 323 bool bUseSolidGeometry) 324 { 325 326 327 statement->AddElement(sdo_elem_info, 1); 328 if (bUseSolidGeometry == true) { 329 //"(1,1007,3)"; 330 statement->AddElement(sdo_elem_info, 1007); 331 } else { 332 //"(1,1003,3)"; 333 statement->AddElement(sdo_elem_info, 1003); 334 } 335 336 statement->AddElement(sdo_elem_info, 3); 337 460 338 } 461 339 … … 579 457 580 458 oss_geom << "))"; 459 // oss << "INSERT INTO "<< tableName << 460 // "(OBJ_ID, BLK_ID, NUM_POINTS, BLK_EXTENT, POINTS, " 461 // "PCBLK_MIN_RES, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) " 462 // "VALUES ( :1, :2, :3, :4, MDSYS.SDO_GEOMETRY(:5, :6, null, :7, :8)" 463 // // << pc_id << "," << result.GetID() <<"," << num_points << ", " 464 // // << oss_geom.str() <<", :1" 465 // ", 1, 1, 0, 1)"; 466 467 581 468 oss << "INSERT INTO "<< tableName << 582 469 "(OBJ_ID, BLK_ID, NUM_POINTS, BLK_EXTENT, POINTS, " 583 470 "PCBLK_MIN_RES, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) " 584 "VALUES ( :1, :2, :3, :4, :5"471 "VALUES ( :1, :2, :3, " << oss_geom.str() << 585 472 // << pc_id << "," << result.GetID() <<"," << num_points << ", " 586 // << oss_geom.str() <<", :1"587 ", 1, 1, 0, 1)";588 473 474 ",:4, 1, 1, 0, 1)"; 475 589 476 OWStatement* statement = 0; 590 477 OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 ); … … 592 479 statement = connection->CreateStatement(oss.str().c_str()); 593 480 481 482 594 483 long* p_pc_id = (long*) malloc( 1 * sizeof(long)); 595 *p_pc_id= pc_id;484 p_pc_id[0] = pc_id; 596 485 597 486 long* p_result_id = (long*) malloc( 1 * sizeof(long)); 598 *p_result_id = (long)result.GetID(); 599 600 int* p_num_points = (int*) malloc (1 * sizeof(int)); 601 *p_num_points = num_points; 602 603 statement->Bind( p_pc_id ); 604 statement->Bind( p_result_id ); 605 statement->Bind( p_num_points); 606 statement->Bind( oss_geom.str().c_str(), (int)oss_geom.str().size()); 487 long n_results = result.GetID(); 488 p_result_id[0] = (long)result.GetID(); 489 490 long* p_num_points = (long*) malloc (1 * sizeof(long)); 491 p_num_points[0] = num_points; 492 493 // :1 494 statement->Bind( &pc_id ); 495 496 // :2 497 statement->Bind( &n_results ); 498 499 // :3 500 statement->Bind( (long*)&num_points); 501 502 // :4 607 503 statement->Define( locator, 1 ); 608 504 … … 613 509 statement->Bind((char*)&(data[0]),(long)data.size()); 614 510 615 511 // :5 512 int gtype = atoi(s_gtype.str().c_str()); 513 long* p_gtype = (long*) malloc (1 * sizeof(long)); 514 *p_gtype = gtype; 515 516 printf("gtype: %d %d %s\n", *p_gtype, gtype, s_gtype.str().c_str()); 517 // statement->Bind(p_gtype); 518 519 // :6 520 int* p_srid = (int*) malloc (1 * sizeof(int)); 521 *p_srid = srid; 522 // statement->Bind(p_srid); 523 524 // :7 525 526 OCIArray* sdo_elem_info=0; 527 OCIArray* sdo_ordinates=0; 528 529 connection->CreateType(sdo_elem_info, connection->GetElemInfoType()); 530 connection->CreateType(sdo_ordinates, connection->GetOrdinateType()); 531 532 // GetElements(statement, sdo_elem_info, bUseSolidGeometry); 533 534 // statement->Bind(sdo_elem_info, connection->GetElemInfoType()); 535 536 // :8 537 // statement->Bind(ordinates); 538 616 539 if (statement->Execute() == false) { 617 540 delete statement; -
apps/oci_wrapper.cpp
r1582 r1583 64 64 hGeometryTDO = NULL; 65 65 hGeoRasterTDO = NULL; 66 hElemArrayTDO = NULL; 67 hOrdinateArrayTDO = NULL; 66 68 bSuceeeded = false; 67 69 nCharSize = 1; … … 156 158 hGeometryTDO = DescribeType( (char*) SDO_GEOMETRY ); 157 159 hGeoRasterTDO = DescribeType( (char*) SDO_GEORASTER ); 160 hElemArrayTDO = DescribeType( (char*) SDO_ELEM_INFO_ARRAY); 161 hOrdinateArrayTDO = DescribeType( (char* ) SDO_ORDINATE_ARRAY); 158 162 } 159 163 … … 241 245 } 242 246 247 void OWConnection::CreateType( OCIArray* phData, OCIType* otype) 248 { 249 CheckError( 250 OCIObjectNew( hEnv, 251 hError, 252 hSvcCtx, 253 OCI_TYPECODE_VARRAY, 254 otype, 255 (dvoid *)NULL, 256 OCI_DURATION_SESSION, 257 FALSE, 258 (dvoid **)&phData) 259 , 260 hError ); 261 } 262 263 void OWConnection::DestroyType( OCIArray* phData ) 264 { 265 CheckError( OCIObjectFree( 266 hEnv, 267 hError, 268 (OCIColl*) phData, 269 (ub2) 0), NULL ); 270 } 271 272 243 273 OWStatement* OWConnection::CreateStatement( const char* pszStatementIn ) 244 274 { … … 573 603 574 604 nNextBnd++; 575 605 606 printf("Binding long column #: %d\n", nNextBnd); 576 607 CheckError( OCIBindByPos( 577 608 hStmt, … … 581 612 (dvoid*) pnData, 582 613 (sb4) sizeof(long), 583 (ub2) SQLT_ LNG,614 (ub2) SQLT_NUM, 584 615 (void*) NULL, 585 616 (ub2*) NULL, … … 618 649 619 650 nNextBnd++; 620 651 printf("Binding blob column #: %d\n", nNextBnd); 621 652 CheckError( OCIBindByPos( 622 653 hStmt, … … 799 830 (dvoid**) NULL, 800 831 (ub4*) NULL ), hError ); 832 } 833 834 void OWStatement::Bind( OCIArray* pphData, OCIType* type ) 835 { 836 OCIBind* hBind = NULL; 837 838 nNextBnd++; 839 840 CheckError( OCIBindByPos( 841 hStmt, 842 &hBind, 843 hError, 844 (ub4) nNextBnd, 845 (dvoid*) 0, 846 (sb4) 0, 847 (ub2) SQLT_NTY, 848 (void*) NULL, 849 (ub2*) NULL, 850 (ub2*) NULL, 851 (ub4) NULL, 852 (ub4) NULL, 853 (ub4) OCI_DEFAULT ), 854 hError ); 855 856 CheckError( OCIBindObject( 857 hBind, 858 hError, 859 type, 860 (dvoid **)&pphData, 861 (ub4 *)0, 862 (dvoid **)0, 863 (ub4 *)0 ), 864 hError); 865 801 866 } 802 867 … … 948 1013 949 1014 } 1015 1016 950 1017 char* OWStatement::GetString( OCIString* ppoData ) 951 1018 { … … 1039 1106 } 1040 1107 1041 1108 void OWStatement::AddElement( OCIArray* poData, 1109 int nValue ) 1110 { 1111 OCINumber oci_number; 1112 1113 1114 CheckError(OCINumberFromInt(hError, (dvoid *)&nValue, 1115 (uword)sizeof(ub4), OCI_NUMBER_UNSIGNED, 1116 (OCINumber *)&oci_number), hError); 1117 CheckError(OCICollAppend(poConnect->hEnv, hError, (OCINumber *)&oci_number, 1118 (dvoid *)0, (OCIColl *) poData), hError); 1119 1120 } 1121 1122 void OWStatement::AddElement( OCIArray* poData, 1123 double dfValue ) 1124 { 1125 OCINumber oci_number; 1126 1127 CheckError(OCINumberFromReal(hError, (dvoid *)&dfValue, 1128 (uword)sizeof(double), (OCINumber *)&oci_number), hError); 1129 CheckError(OCICollAppend(poConnect->hEnv, hError, (OCINumber *)&oci_number, 1130 (dvoid *)0, (OCIColl *) poData), hError); 1131 1132 } 1042 1133 unsigned long OWStatement::ReadBlob( OCILobLocator* phLocator, 1043 1134 void* pBuffer, … … 1174 1265 } 1175 1266 1267 void OWStatement::BindName( char* pszName, long* pnData ) 1268 { 1269 OCIBind* hBind = NULL; 1270 1271 CheckError( OCIBindByName( 1272 (OCIStmt*) hStmt, 1273 (OCIBind**) &hBind, 1274 (OCIError*) hError, 1275 (text*) pszName, 1276 (sb4) -1, 1277 (dvoid*) pnData, 1278 (sb4) sizeof(long), 1279 (ub2) SQLT_LNG, 1280 (dvoid*) NULL, 1281 (ub2*) NULL, 1282 (ub2*) NULL, 1283 (ub4) 0, 1284 (ub4*) NULL, 1285 (ub4) OCI_DEFAULT ), 1286 hError ); 1287 } 1176 1288 void OWStatement::BindName( char* pszName, char* pszData, int nSize ) 1177 1289 { -
apps/oci_wrapper.h
r1582 r1583 231 231 void CreateType( sdo_geometry** pphData ); 232 232 void DestroyType( sdo_geometry** pphData ); 233 234 void CreateType( OCIArray* phData , OCIType* type); 235 void DestroyType( OCIArray* phData ); 236 233 237 OCIType* DescribeType( char *pszTypeName ); 234 238 … … 240 244 int GetVersion () { return nVersion; }; 241 245 sb4 GetCharSize () { return nCharSize; }; 246 247 OCIType* GetGeometryType() { return hGeometryTDO; } 248 OCIType* GetGeoRasterType() { return hGeoRasterTDO; } 249 OCIType* GetElemInfoType() {return hElemArrayTDO; } 250 OCIType* GetOrdinateType() {return hOrdinateArrayTDO; } 242 251 243 252 }; … … 287 296 void Bind( double* pnData ); 288 297 void Bind( char* pData, long nData); 298 void Bind( OCIArray* pphData, OCIType* type ); 299 289 300 void Define( double* pnData ); 290 301 void Define( char* pszData, int nSize = OWNAME ); … … 299 310 void Define( OCILobLocator** pphLocator, 300 311 int nIterations ); 312 301 313 void BindName( char* pszName, int* pnData ); 314 void BindName( char* pszName, long* pnData ); 302 315 void BindName( char* pszName, char* pszData, 303 316 int nSize = OWNAME ); … … 315 328 double GetElement( OCIArray** ppoData, 316 329 int nIndex, double* pdfResult ); 330 void AddElement( OCIArray* ppoData, 331 int nValue ); 332 void AddElement( OCIArray* ppoData, 333 double dfValue ); 317 334 }; 318 335
Note: See TracChangeset
for help on using the changeset viewer.
