Changeset 1582:95b260e3e1c6


Ignore:
Timestamp:
02/16/10 14:32:50 (5 months ago)
Author:
Howard Butler <hobu.inc@…>
Branch:
default
Message:

more capabilities to OCI bindings

Location:
apps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/las2oci.cpp

    r1529 r1582  
    319319} 
    320320 
     321sdo_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; 
     460} 
     461 
    321462bool InsertBlock(OWConnection* connection,  
    322463                const LASQueryResult& result,  
     
    435576    } 
    436577 
    437  
     578    long result_id = result.GetID(); 
     579     
    438580    oss_geom << "))"; 
    439581    oss << "INSERT INTO "<< tableName <<  
    440             "(OBJ_ID, BLK_ID, NUM_POINTS, BLK_EXTENT, POINTS, PCBLK_MIN_RES, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) VALUES ( "  
    441             << pc_id << "," << result.GetID() <<"," << num_points << ", "  
    442             << oss_geom.str() <<", :1, 1, 1, 0, 1)"; 
     582            "(OBJ_ID, BLK_ID, NUM_POINTS, BLK_EXTENT, POINTS, " 
     583            "PCBLK_MIN_RES, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) " 
     584            "VALUES ( :1, :2, :3, :4, :5"  
     585            // << pc_id << "," << result.GetID() <<"," << num_points << ", "  
     586            // << oss_geom.str() <<", :1" 
     587            ", 1, 1, 0, 1)"; 
    443588 
    444589    OWStatement* statement = 0; 
     
    446591 
    447592    statement = connection->CreateStatement(oss.str().c_str()); 
    448     statement->Define( locator, 1 ); // fetch one blob 
     593     
     594    long* p_pc_id = (long*) malloc( 1 * sizeof(long)); 
     595    *p_pc_id = pc_id; 
     596 
     597    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()); 
     607    statement->Define( locator, 1 );  
    449608     
    450609    std::vector<liblas::uint8_t> data; 
     
    463622    oss.str(""); 
    464623     
    465     // FIXME (BLK_ID *and* OBJ_ID must be used as part of the query.) 
    466     // oss << "SELECT POINTS FROM " << tableName << " WHERE BLK_ID=" << result.GetID() << " and OBJ_ID=" << pc_id<<"  FOR UPDATE"; 
    467      
    468     // we only expect one blob to come back 
    469     // OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 ); 
    470  
    471     // statement = connection->CreateStatement(oss.str().c_str()); 
    472     // statement->Define( locator, 1 ); // fetch one blob 
    473     //  
    474     //  
    475     // if( statement->Execute() == false ) 
    476     // { 
    477     //     std::cout << "Unable to execute statement!" << std::endl; 
    478     //     delete statement; 
    479     //     return false; 
    480     // } 
    481     //  
    482     // if( statement->Fetch( 1 ) == false ) 
    483     // { 
    484     //     std::cout << "Unable to fetch POINTS blob!" << std::endl; 
    485     //     delete statement; 
    486     //     return false; 
    487     // } 
    488      
    489     // std::vector<liblas::uint8_t> data; 
    490     // bool gotdata = GetResultData(result, reader, data, 3); 
    491     // if (! gotdata) throw std::runtime_error("unable to fetch point data byte array"); 
    492     //  
    493     // liblas::uint32_t wroteblob = statement->WriteBlob(  locator[0], 
    494     //                                                     (void*)&(data[0]), 
    495     //                                                     data.size()); 
    496     //  
    497     // if (! wroteblob) throw std::runtime_error("No blob bytes could be written!"); 
    498 //select dbms_lob.getlength(points) from TO_core_last_clip 
    499  
    500     // oss << ""; 
    501     // oss <<  "COMMIT"; 
    502     // statement = Run(connection, oss); 
    503     // if (statement != 0) delete statement; else return false; 
    504     // oss.str(""); 
    505624 
    506625    OWStatement::Free(locator, 1); 
     
    512631    return true; 
    513632 
     633} 
     634 
     635bool InsertBlocks( 
     636                OWConnection* con,  
     637                const std::list<LASQueryResult>& results, 
     638                long nCommitInterval,  
     639                int srid,  
     640                LASReader* reader2,  
     641                const std::string& table_name,  
     642                long precision, 
     643                long pc_id, 
     644                bool bUseSolidGeometry, 
     645                bool bUse3d 
     646                ) 
     647{ 
     648 
     649     
     650    std::list<LASQueryResult>::const_iterator i; 
     651 
     652 
     653    for (i=results.begin(); i!=results.end(); i++) 
     654    { 
     655        bool inserted = InsertBlock(con,  
     656                                    *i,  
     657                                    srid,  
     658                                    reader2,  
     659                                    table_name.c_str(),  
     660                                    precision,  
     661                                    pc_id,  
     662                                    bUseSolidGeometry,  
     663                                    bUse3d); 
     664    } 
     665     
    514666} 
    515667 
     
    9731125    double zmax = 0.0; 
    9741126    bool bSetExtents = false; 
    975          
     1127     
     1128    int nCommitInterval = 100; 
    9761129     
    9771130    for (int i = 1; i < argc; i++) 
     
    10951248            i++; 
    10961249            precision = atoi(argv[i]); 
     1250        } 
     1251        else if (   strcmp(argv[i],"--commit-interval") == 0  || 
     1252                    strcmp(argv[i],"-ci") == 0   
     1253                ) 
     1254        { 
     1255            i++; 
     1256            nCommitInterval = atoi(argv[i]); 
    10971257        } 
    10981258        else if (   strcmp(argv[i],"--solid") == 0 || 
     
    13401500        oss.str("");         
    13411501    } 
    1342  
    1343     for (i=results.begin(); i!=results.end(); i++) 
    1344     { 
    1345         bool inserted = InsertBlock(con,  
    1346                                     *i,  
    1347                                     srid,  
    1348                                     reader2,  
    1349                                     table_name.c_str(),  
    1350                                     precision,  
    1351                                     pc_id,  
    1352                                     bUseSolidGeometry,  
    1353                                     bUse3d); 
    1354     } 
     1502     
     1503    InsertBlocks(con, results, nCommitInterval, srid, reader2, table_name.c_str(), precision, pc_id, bUseSolidGeometry, bUse3d); 
     1504    //  
     1505    // for (i=results.begin(); i!=results.end(); i++) 
     1506    // { 
     1507    //     bool inserted = InsertBlock(con,  
     1508    //                                 *i,  
     1509    //                                 srid,  
     1510    //                                 reader2,  
     1511    //                                 table_name.c_str(),  
     1512    //                                 precision,  
     1513    //                                 pc_id,  
     1514    //                                 bUseSolidGeometry,  
     1515    //                                 bUse3d); 
     1516    // } 
    13551517     
    13561518    if (!bUseExistingBlockTable) { 
  • apps/oci_wrapper.cpp

    r1438 r1582  
    436436    if( nStmtType != OCI_STMT_SELECT ) 
    437437    { 
    438         nStmtMode = OCI_COMMIT_ON_SUCCESS; 
    439         // nStmtMode = OCI_DEFAULT; 
     438        // nStmtMode = OCI_COMMIT_ON_SUCCESS; 
     439        nStmtMode = OCI_DEFAULT; 
    440440 
    441441    } 
     
    549549} 
    550550 
     551void OWStatement::Define( long* pnData ) 
     552{ 
     553    OCIDefine* hDefine = NULL; 
     554 
     555    nNextCol++; 
     556 
     557    CheckError( OCIDefineByPos( hStmt, 
     558        &hDefine, 
     559        hError, 
     560        (ub4) nNextCol, 
     561        (dvoid*) pnData, 
     562        (sb4) sizeof(long), 
     563        (ub2) SQLT_LNG, 
     564        (void*) NULL, 
     565        (ub2*) NULL, 
     566        (ub2*) NULL,  
     567        (ub4) OCI_DEFAULT ), hError ); 
     568} 
     569 
     570void OWStatement::Bind( long* pnData ) 
     571{ 
     572    OCIBind* hBind = NULL; 
     573 
     574    nNextBnd++; 
     575 
     576    CheckError( OCIBindByPos( 
     577        hStmt, 
     578        &hBind, 
     579        hError, 
     580        (ub4) nNextBnd, 
     581        (dvoid*) pnData, 
     582        (sb4) sizeof(long), 
     583        (ub2) SQLT_LNG, 
     584        (void*) NULL, 
     585        (ub2*) NULL, 
     586        (ub2*) NULL, 
     587        (ub4) NULL, 
     588        (ub4) NULL, 
     589        (ub4) OCI_DEFAULT ), 
     590        hError ); 
     591} 
    551592void OWStatement::Bind( double* pnData ) 
    552593{ 
     
    636677 
    637678void OWStatement::Bind( char* pszData, int nSize ) 
     679{ 
     680    OCIBind* hBind = NULL; 
     681 
     682    nNextBnd++; 
     683 
     684    CheckError( OCIBindByPos( 
     685        hStmt, 
     686        &hBind, 
     687        hError, 
     688        (ub4) nNextBnd, 
     689        (dvoid*) pszData, 
     690        (sb4) nSize, 
     691        (ub2) SQLT_STR, 
     692        (void*) NULL, 
     693        (ub2*) NULL, 
     694        (ub2*) NULL, 
     695        (ub4) NULL, 
     696        (ub4) NULL, 
     697        (ub4) OCI_DEFAULT ), 
     698        hError ); 
     699} 
     700 
     701void OWStatement::Define( const char* pszData, int nSize ) 
     702{ 
     703    OCIDefine* hDefine = NULL; 
     704 
     705    nNextCol++; 
     706 
     707    CheckError( OCIDefineByPos( 
     708        hStmt, 
     709        &hDefine, 
     710        hError, 
     711        (ub4) nNextCol, 
     712        (dvoid*) pszData, 
     713        (sb4) nSize, 
     714        (ub2) SQLT_STR, 
     715        (void*) NULL, 
     716        (ub2*) NULL, 
     717        (ub2*) NULL, 
     718        (ub4) OCI_DEFAULT ), 
     719        hError ); 
     720} 
     721 
     722void OWStatement::Bind( const char* pszData, int nSize ) 
    638723{ 
    639724    OCIBind* hBind = NULL; 
     
    826911} 
    827912 
     913void OWStatement::SetInteger( OCINumber* ppoData, int value ) 
     914{ 
     915 
     916    CheckError( OCINumberFromReal( 
     917        hError, 
     918        &value, 
     919        (uword) sizeof(int), 
     920        ppoData ), 
     921        hError ); 
     922 
     923} 
     924 
    828925double OWStatement::GetDouble( OCINumber* ppoData ) 
    829926{ 
     
    840937} 
    841938 
     939void OWStatement::SetDouble( OCINumber* ppoData, double value ) 
     940{ 
     941 
     942    CheckError( OCINumberFromReal( 
     943        hError, 
     944        &value, 
     945        (uword) sizeof(double), 
     946        ppoData ), 
     947        hError ); 
     948 
     949} 
    842950char* OWStatement::GetString( OCIString* ppoData ) 
    843951{ 
  • apps/oci_wrapper.h

    r1438 r1582  
    9494#define SDO_GEORASTER               TYPE_OWNER".SDO_GEORASTER" 
    9595#define SDO_NUMBER_ARRAY            TYPE_OWNER".SDO_NUMBER_ARRAY" 
     96#define SDO_ORDINATE_ARRAY          TYPE_OWNER".SDO_ORDINATE_ARRAY" 
     97#define SDO_ELEM_INFO_ARRAY         TYPE_OWNER".SDO_ELEM_INFO_ARRAY" 
     98 
    9699#define OW_XMLNS        "xmlns=\"http://xmlns.oracle.com/spatial/georaster\"" 
    97100 
     
    210213    OCIType*            hGeometryTDO; 
    211214    OCIType*            hGeoRasterTDO; 
    212  
     215    OCIType*            hElemArrayTDO; 
     216    OCIType*            hOrdinateArrayTDO; 
     217     
    213218public: 
    214219 
     
    271276 
    272277    int                 GetInteger( OCINumber* ppoData ); 
     278    void                SetInteger( OCINumber* ppoData, int value); 
    273279    double              GetDouble( OCINumber* ppoData ); 
     280    void                SetDouble( OCINumber* ppoData, double value); 
    274281    char*               GetString( OCIString* ppoData ); 
    275282 
    276283    void                Define( int* pnData ); 
    277284    void                Bind( int* pnData ); 
     285    void                Define( long* pnData ); 
     286    void                Bind( long* pnData ); 
    278287    void                Bind( double* pnData ); 
    279288    void                Bind( char* pData, long nData); 
     
    281290    void                Define( char* pszData, int nSize = OWNAME ); 
    282291    void                Bind( char* pszData, int nSize = OWNAME ); 
     292    void                Define( const char* pszData, int nSize = OWNAME ); 
     293    void                Bind( const char* pszData, int nSize = OWNAME ); 
    283294    void                Define( OCILobLocator** pphLocator, 
    284295                            bool bBLOB = false); 
Note: See TracChangeset for help on using the changeset viewer.