Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:25:33+00:00 2026-06-07T00:25:33+00:00

Here is the scenario. I’m writing my geo-ruby oracle adapter for Ruby On Rails

  • 0

Here is the scenario.
I’m writing my geo-ruby oracle adapter for Ruby On Rails which supports working with SDO_GEOMETRY out of box.
It was going well. I wrote codes for selecting SDO_GEOMETRY objects from Oracle DB successfully.
Everything ruins up when I wanted to write insert and update parts.
Following is what’s in my mind. I want to be able to do this statement:

g = GeoShape.new(name:"point1", shape: Point.from_x_y(-34,-43,4326))
g.save

I generated following sql query from the above statements:

INSERT INTO "GEO_SHAPES" ("CREATED_AT", "ID", "NAME", "SHAPE", "UPDATED_AT") VALUES (:a1, :a2, :a3, :a4, :a5)  [["created_at", Tue, 03 Jul 2012 08:42:01 UTC +00:00], ["id", 10112], ["name", "point1"], ["shape", "SDO_GEOMETRY(2001,  NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1,1), SDO_ORDINATE_ARRAY(-34,-43))"], ["updated_at", Tue, 03 Jul 2012 08:42:01 UTC +00:00]]

But execution of above query gave me this error:

ActiveRecord::StatementInvalid: OCIError: ORA-00932: inconsistent datatypes: expected MDSYS.SDO_GEOMETRY got CHAR

I got into oracle_enhanced_adapter to trace the problem. I tried to monkey patch it and manually initialize binds[3][1] (which is the value of sdo_geometry column in my DB) as follows:

    def exec_insert(sql, name, binds)
    log(sql, name, binds) do
      returning_id_index = nil
      cursor = if @statements.key?(sql)
        @statements[sql]
      else
        @statements[sql] = @connection.prepare(sql)
      end

    binds[3][1] = "SDO_GEOMETRY(2001,  NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1,1), SDO_ORDINATE_ARRAY(-34,-43))" ### DAVE

      binds.each_with_index do |bind, i|
        col, val = bind
        if col == :returning_id
          returning_id_index = i + 1
          cursor.bind_returning_param(returning_id_index, Integer)
        else
          if val == "SDO_GEOMETRY(2001,  NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1,1), SDO_ORDINATE_ARRAY(-34,-43))" ### DAVE
            cursor.bind_param(i + 1, val, OCI8::Object::Mdsys::SdoGeometry) ###DAVE
          else ### DAVE
            cursor.bind_param(i + 1, type_cast(val, col), col && col.type)
          end
        end
      end

      cursor.exec_update

Unfortunately, it didn’t help. I still got the same error ORA-00932.
Any ideas? It’s so critical for me to fix this.

P.S: ###DAVE parts are my monkey patches of oracle_enhanced_adapter.rb
P.S: Here is my config.

  • Oracle 11.2
  • Ruby version 1.9.3 (i386-darwin11.3.0)
  • Rails version 3.2.5
  • Active Record version 3.2.5
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:25:33+00:00Added an answer on June 7, 2026 at 12:25 am

    Finally, I managed to fix the problem.
    Enhanced adapter uses bind_param method to perform binding variables to their appropriate oracle types. Here was the problem and error.
    I had to override some codes in oracle_enhanced_adpter.rb.
    I add a method to this file to manually build a SDO_GEOMETRY object.
    Then I bind this returned object to OCI8::Object::Mdsys::SdoGeometry type.

    My method contains these codes (Now, only for creating SDO_GEOMETRY Points):

    #I needed a connection to my oracle database. Connection placeholder is conn.
    def create_sdo_geometry_object(conn, gtype, srid, point, x, y)
        local_cursor = conn.parse("BEGIN :geom := SDO_GEOMETRY(:sdo_gtype, :sdo_srid, :sdo_point, :sdo_elem_info_array, :sdo_ordinate_array); END;")
        local_cursor.bind_param(:sdo_gtype, OraNumber)
        local_cursor.bind_param(:sdo_srid, OraNumber) 
        local_cursor.bind_param(:sdo_point, OCI8::Object::Mdsys::SdoPointType) 
        local_cursor.bind_param(:sdo_elem_info_array, OCI8::Object::Mdsys::SdoElemInfoArray)
        local_cursor.bind_param(:sdo_ordinate_array, OCI8::Object::Mdsys::SdoOrdinateArray)
    
        local_cursor.bind_param(:geom, OCI8::Object::Mdsys::SdoGeometry)
    
        sdo_gtype = OraNumber.new(gtype)
        sdo_srid = OraNumber.new(srid)
        sdo_point = nil #Temporarily I set it to nil
    
    
        #sdo_elem_info_array must be [1,1,1] for creating points.
        sdo_elem_info_array = OCI8::Object::Mdsys::SdoElemInfoArray.new(conn,OraNumber.new(1),OraNumber.new(1),OraNumber.new(1))
        #I want to create a point with x and y coordinates
        sdo_ordinate_array = OCI8::Object::Mdsys::SdoOrdinateArray.new(conn,OraNumber.new(x),OraNumber.new(y))
    
        local_cursor[:sdo_gtype] = sdo_gtype
        local_cursor[:sdo_srid] = sdo_srid
        local_cursor[:sdo_point] = sdo_point
        local_cursor[:sdo_elem_info_array] = sdo_elem_info_array
        local_cursor[:sdo_ordinate_array] = sdo_ordinate_array
        local_cursor.exec
    
        local_cursor[:geom]
    end
    

    Then when I wanted to bind this parameter I used the following code:

    cursor.bind_param(i + 1, create_sdo_geometry_object("PARAMS HERE"), OCI8::Object::Mdsys::SdoGeometry)
    

    It worked like a charm!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the scenario I anticipate: I have an app written in PHP which has
I am facing a scenario here. I have a main class which initializes a
Class person{ int name; }; I have a scenario here in which i'm parsing
Here is the scenario: In my working directory, I have a number of files
Tackling a strange scenario here. We use a proprietary workstation management application which uses
I had a simple working (ASP.NET) Scenario here: 3 asp:RadioButtons that each have OnCheckedChanged
Here is my scenario. Working with Bing Map control(MVVM): <m:Map x:Name=MainMap ZoomLevel={Binding MapZoomLevel, Mode=TwoWay}
Ok, I have a complicated scenario here. I have a scrollview which scrolls horizontally
Here is the scenario: I'm writing an app that will watch for any changes
Here the scenario : A method is called each minute by a timer. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.