Beispiel #1
0
    bool Statement::Step()
    {
#if ORTHANC_SQLITE_STANDALONE != 1
      VLOG(1) << "SQLite::Statement::Step " << sqlite3_sql(GetStatement());
#endif

      return CheckError(sqlite3_step(GetStatement()), ErrorCode_SQLiteCannotStep) == SQLITE_ROW;
    }
Beispiel #2
0
    bool Statement::Run()
    {
#if ORTHANC_SQLITE_STANDALONE != 1
      VLOG(1) << "SQLite::Statement::Run " << sqlite3_sql(GetStatement());
#endif

      return CheckError(sqlite3_step(GetStatement())) == SQLITE_DONE;
    }
Beispiel #3
0
 void Statement::Reset(bool clear_bound_vars) 
 {
   // We don't call CheckError() here because sqlite3_reset() returns
   // the last error that Step() caused thereby generating a second
   // spurious error callback.
   if (clear_bound_vars)
     sqlite3_clear_bindings(GetStatement());
   //VLOG(1) << "SQLite::Statement::Reset";
   sqlite3_reset(GetStatement());
 }
Beispiel #4
0
    std::string Statement::ColumnString(int col) const 
    {
      const char* str = reinterpret_cast<const char*>(
        sqlite3_column_text(GetStatement(), col));
      int len = sqlite3_column_bytes(GetStatement(), col);

      std::string result;
      if (str && len > 0)
        result.assign(str, len);
      return result;
    }
Beispiel #5
0
Datei: Dsl.cpp Projekt: CQiao/DSL
  void Function::WriteToFile(FILE* fp, int indent)const
  {
#if _DEBUG
    if (m_Call.IsValid()){
      m_Call.WriteToFile(fp, indent);
      fwrite("\n", 1, 1, fp);
    }
    if (HaveStatement()){
      WriteIndent(fp, indent);
      fwrite("{\n", 2, 1, fp);
      for (int ix = 0; ix < GetStatementNum(); ++ix){
        ISyntaxComponent& component = *GetStatement(ix);
        WriteComponent(fp, component, indent + 1);
        fwrite(";\n", 2, 1, fp);
      }
      WriteIndent(fp, indent);
      fwrite("}", 1, 1, fp);
    }
    if (HaveExternScript()){
      WriteIndent(fp, indent);
      fwrite("{:\n", 3, 1, fp);
      fwrite(m_ExternScript, strlen(m_ExternScript), 1, fp);
      fwrite(":}", 2, 1, fp);
    }
#endif
  }
Beispiel #6
0
void DoFirstPass(FILE *fd) {

   StatementType statement;

   current_address = 0;
   while(GetStatement(fd, &statement, 1, NULL)) {
      ++current_address;
      ++byte_count;
      if(statement.arg) {
         switch(statement.op) {
         case BYTE_OP:
            break;
         case WORD_OP:
            ++current_address;
            ++byte_count;
            break;
         default:
            current_address += 2;
            byte_count += 2;
            break;
         }
      }
   }

}
Beispiel #7
0
 void Statement::BindString(int col, const std::string& val) 
 {
   CheckOk(sqlite3_bind_text(GetStatement(),
                             col + 1,
                             val.data(),
                             val.size(),
                             SQLITE_TRANSIENT));
 }
