Changeset 1583:dad968d79e1d


Ignore:
Timestamp:
02/18/10 10:59:01 (5 months ago)
Author:
Howard Butler <hobu.inc@…>
Branch:
default
Message:

more OCI binding stuff

Location:
apps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/las2oci.cpp

    r1582 r1583  
    319319} 
    320320 
    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; 
     321void 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  
    460338} 
    461339 
     
    579457     
    580458    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 
    581468    oss << "INSERT INTO "<< tableName <<  
    582469            "(OBJ_ID, BLK_ID, NUM_POINTS, BLK_EXTENT, POINTS, " 
    583470            "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() << 
    585472            // << 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             
    589476    OWStatement* statement = 0; 
    590477    OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 ); 
     
    592479    statement = connection->CreateStatement(oss.str().c_str()); 
    593480     
     481 
     482     
    594483    long* p_pc_id = (long*) malloc( 1 * sizeof(long)); 
    595     *p_pc_id = pc_id; 
     484    p_pc_id[0] = pc_id; 
    596485 
    597486    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 
    607503    statement->Define( locator, 1 );  
    608504     
     
    613509    statement->Bind((char*)&(data[0]),(long)data.size()); 
    614510 
    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     
    616539    if (statement->Execute() == false) { 
    617540        delete statement; 
  • apps/oci_wrapper.cpp

    r1582 r1583  
    6464    hGeometryTDO    = NULL; 
    6565    hGeoRasterTDO   = NULL; 
     66    hElemArrayTDO   = NULL; 
     67    hOrdinateArrayTDO = NULL; 
    6668    bSuceeeded      = false; 
    6769    nCharSize       = 1; 
     
    156158    hGeometryTDO    = DescribeType( (char*) SDO_GEOMETRY ); 
    157159    hGeoRasterTDO   = DescribeType( (char*) SDO_GEORASTER ); 
     160    hElemArrayTDO   = DescribeType( (char*) SDO_ELEM_INFO_ARRAY); 
     161    hOrdinateArrayTDO = DescribeType( (char* ) SDO_ORDINATE_ARRAY); 
    158162} 
    159163 
     
    241245} 
    242246 
     247void 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 
     263void OWConnection::DestroyType( OCIArray* phData ) 
     264{ 
     265    CheckError( OCIObjectFree( 
     266        hEnv, 
     267        hError, 
     268        (OCIColl*) phData, 
     269        (ub2) 0), NULL ); 
     270} 
     271 
     272 
    243273OWStatement* OWConnection::CreateStatement( const char* pszStatementIn ) 
    244274{ 
     
    573603 
    574604    nNextBnd++; 
    575  
     605     
     606    printf("Binding long column #: %d\n", nNextBnd); 
    576607    CheckError( OCIBindByPos( 
    577608        hStmt, 
     
    581612        (dvoid*) pnData, 
    582613        (sb4) sizeof(long), 
    583         (ub2) SQLT_LNG, 
     614        (ub2) SQLT_NUM, 
    584615        (void*) NULL, 
    585616        (ub2*) NULL, 
     
    618649 
    619650    nNextBnd++; 
    620  
     651    printf("Binding blob column #: %d\n", nNextBnd); 
    621652    CheckError( OCIBindByPos(  
    622653        hStmt, 
     
    799830        (dvoid**) NULL, 
    800831        (ub4*) NULL ), hError ); 
     832} 
     833 
     834void 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         
    801866} 
    802867 
     
    9481013 
    9491014} 
     1015 
     1016 
    9501017char* OWStatement::GetString( OCIString* ppoData ) 
    9511018{ 
     
    10391106} 
    10401107 
    1041  
     1108void 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 
     1122void 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} 
    10421133unsigned long OWStatement::ReadBlob( OCILobLocator* phLocator, 
    10431134                                     void* pBuffer, 
     
    11741265} 
    11751266 
     1267void 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} 
    11761288void OWStatement::BindName( char* pszName, char* pszData, int nSize ) 
    11771289{ 
  • apps/oci_wrapper.h

    r1582 r1583  
    231231    void                CreateType( sdo_geometry** pphData ); 
    232232    void                DestroyType( sdo_geometry** pphData ); 
     233 
     234    void                CreateType( OCIArray* phData , OCIType* type); 
     235    void                DestroyType( OCIArray* phData ); 
     236 
    233237    OCIType*            DescribeType( char *pszTypeName ); 
    234238 
     
    240244    int                 GetVersion () { return nVersion; }; 
    241245    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; } 
    242251 
    243252}; 
     
    287296    void                Bind( double* pnData ); 
    288297    void                Bind( char* pData, long nData); 
     298    void                Bind( OCIArray* pphData, OCIType* type ); 
     299     
    289300    void                Define( double* pnData ); 
    290301    void                Define( char* pszData, int nSize = OWNAME ); 
     
    299310    void                Define( OCILobLocator** pphLocator, 
    300311                            int nIterations ); 
     312 
    301313    void                BindName( char* pszName, int* pnData ); 
     314    void                BindName( char* pszName, long* pnData ); 
    302315    void                BindName( char* pszName, char* pszData, 
    303316                            int nSize = OWNAME ); 
     
    315328    double              GetElement( OCIArray** ppoData, 
    316329                            int nIndex, double* pdfResult ); 
     330    void                AddElement( OCIArray* ppoData,  
     331                            int nValue );                           
     332    void                AddElement( OCIArray* ppoData,  
     333                            double dfValue );    
    317334}; 
    318335 
Note: See TracChangeset for help on using the changeset viewer.