7 Replies Latest reply: Nov 26, 2007 8:03 PM by 586655 RSS

    Date of 19-SEP-07 is coming up as 0007/09/19 in rails

    598967
      In my table i have a field:
      SCHEDULED_DATE of type DATE.

      When I do a query model = MyModel.find(1)
      model.scheduled_date_before_type_case ends up being equal to
      '0007-09-19' instead of '2007-09-19'.

      In the oracle adapter I ran a debug accross all the fields and got, just
      after it does the query and gets the results.
      - 0001017408770802
      - 0001017408
      - "770802"
      - !ruby/object:OraDate 0007/09/19 00:00:00
      - !ruby/object:OraDate 0007/09/19 00:00:00
      - N
      - !ruby/object:OraDate 0007/09/19 00:00:00
      - RM


      Any ideas?
        • 1. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
          589551
          Hi, Zyclops

          I test retrieving date from a db Date field on my Rails application with Oracle 10g XE, it works well without any problem. Could you give more information about your environment? That should include db version, ruby-oci8 version and so on.

          And another thing you have to know is that, the sequence used by Oracle adapter to generate "ID" starts from number "10000" by default. So in most case, you can't directly use MyModel.find(1) to find the first record in the database table, unless you are quite sure that there is row with ID "1". Please check your db table, find an existed row's ID number, and try using that number to find the record again.
          • 2. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
            598967
            LimLian.. thankyou for the reply.

            My Oracle Version:
            Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
            PL/SQL Release 10.2.0.3.0 - Production
            CORE     10.2.0.3.0     Production
            TNS for Linux: Version 10.2.0.3.0 - Production
            NLSRTL Version 10.2.0.3.0 - Production

            Sorry, the .find(1) was just an example.

            The query generated was:
            SELECT * FROM project_milestones WHERE (project_milestones.id = '0001017408770802')

            The result .yaml was:
            --- !ruby/object:ProjectMilestone
            attributes:
            completion_status_code: N
            final_submission_date: 0007-09-19
            scheduled_date: 0007-09-19
            data_source: RM
            id: 0001017408770802
            completion_date: 0007-09-19
            rm_project_id: 0001017408
            milestone_code: "770802"

            The only oci8 version I could find was from a class in /site_ruby/1.8/oci8.rb ..

            class OCI8
            VERSION = '1.0.0-rc3'
            CLIENT_VERSION = '1020'
            • 3. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
              598967
              Also from irb:
              irb(main:040:0>bla = OCI8.new('username', 'password', 'database')
              irb(main):041:0>bla.exec('select * from project_milestones where rown
              um < 11') do |r| puts r.join(','); end


              0001017793NRP-ENVIR,0001017793,NRP-ENVIR,0007/09/19 00:00:00,0007/09/19 00:00:00
              ,N,0007/09/19 00:00:00,RM

              0001016321NRP-GDHLTH,0001016321,NRP-GDHLTH,0007/09/19 00:00:00,0007/09/19 00:00:
              00,N,0007/09/19 00:00:00,RM
              • 4. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
                589551
                Hi, Zycolps

                What's the result if you use sqlplus to do the query? If the result is correct, there should be nothing wrong with your database. Then you have to report your problem on ruby-oci8's project website,http://rubyforge.org/projects/ruby-oci8/. Or you can contact ruby-oci8's author KUBO directly.

                Good Luck!

                Message was edited by:
                LimLian
                • 5. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
                  598967
                  Cheers... i'll put up a post in OCI8 :)
                  • 6. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
                    dvohra21
                    Non default date format may be defined.
                    http://wiki.rubyonrails.org/rails/pages/HowToDefineYourOwnDateFormat
                    • 7. Re: Date of 19-SEP-07 is coming up as 0007/09/19 in rails
                      586655
                      Please refer the answer to this problem by Kubo
                      http://rubyforge.org/forum/forum.php?thread_id=17768&forum_id=1078