Beispiel #8
0
void ShowTable(std::string database_name, std::string table_name) {
  // auto table =
  // catalog::Catalog::GetInstance()->GetTableWithName(database_name,
  //                                                                table_name);
  (void)database_name;
  std::unique_ptr<Statement> statement;
  auto &peloton_parser = parser::PostgresParser::GetInstance();
  executor::ExecutionResult status;
  std::vector<type::Value> params;
  std::vector<ResultValue> result;

  optimizer::Optimizer optimizer;

  auto &traffic_cop = tcop::TrafficCop::GetInstance();
  traffic_cop.SetTaskCallback(TestingSQLUtil::UtilTestTaskCallback,
                              &TestingSQLUtil::counter_);
  auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
  auto txn = txn_manager.BeginTransaction();
  traffic_cop.SetTcopTxnState(txn);

  statement.reset(new Statement("SELECT", "SELECT * FROM " + table_name));
  auto select_stmt =
      peloton_parser.BuildParseTree("SELECT * FROM " + table_name);

  auto parse_tree = select_stmt->GetStatement(0);
  auto bind_node_visitor = binder::BindNodeVisitor(txn, DEFAULT_DB_NAME);
  bind_node_visitor.BindNameToNode(parse_tree);

  statement->SetPlanTree(optimizer.BuildPelotonPlanTree(select_stmt, txn));
  LOG_TRACE("Query Plan\n%s",
            planner::PlanUtil::GetInfo(statement->GetPlanTree().get()).c_str());
  std::vector<int> result_format;
  auto tuple_descriptor = traffic_cop.GenerateTupleDescriptor(
      (parser::SelectStatement *)select_stmt->GetStatement(0));
  result_format = std::vector<int>(tuple_descriptor.size(), 0);
  TestingSQLUtil::counter_.store(1);
  status = traffic_cop.ExecuteHelper(statement->GetPlanTree(), params, result,
                                     result_format);
  if (traffic_cop.GetQueuing()) {
    TestingSQLUtil::ContinueAfterComplete();
    traffic_cop.ExecuteStatementPlanGetResult();
    status = traffic_cop.p_status_;
    traffic_cop.SetQueuing(false);
  }
  traffic_cop.CommitQueryHelper();
}
Beispiel #9
0
 void Statement::BindString(int col, const std::string& val) 
 {
   CheckOk(sqlite3_bind_text(GetStatement(),
                             col + 1,
                             val.data(),
                             val.size(),
                             SQLITE_TRANSIENT),
           ErrorCode_BadParameterType);
 }
Beispiel #10
0
    ColumnType Statement::GetColumnType(int col) const 
    {
      // Verify that our enum matches sqlite's values.
      assert(COLUMN_TYPE_INTEGER == SQLITE_INTEGER);
      assert(COLUMN_TYPE_FLOAT == SQLITE_FLOAT);
      assert(COLUMN_TYPE_TEXT == SQLITE_TEXT);
      assert(COLUMN_TYPE_BLOB == SQLITE_BLOB);
      assert(COLUMN_TYPE_NULL == SQLITE_NULL);

      return static_cast<ColumnType>(sqlite3_column_type(GetStatement(), col));
    }
Beispiel #11
0
    ColumnType Statement::GetDeclaredColumnType(int col) const 
    {
      std::string column_type(sqlite3_column_decltype(GetStatement(), col));
      std::transform(column_type.begin(), column_type.end(), column_type.begin(), tolower);

      if (column_type == "integer")
        return COLUMN_TYPE_INTEGER;
      else if (column_type == "float")
        return COLUMN_TYPE_FLOAT;
      else if (column_type == "text")
        return COLUMN_TYPE_TEXT;
      else if (column_type == "blob")
        return COLUMN_TYPE_BLOB;

      return COLUMN_TYPE_NULL;
    }
Beispiel #12
0
OGRFeature *OGRWalkLayer::GetNextRawFeature()

