Changeset 1589:b29fc8876204


Ignore:
Timestamp:
02/22/10 12:17:06 (5 months ago)
Author:
Howard Butler <hobu.inc@…>
Branch:
default
Message:

basic array insertion working

Location:
apps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/las2oci.cpp

    r1587 r1589  
    3838#endif 
    3939 
    40  
     40typedef struct 
     41    { 
     42        long* srid; 
     43         
     44    } block; 
     45     
    4146bool KDTreeIndexExists(std::string& filename) 
    4247{ 
     
    7681    } 
    7782    return istrm; 
     83} 
     84 
     85bool EnableTracing(OWConnection* connection) 
     86{ 
     87    ostringstream oss; 
     88// http://www.oracle-base.com/articles/10g/SQLTrace10046TrcsessAndTkprof10g.php 
     89    oss << "ALTER SESSION SET EVENTS '10046 trace name context forever, level 12'"; 
     90 
     91    OWStatement* statement = 0; 
     92     
     93    statement = connection->CreateStatement(oss.str().c_str()); 
     94     
     95    if (statement->Execute() == false) { 
     96         
     97        std::cout << "statement execution failed "  << CPLGetLastErrorMsg() << std::endl; 
     98        delete statement; 
     99        return 0; 
     100    }     
    78101} 
    79102 
     
    319342} 
    320343 
    321 void GetElements(   OWStatement* statement, 
     344void SetElements(   OWStatement* statement, 
    322345                    OCIArray* sdo_elem_info,  
    323346                    bool bUseSolidGeometry) 
     
    338361} 
    339362 
    340 void GetOrdinates(   OWStatement* statement, 
     363void SetOrdinates(   OWStatement* statement, 
    341364                     OCIArray* sdo_ordinates,  
    342365                     double x0, double x1,  
     
    376399 
    377400    ostringstream s_srid; 
    378     ostringstream s_gtype; 
     401    long gtype; 
    379402    ostringstream s_eleminfo; 
    380403    bool bGeographic = false; 
    381404     
    382     if (srid == 0) { 
    383         s_srid << "NULL"; 
    384         // bUse3d = true; 
    385         // bUseSolidGeometry = true; 
    386         } 
    387     else if (srid == 4326) { 
    388         // bUse3d = true; 
    389         // bUseSolidGeometry = true; 
     405    EnableTracing(connection); 
     406     
     407    if (srid == 4326) { 
    390408        bGeographic = true; 
    391         s_srid << srid; 
    392         // s_srid << "NULL"; 
    393409    } 
    394410    else { 
     
    402418    if (bUse3d) { 
    403419        if (bUseSolidGeometry == true) { 
    404             s_gtype << "3008"; 
    405             s_eleminfo << "(1,1007,3)"; 
     420            gtype = 3008; 
    406421 
    407422        } else { 
    408             s_gtype << "3003"; 
    409             s_eleminfo  << "(1,1003,3)"; 
    410  
     423            gtype = 3003; 
    411424        } 
    412425    } else { 
    413426        if (bUseSolidGeometry == true) { 
    414             s_gtype << "2008"; 
    415             s_eleminfo << "(1,1007,3)"; 
    416  
     427            gtype = 2008; 
    417428        } else { 
    418             s_gtype << "2003"; 
    419             s_eleminfo  << "(1,1003,3)"; 
    420  
     429            gtype = 2003; 
    421430        } 
    422431    } 
    423432 
    424433    double x0, x1, y0, y1, z0, z1; 
    425     double tolerance = 0.05; 
    426434     
    427435 
     
    446454        z0 = 0.0; 
    447455        z1 = 20000.0; 
    448         tolerance = 0.000000005; 
    449456    } else { 
    450457        z0 = 0.0; 
     
    453460     
    454461         
    455     // std::cout << "use 3d?: " << bUse3d << " srid: " << s_srid.str() << std::endl; 
    456462    oss_geom.setf(std::ios_base::fixed, std::ios_base::floatfield); 
    457463    oss_geom.precision(precision); 
    458464 
    459 //     oss_geom << "           mdsys.sdo_geometry("<<s_gtype.str() <<", "<<s_srid.str()<<", null,\n" 
    460 // "              mdsys.sdo_elem_info_array"<< s_eleminfo.str() <<",\n" 
    461 // "              mdsys.sdo_ordinate_array(\n"; 
    462  
    463     oss_geom << "           mdsys.sdo_geometry(:5, :6, null,\n" 
    464 "              mdsys.sdo_elem_info_array"<< s_eleminfo.str() <<",\n" 
    465 "              mdsys.sdo_ordinate_array(\n"; 
    466     oss_geom << x0 << ",\n" << y0 << ",\n"; 
    467  
    468     if (bUse3d) { 
    469         oss_geom << z0 << ",\n"; 
    470     } 
    471  
    472     oss_geom << x1 << ",\n" << y1 << "\n"; 
    473  
    474     if (bUse3d) { 
    475         oss_geom << ",\n"; 
    476         oss_geom << z1; 
    477     } 
    478  
    479     long result_id = result.GetID(); 
    480      
    481     oss_geom << "))"; 
    482465    oss << "INSERT INTO "<< tableName <<  
    483             "(OBJ_ID, BLK_ID, NUM_POINTS, POINTS, BLK_EXTENT,  " 
    484             "PCBLK_MIN_RES, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) " 
    485             "VALUES ( :1, :2, :3, :4, " << oss_geom.str() << //:7, :8)"  
    486             // << pc_id << "," << result.GetID() <<"," << num_points << ", "  
    487             // << oss_geom.str() <<", :1" 
    488             ", 1, 1, 0, 1)"; 
    489  
    490  
    491     // oss << "INSERT INTO "<< tableName <<  
    492     //         "(OBJ_ID, BLK_ID, NUM_POINTS, BLK_EXTENT, POINTS, " 
    493     //         "PCBLK_MIN_RES, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) " 
    494     //         "VALUES ( :1, :2, :3, " << oss_geom.str() << 
    495     //         // << pc_id << "," << result.GetID() <<"," << num_points << ", "  
    496     //           
    497     //         ",:4, 1, 1, 0, 1)"; 
    498  
    499  
    500              
     466            "(OBJ_ID, BLK_ID, NUM_POINTS, POINTS,   " 
     467            "PCBLK_MIN_RES, BLK_EXTENT, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM) " 
     468            "VALUES ( :1, :2, :3, :4, 1, mdsys.sdo_geometry(:5, :6, null,:7, :8)"  
     469            ", 1, 0, 1)"; 
     470           
    501471    OWStatement* statement = 0; 
    502472    OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 ); 
     
    535505 
    536506    // :5 
    537     int gtype = atoi(s_gtype.str().c_str()); 
    538507    long* p_gtype = (long*) malloc (1 * sizeof(long)); 
    539508    p_gtype[0] = gtype; 
    540509 
    541     printf("gtype: %d %d %s\n", *p_gtype, gtype, s_gtype.str().c_str()); 
    542510    statement->Bind(p_gtype); 
    543511     
     
    553521     
    554522    // :7 
    555  
    556523    OCIArray* sdo_elem_info=0; 
    557     // connection->CreateType(sdo_elem_info, connection->GetElemInfoType()); 
    558     // GetElements(statement, sdo_elem_info, bUseSolidGeometry); 
    559      
    560     // statement->Bind(sdo_elem_info, connection->GetElemInfoType()); 
     524    connection->CreateType(&sdo_elem_info, connection->GetElemInfoType()); 
     525    SetElements(statement, sdo_elem_info, bUseSolidGeometry);     
     526    statement->Bind(&sdo_elem_info, connection->GetElemInfoType()); 
    561527     
    562528    // :8 
    563529    OCIArray* sdo_ordinates=0; 
    564     // connection->CreateType(sdo_ordinates, connection->GetOrdinateType()); 
    565      
    566     // GetOrdinates(statement, sdo_ordinates, x0, x1, y0, y1, z0, z1, bUse3d); 
    567     // statement->Bind(sdo_ordinates, connection->GetOrdinateType()); 
     530    connection->CreateType(&sdo_ordinates, connection->GetOrdinateType()); 
     531     
     532    SetOrdinates(statement, sdo_ordinates, x0, x1, y0, y1, z0, z1, bUse3d); 
     533    statement->Bind(&sdo_ordinates, connection->GetOrdinateType()); 
    568534     
    569535    if (statement->Execute() == false) { 
     
    649615    // } 
    650616     
     617 
    651618    if (srid == 0) { 
    652619        s_srid << "NULL"; 
     
    785752} 
    786753 
     754 
     755 
    787756long CreatePCEntry( OWConnection* connection,  
    788757                    LASQuery* query,  
  • apps/oci_wrapper.cpp

    r1588 r1589  
    245245} 
    246246 
    247 void OWConnection::CreateType( OCIArray* phData, OCIType* otype) 
     247void OWConnection::CreateType( OCIArray** phData, OCIType* otype) 
    248248{ 
    249249    CheckError(  
     
    256256                        OCI_DURATION_SESSION, 
    257257                        FALSE,  
    258                         (dvoid **)&phData) 
     258                        (dvoid **)phData) 
    259259                ,  
    260260                hError ); 
    261261} 
    262262 
    263 void OWConnection::DestroyType( OCIArray* phData ) 
     263void OWConnection::DestroyType( OCIArray** phData ) 
    264264{ 
    265265    CheckError( OCIObjectFree( 
    266266        hEnv, 
    267267        hError, 
    268         (OCIColl*) phData, 
     268        (OCIColl*) *phData, 
    269269        (ub2) 0), NULL ); 
    270270} 
     
    466466    if( nStmtType != OCI_STMT_SELECT ) 
    467467    { 
    468         nStmtMode = OCI_COMMIT_ON_SUCCESS; 
    469         // nStmtMode = OCI_DEFAULT; 
     468        // nStmtMode = OCI_COMMIT_ON_SUCCESS; 
     469        nStmtMode = OCI_DEFAULT; 
    470470 
    471471    } 
     
    648648 
    649649    nNextBnd++; 
    650     printf("Binding blob column #: %d\n", nNextBnd); 
    651650    CheckError( OCIBindByPos(  
    652651        hStmt, 
     
    831830} 
    832831 
    833 void OWStatement::Bind( OCIArray* pphData, OCIType* type ) 
     832void OWStatement::Bind( OCIArray** pphData, OCIType* type ) 
    834833{ 
    835834    OCIBind* hBind = NULL; 
     
    857856        hError,  
    858857        type,  
    859         (dvoid **)&pphData,  
     858        (dvoid **)pphData,  
    860859        (ub4 *)0,  
    861860        (dvoid **)0,  
     
    11091108{ 
    11101109    OCINumber      oci_number; 
    1111  
    1112  
     1110     
    11131111    CheckError(OCINumberFromInt(hError, (dvoid *)&nValue,  
    11141112        (uword)sizeof(ub4), OCI_NUMBER_UNSIGNED,  
  • apps/oci_wrapper.h

    r1583 r1589  
    232232    void                DestroyType( sdo_geometry** pphData ); 
    233233 
    234     void                CreateType( OCIArray* phData , OCIType* type); 
    235     void                DestroyType( OCIArray* phData ); 
     234    void                CreateType( OCIArray** phData , OCIType* type); 
     235    void                DestroyType( OCIArray** phData ); 
    236236 
    237237    OCIType*            DescribeType( char *pszTypeName ); 
     
    296296    void                Bind( double* pnData ); 
    297297    void                Bind( char* pData, long nData); 
    298     void                Bind( OCIArray* pphData, OCIType* type ); 
     298    void                Bind( OCIArray** pphData, OCIType* type ); 
    299299     
    300300    void                Define( double* pnData ); 
Note: See TracChangeset for help on using the changeset viewer.