{
    if( GetStatement() == NULL )
        return NULL;

/* -------------------------------------------------------------------- */
/*      If we are marked to restart then do so, and fetch a record.     */
/* -------------------------------------------------------------------- */
    if( !poStmt->Fetch() )
    {
        delete poStmt;
        poStmt = NULL;
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Create a feature from the current result.                       */
/* -------------------------------------------------------------------- */
    OGRFeature *poFeature = new OGRFeature( poFeatureDefn );

    if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
        poFeature->SetFID(
            atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
    else
        poFeature->SetFID( iNextShapeId );

    iNextShapeId++;
    m_nFeaturesRead++;

/* -------------------------------------------------------------------- */
/*      Set the fields.                                                 */
/* -------------------------------------------------------------------- */
    for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        int iSrcField = panFieldOrdinals[iField]-1;
        const char *pszValue = poStmt->GetColData( iSrcField );

        if( pszValue == NULL )
            /* no value */;
        else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
            poFeature->SetField( iField,
                                 poStmt->GetColDataLength(iSrcField),
                                 (GByte *) pszValue );
        else
            poFeature->SetField( iField, pszValue );
    }

/* -------------------------------------------------------------------- */
/*      Try to extract a geometry.                                      */
/* -------------------------------------------------------------------- */
    if( pszGeomColumn != NULL )
    {
        int iField = poStmt->GetColId( pszGeomColumn );
        const char *pszGeomBin = poStmt->GetColData( iField );
        int nGeomLength = poStmt->GetColDataLength( iField );
        OGRGeometry *poGeom = NULL;
        OGRErr eErr = OGRERR_NONE;

        if( pszGeomBin != NULL && bGeomColumnWKB )
        {
            WKBGeometry *WalkGeom = (WKBGeometry *)CPLMalloc(sizeof(WKBGeometry));
            if( Binary2WkbGeom((unsigned char *)pszGeomBin, WalkGeom, nGeomLength)
                != OGRERR_NONE )
            {
                CPLFree(WalkGeom);
                return NULL;
            }
            eErr = TranslateWalkGeom(&poGeom, WalkGeom);

            DeleteWKBGeometry(*WalkGeom);
            CPLFree(WalkGeom);
        }

        if ( eErr != OGRERR_NONE )
        {
            const char *pszMessage;

            switch ( eErr )
            {
                case OGRERR_NOT_ENOUGH_DATA:
                    pszMessage = "Not enough data to deserialize";
                    break;
                case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
                    pszMessage = "Unsupported geometry type";
                    break;
                case OGRERR_CORRUPT_DATA:
                    pszMessage = "Corrupt data";
                    break;
                default:
                    pszMessage = "Unrecognized error";
            }
            CPLError(CE_Failure, CPLE_AppDefined,
                     "GetNextRawFeature(): %s", pszMessage);
        }

        if( poGeom != NULL && eErr == OGRERR_NONE )
        {
            poGeom->assignSpatialReference( poSRS );
            poFeature->SetGeometryDirectly( poGeom );
        }
    }

    return poFeature;
}
Beispiel #13
0
 void Statement::BindNull(int col)
 {
   CheckOk(sqlite3_bind_null(GetStatement(), col + 1),
           ErrorCode_BadParameterType);
 }
Beispiel #14
0
TEST_F(CreateIndexTests, CreatingIndex) {
  LOG_INFO("Bootstrapping...");
  auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
  auto txn = txn_manager.BeginTransaction();
  catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
  txn_manager.CommitTransaction(txn);
  LOG_INFO("Bootstrapping completed!");

  std::unique_ptr<optimizer::AbstractOptimizer> optimizer;
  optimizer.reset(new optimizer::Optimizer);

  auto &traffic_cop = tcop::TrafficCop::GetInstance();
  traffic_cop.SetTaskCallback(TestingSQLUtil::UtilTestTaskCallback,
                              &TestingSQLUtil::counter_);

  // Create a table first
  txn = txn_manager.BeginTransaction();
  traffic_cop.SetTcopTxnState(txn);
  LOG_INFO("Creating table");
  LOG_INFO(
      "Query: CREATE TABLE department_table(dept_id INT PRIMARY KEY,student_id "
      "INT, dept_name TEXT);");
  std::unique_ptr<Statement> statement;
  statement.reset(new Statement("CREATE",
                                "CREATE TABLE department_table(dept_id INT "
                                "PRIMARY KEY, student_id INT, dept_name "
                                "TEXT);"));

  auto &peloton_parser = parser::PostgresParser::GetInstance();

  LOG_INFO("Building parse tree...");
  auto create_stmt = peloton_parser.BuildParseTree(
      "CREATE TABLE department_table(dept_id INT PRIMARY KEY, student_id INT, "
      "dept_name TEXT);");
  LOG_INFO("Building parse tree completed!");

  LOG_INFO("Binding parse tree...");
  auto parse_tree = create_stmt->GetStatement(0);
  auto bind_node_visitor = binder::BindNodeVisitor(txn, DEFAULT_DB_NAME);
  bind_node_visitor.BindNameToNode(parse_tree);
  LOG_INFO("Binding parse tree completed!");

  LOG_INFO("Building plan tree...");
  statement->SetPlanTree(optimizer->BuildPelotonPlanTree(create_stmt, txn));
  LOG_INFO("Building plan tree completed!");

  std::vector<type::Value> params;
  std::vector<ResultValue> result;
  LOG_INFO("Executing plan...\n%s",
           planner::PlanUtil::GetInfo(statement->GetPlanTree().get()).c_str());
  std::vector<int> result_format;
  result_format = std::vector<int>(statement->GetTupleDescriptor().size(), 0);

  TestingSQLUtil::counter_.store(1);
  executor::ExecutionResult status = traffic_cop.ExecuteHelper(
      statement->GetPlanTree(), params, result, result_format);

  if (traffic_cop.GetQueuing()) {
    TestingSQLUtil::ContinueAfterComplete();
    traffic_cop.ExecuteStatementPlanGetResult();
    status = traffic_cop.p_status_;
    traffic_cop.SetQueuing(false);
  }

  LOG_INFO("Statement executed. Result: %s",
           ResultTypeToString(status.m_result).c_str());
  LOG_INFO("Table Created");
  traffic_cop.CommitQueryHelper();

  txn = txn_manager.BeginTransaction();
  // Inserting a tuple end-to-end
  traffic_cop.SetTcopTxnState(txn);
  LOG_INFO("Inserting a tuple...");
  LOG_INFO(
      "Query: INSERT INTO department_table(dept_id,student_id ,dept_name) "
      "VALUES (1,52,'hello_1');");
  statement.reset(new Statement("INSERT",
                                "INSERT INTO department_table(dept_id, "
                                "student_id, dept_name) VALUES "
                                "(1,52,'hello_1');"));

  LOG_INFO("Building parse tree...");
  auto insert_stmt = peloton_parser.BuildParseTree(
      "INSERT INTO department_table(dept_id,student_id,dept_name) VALUES "
      "(1,52,'hello_1');");
  LOG_INFO("Building parse tree completed!");

  LOG_INFO("Binding parse tree...");
  parse_tree = insert_stmt->GetStatement(0);
  bind_node_visitor = binder::BindNodeVisitor(txn, DEFAULT_DB_NAME);
  bind_node_visitor.BindNameToNode(parse_tree);
  LOG_INFO("Binding parse tree completed!");

  LOG_INFO("Building plan tree...");
  statement->SetPlanTree(optimizer->BuildPelotonPlanTree(insert_stmt, txn));
  LOG_INFO("Building plan tree completed!\n%s",
           planner::PlanUtil::GetInfo(statement->GetPlanTree().get()).c_str());

  LOG_INFO("Executing plan...");
  result_format = std::vector<int>(statement->GetTupleDescriptor().size(), 0);

  TestingSQLUtil::counter_.store(1);
  status = traffic_cop.ExecuteHelper(statement->GetPlanTree(), params, result,
                                     result_format);

  if (traffic_cop.GetQueuing()) {
    TestingSQLUtil::ContinueAfterComplete();
    traffic_cop.ExecuteStatementPlanGetResult();
    status = traffic_cop.p_status_;
    traffic_cop.SetQueuing(false);
  }
  LOG_INFO("Statement executed. Result: %s",
           ResultTypeToString(status.m_result).c_str());
  LOG_INFO("Tuple inserted!");
  traffic_cop.CommitQueryHelper();

  // Now Updating end-to-end
  txn = txn_manager.BeginTransaction();
  traffic_cop.SetTcopTxnState(txn);
  LOG_INFO("Creating and Index");
  LOG_INFO("Query: CREATE INDEX saif ON department_table (student_id);");
  statement.reset(new Statement(
      "CREATE", "CREATE INDEX saif ON department_table (student_id);"));

  LOG_INFO("Building parse tree...");
  auto update_stmt = peloton_parser.BuildParseTree(
      "CREATE INDEX saif ON department_table (student_id);");
  LOG_INFO("Building parse tree completed!");

  LOG_INFO("Binding parse tree...");
  parse_tree = update_stmt->GetStatement(0);
  bind_node_visitor = binder::BindNodeVisitor(txn, DEFAULT_DB_NAME);
  bind_node_visitor.BindNameToNode(parse_tree);
  LOG_INFO("Binding parse tree completed!");

  LOG_INFO("Building plan tree...");
  statement->SetPlanTree(optimizer->BuildPelotonPlanTree(update_stmt, txn));
  LOG_INFO("Building plan tree completed!\n%s",
           planner::PlanUtil::GetInfo(statement->GetPlanTree().get()).c_str());

  LOG_INFO("Executing plan...");
  result_format = std::vector<int>(statement->GetTupleDescriptor().size(), 0);

  TestingSQLUtil::counter_.store(1);
  status = traffic_cop.ExecuteHelper(statement->GetPlanTree(), params, result,
                                     result_format);

  if (traffic_cop.GetQueuing()) {
    TestingSQLUtil::ContinueAfterComplete();
    traffic_cop.ExecuteStatementPlanGetResult();
    status = traffic_cop.p_status_;
    traffic_cop.SetQueuing(false);
  }
  LOG_INFO("Statement executed. Result: %s",
           ResultTypeToString(status.m_result).c_str());
  LOG_INFO("INDEX CREATED!");
  traffic_cop.CommitQueryHelper();

  txn = txn_manager.BeginTransaction();
  auto target_table_ = catalog::Catalog::GetInstance()->GetTableWithName(
      DEFAULT_DB_NAME, DEFUALT_SCHEMA_NAME, "department_table", txn);
  // Expected 2 , Primary key index + created index
  EXPECT_EQ(target_table_->GetIndexCount(), 2);

  // free the database just created
  catalog::Catalog::GetInstance()->DropDatabaseWithName(DEFAULT_DB_NAME, txn);
  txn_manager.CommitTransaction(txn);
}
Beispiel #15
0
OGRFeature *OGRDB2Layer::GetNextRawFeature()

{

    if( GetStatement() == nullptr )
        return nullptr;

    /* -------------------------------------------------------------------- */
    /*      If we are marked to restart then do so, and fetch a record.     */
    /* -------------------------------------------------------------------- */
    if( !m_poStmt->Fetch() )  // fail is normal for final fetch
    {
//      CPLDebug("OGR_DB2Layer::GetNextRawFeature","Fetch failed");
        delete m_poStmt;
        m_poStmt = nullptr;
        return nullptr;
    }
//      CPLDebug("OGR_DB2Layer::GetNextRawFeature","Create feature");
    /* -------------------------------------------------------------------- */
    /*      Create a feature from the current result.                       */
    /* -------------------------------------------------------------------- */
    int         iField;
    OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
    if( pszFIDColumn != nullptr && m_poStmt->GetColId(pszFIDColumn) > -1 )
        poFeature->SetFID(
            atoi(m_poStmt->GetColData(m_poStmt->GetColId(pszFIDColumn))) );
    else
        poFeature->SetFID( iNextShapeId );

    iNextShapeId++;
    m_nFeaturesRead++;

    /* -------------------------------------------------------------------- */
    /*      Set the fields.                                                 */
    /* -------------------------------------------------------------------- */

    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        if ( poFeatureDefn->GetFieldDefn(iField)->IsIgnored() )
            continue;

        int iSrcField = panFieldOrdinals[iField];
        const char *pszValue = m_poStmt->GetColData( iSrcField );

        if( pszValue == nullptr )
            poFeature->SetFieldNull( iField );
        else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
            poFeature->SetField( iField,
                                 m_poStmt->GetColDataLength(iSrcField),
                                 (GByte *) pszValue );
        else
            poFeature->SetField( iField, pszValue );
    }

    /* -------------------------------------------------------------------- */
    /*      Try to extract a geometry.                                      */
    /* -------------------------------------------------------------------- */

    if( pszGeomColumn != nullptr && !poFeatureDefn->IsGeometryIgnored())
    {
        iField = m_poStmt->GetColId( pszGeomColumn );
        const char *pszGeomText = m_poStmt->GetColData( iField );
        OGRGeometry *poGeom = nullptr;
        OGRErr eErr = OGRERR_NONE;
        if( pszGeomText != nullptr )
        {
            eErr = OGRGeometryFactory::createFromWkt(pszGeomText,
                    nullptr, &poGeom);
        }

        if ( eErr != OGRERR_NONE )
        {
            const char *pszMessage;

            switch ( eErr )
            {
            case OGRERR_NOT_ENOUGH_DATA:
                pszMessage = "Not enough data to deserialize";
                break;
            case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
                pszMessage = "Unsupported geometry type";
                break;
            case OGRERR_CORRUPT_DATA:
                pszMessage = "Corrupt data";
                break;
            default:
                pszMessage = "Unrecognized error";
            }
            CPLError(CE_Failure, CPLE_AppDefined,
                     "GetNextRawFeature(): %s", pszMessage);
        }

        if( poGeom != nullptr )
        {
            if ( GetSpatialRef() )
                poGeom->assignSpatialReference( poSRS );

            poFeature->SetGeometryDirectly( poGeom );
        }
    }

    return poFeature;
}
Beispiel #16
0
 const void* Statement::ColumnBlob(int col) const 
 {
   return sqlite3_column_blob(GetStatement(), col);
 }
Beispiel #17
0
OGRFeature *OGRODBCLayer::GetNextRawFeature()

{
    if( GetStatement() == NULL )
        return NULL;

/* -------------------------------------------------------------------- */
/*      If we are marked to restart then do so, and fetch a record.     */
/* -------------------------------------------------------------------- */
    if( !poStmt->Fetch() )
    {
        delete poStmt;
        poStmt = NULL;
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Create a feature from the current result.                       */
/* -------------------------------------------------------------------- */
    int         iField;
    OGRFeature *poFeature = new OGRFeature( poFeatureDefn );

    if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
        poFeature->SetFID( 
            atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
    else
        poFeature->SetFID( iNextShapeId );

    iNextShapeId++;
    m_nFeaturesRead++;

/* -------------------------------------------------------------------- */
/*      Set the fields.                                                 */
/* -------------------------------------------------------------------- */
    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        int iSrcField = panFieldOrdinals[iField]-1;
        const char *pszValue = poStmt->GetColData( iSrcField );

        if( pszValue == NULL )
            /* no value */;
        else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
            poFeature->SetField( iField, 
                                 poStmt->GetColDataLength(iSrcField),
                                 (GByte *) pszValue );
        else
            poFeature->SetField( iField, pszValue );
    }

/* -------------------------------------------------------------------- */
/*      Try to extract a geometry.                                      */
/* -------------------------------------------------------------------- */
    if( pszGeomColumn != NULL )
    {
        int iField = poStmt->GetColId( pszGeomColumn );
        const char *pszGeomText = poStmt->GetColData( iField );
        OGRGeometry *poGeom = NULL;
        OGRErr eErr = OGRERR_NONE;

        if( pszGeomText != NULL && !bGeomColumnWKB )
        {
            eErr =
                OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
                                                  NULL, &poGeom);
        }
        else if( pszGeomText != NULL && bGeomColumnWKB )
        {
            int nLength = poStmt->GetColDataLength( iField );

            eErr =
                OGRGeometryFactory::createFromWkb((unsigned char *) pszGeomText,
                                                  NULL, &poGeom, nLength);
        }
        
        if ( eErr != OGRERR_NONE )
        {
            const char *pszMessage;

            switch ( eErr )
            {
                case OGRERR_NOT_ENOUGH_DATA:
                    pszMessage = "Not enough data to deserialize";
                    break;
                case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
                    pszMessage = "Unsupported geometry type";
                    break;
                case OGRERR_CORRUPT_DATA:
                    pszMessage = "Corrupt data";
                    break;
                default:
                    pszMessage = "Unrecognized error";
            }
            CPLError(CE_Failure, CPLE_AppDefined,
                     "GetNextRawFeature(): %s", pszMessage);
        }

        if( poGeom != NULL )
            poFeature->SetGeometryDirectly( poGeom );
    }

    return poFeature;
}
Beispiel #18
0
 void Statement::BindInt64(int col, int64_t val) 
 {
   CheckOk(sqlite3_bind_int64(GetStatement(), col + 1, val),
           ErrorCode_BadParameterType);
 }
Beispiel #19
0
 int Statement::ColumnCount() const 
 {
   return sqlite3_column_count(GetStatement());
 }
Beispiel #20
0
 int64_t Statement::ColumnInt64(int col) const 
 {
   return sqlite3_column_int64(GetStatement(), col);
 }
Beispiel #21
0
 double Statement::ColumnDouble(int col) const 
 {
   return sqlite3_column_double(GetStatement(), col);
 }
Beispiel #22
0
 void Statement::BindDouble(int col, double val) 
 {
   CheckOk(sqlite3_bind_double(GetStatement(), col + 1, val),
           ErrorCode_BadParameterType);
 }
Beispiel #23
0
OGRFeature *OGRPGeoLayer::GetNextRawFeature()

{
    OGRErr err = OGRERR_NONE;

    if( GetStatement() == NULL )
        return NULL;

    /* -------------------------------------------------------------------- */
    /*      If we are marked to restart then do so, and fetch a record.     */
    /* -------------------------------------------------------------------- */
    if( !poStmt->Fetch() )
    {
        delete poStmt;
        poStmt = NULL;
        return NULL;
    }

    /* -------------------------------------------------------------------- */
    /*      Create a feature from the current result.                       */
    /* -------------------------------------------------------------------- */
    int         iField;
    OGRFeature *poFeature = new OGRFeature( poFeatureDefn );

    if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
        poFeature->SetFID(
            atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
    else
        poFeature->SetFID( iNextShapeId );

    iNextShapeId++;
    m_nFeaturesRead++;

    /* -------------------------------------------------------------------- */
    /*      Set the fields.                                                 */
    /* -------------------------------------------------------------------- */
    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        int iSrcField = panFieldOrdinals[iField]-1;
        const char *pszValue = poStmt->GetColData( iSrcField );

        if( pszValue == NULL )
            /* no value */;
        else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
            poFeature->SetField( iField,
                                 poStmt->GetColDataLength(iSrcField),
                                 (GByte *) pszValue );
        else
            poFeature->SetField( iField, pszValue );
    }

    /* -------------------------------------------------------------------- */
    /*      Try to extract a geometry.                                      */
    /* -------------------------------------------------------------------- */
    if( pszGeomColumn != NULL )
    {
        int iField = poStmt->GetColId( pszGeomColumn );
        GByte *pabyShape = (GByte *) poStmt->GetColData( iField );
        int nBytes = poStmt->GetColDataLength(iField);
        OGRGeometry *poGeom = NULL;

        if( pabyShape != NULL )
        {
            err = OGRCreateFromShapeBin( pabyShape, &poGeom, nBytes );
            if( OGRERR_NONE != err )
            {
                CPLDebug( "PGeo",
                          "Translation shape binary to OGR geometry failed (FID=%ld)",
                          (long)poFeature->GetFID() );
            }
        }

        if( poGeom != NULL && OGRERR_NONE == err )
        {
            poGeom->assignSpatialReference( poSRS );
            poFeature->SetGeometryDirectly( poGeom );
        }
    }

    return poFeature;
}
Beispiel #24
0
 void Statement::BindCString(int col, const char* val) 
 {
   CheckOk(sqlite3_bind_text(GetStatement(), col + 1, val, -1, SQLITE_TRANSIENT),
           ErrorCode_BadParameterType);
 }
Beispiel #25
0
 std::string Statement::GetOriginalSQLStatement()
 {
   return std::string(sqlite3_sql(GetStatement()));
 }
Beispiel #26
0
 int Statement::ColumnByteLength(int col) const 
 {
   return sqlite3_column_bytes(GetStatement(), col);
 }
Beispiel #27
0
void DoSecondPass(FILE *input, FILE *output) {

   StatementType statement;
   unsigned int temp;
   char *line;
   size_t len;
   char *start, *end;

   current_address = 0;
   line = NULL;
   while(GetStatement(input, &statement, 0, &line)) {

      start = line;
      for(;;) {
         end = strchr(start, '\n');
         if(!end) {
            break;
         }
         *end = 0;
         if(output_format == OUT_LISTING) {
            fprintf(output, "                    %s\n", start);
         }
         start = end + 1;
      }

      // Output the address.
      if(output_format == OUT_LISTING) {
         fprintf(output, "%04X ", current_address);
      }

      // Output the opcode.
      switch(statement.op) {
      case BYTE_OP:
      case WORD_OP:
         break;
      default:
         switch(output_format) {
         case OUT_RAW:
            fprintf(output, "%c", statement.op);
            break;
         case OUT_HEX:
            fprintf(output, "%02X\n", statement.op);
            break;
         default: // LISTING
            fprintf(output, "%02X", statement.op);
            break;
         }
         break;
      }

      // Output the argument (if there is one).
      if(statement.arg) {
         temp = Evaluate(statement.arg);
         switch(statement.op) {
         case BYTE_OP:
            switch(output_format) {
            case OUT_RAW:
               fprintf(output, "%c", temp);
               break;
            case OUT_HEX:
               fprintf(output, "%02X\n", temp);
               break;
            default: // LISTING
               fprintf(output, "%02X", temp);
               break;
            }
            break;
         default:
            switch(output_format) {
            case OUT_RAW:
               fprintf(output, "%c%c", temp >> 8, temp & 0xFF);
               break;
            case OUT_HEX:
               fprintf(output, "%02X\n", temp >> 8);
               fprintf(output, "%02X\n", temp & 0xFF);
               break;
            default: // LISTING
               fprintf(output, " %02X %02X", temp >> 8, temp & 0xFF);
               break;
            }
            break;
         }
      }

      if(output_format == OUT_LISTING) {
         len = 0;
         switch(statement.op) {
         case BYTE_OP:
            len = 3;
            break;
         case WORD_OP:
            len = 6;
            break;
         default:
            if(statement.arg) {
               len = 9;
            } else {
               len = 3;
            }
            break;
         }
         for(temp = 0; temp < (16 - len); temp++) {
            fprintf(output, " ");
         }
         fprintf(output, "%s\n", start);
      }

      ++current_address;
      if(statement.arg) {
         switch(statement.op) {
         case BYTE_OP:
            break;
         case WORD_OP:
            ++current_address;
            break;
         default:
            current_address += 2;
            break;
         }
      }

      free(line);
      line = NULL;

   }
Beispiel #28
0
 void Statement::BindBlob(int col, const void* val, int val_len) 
 {
   CheckOk(sqlite3_bind_blob(GetStatement(), col + 1, val, val_len, SQLITE_TRANSIENT),
           ErrorCode_BadParameterType);
 }
OGRFeature *OGRMSSQLSpatialLayer::GetNextRawFeature()

{
    if( GetStatement() == NULL )
        return NULL;

/* -------------------------------------------------------------------- */
/*      If we are marked to restart then do so, and fetch a record.     */
/* -------------------------------------------------------------------- */
    if( !poStmt->Fetch() )
    {
        delete poStmt;
        poStmt = NULL;
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Create a feature from the current result.                       */
/* -------------------------------------------------------------------- */
    int         iField;
    OGRFeature *poFeature = new OGRFeature( poFeatureDefn );

    if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
        poFeature->SetFID( 
            CPLAtoGIntBig(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
    else
        poFeature->SetFID( iNextShapeId );

    iNextShapeId++;
    m_nFeaturesRead++;

/* -------------------------------------------------------------------- */
/*      Set the fields.                                                 */
/* -------------------------------------------------------------------- */
    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        if ( poFeatureDefn->GetFieldDefn(iField)->IsIgnored() )
            continue;
        
        int iSrcField = panFieldOrdinals[iField];
        const char *pszValue = poStmt->GetColData( iSrcField );

        if( pszValue == NULL )
            /* no value */;
        else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
            poFeature->SetField( iField, 
                                 poStmt->GetColDataLength(iSrcField),
                                 (GByte *) pszValue );
        else
            poFeature->SetField( iField, pszValue );
    }

/* -------------------------------------------------------------------- */
/*      Try to extract a geometry.                                      */
/* -------------------------------------------------------------------- */
    if( pszGeomColumn != NULL && !poFeatureDefn->IsGeometryIgnored())
    {
        int iField = poStmt->GetColId( pszGeomColumn );
        const char *pszGeomText = poStmt->GetColData( iField );
        OGRGeometry *poGeom = NULL;
        OGRErr eErr = OGRERR_NONE;

        if( pszGeomText != NULL )
        {
            int nLength = poStmt->GetColDataLength( iField );

            if ( nGeomColumnType == MSSQLCOLTYPE_GEOMETRY || 
                 nGeomColumnType == MSSQLCOLTYPE_GEOGRAPHY ||
                 nGeomColumnType == MSSQLCOLTYPE_BINARY)
            {
                switch ( poDS->GetGeometryFormat() )
                {
                case MSSQLGEOMETRY_NATIVE:
                    {
                        OGRMSSQLGeometryParser oParser( nGeomColumnType ); 
                        eErr = oParser.ParseSqlGeometry( 
                            (unsigned char *) pszGeomText, nLength, &poGeom );
                        nSRSId = oParser.GetSRSId();
                    }
                    break;
                case MSSQLGEOMETRY_WKB:
                case MSSQLGEOMETRY_WKBZM:
                    eErr = OGRGeometryFactory::createFromWkb((unsigned char *) pszGeomText,
                                                      NULL, &poGeom, nLength);
                    break;
                case MSSQLGEOMETRY_WKT:
                    eErr = OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
                                                      NULL, &poGeom);
                    break;
                } 
            }
            else if (nGeomColumnType == MSSQLCOLTYPE_TEXT)
            {
                eErr = OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
                                                      NULL, &poGeom);
            }    
        }
        
        if ( eErr != OGRERR_NONE )
        {
            const char *pszMessage;

            switch ( eErr )
            {
                case OGRERR_NOT_ENOUGH_DATA:
                    pszMessage = "Not enough data to deserialize";
                    break;
                case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
                    pszMessage = "Unsupported geometry type";
                    break;
                case OGRERR_CORRUPT_DATA:
                    pszMessage = "Corrupt data";
                    break;
                default:
                    pszMessage = "Unrecognized error";
            }
            CPLError(CE_Failure, CPLE_AppDefined,
                     "GetNextRawFeature(): %s", pszMessage);
        }

        if( poGeom != NULL )
        {
            if ( GetSpatialRef() )
                poGeom->assignSpatialReference( poSRS );

            poFeature->SetGeometryDirectly( poGeom );
        }
    }

    return poFeature;
}
Beispiel #30
0
 bool Statement::ColumnIsNull(int col) const 
 {
   return sqlite3_column_type(GetStatement(), col) == SQLITE_NULL;
 }