On Fri, Mar 16, 2012 at 6:55 PM, Jeremy Evans <[email protected]> wrote:
> On Friday, March 16, 2012 1:49:43 AM UTC-7, Christian MICHON wrote:
>>
>> This reminded me I can do DB.run and DB.fetch...
>>
>> Let's call the default schema I want to access 'MINE' and the table I
>> want to access 'MYREC' (I do not wish to disclose more from my
>> oracle).
>>
>> What I figured out is:
>> - DB.tables gives []
>> - DB['MINE.MYREC'].count works
>
>
> This only works by accident.
ouch... true
>
>>
>> - DB['MINE.MYREC'].first fails
>> - DB['MINE.MYREC'].columns fails
>
>
> For these, you should be using:
>
> DB.from(:mine__myrec) or DB.from('MINE.MYREC'.lit)
I tried the 1st one with double underscore: works out of the box.
Thanks! Works even with models...
>
>>
>> - DB.schema 'MINE.MYREC' fail
>
> Try:
>
> DB.schema(:mine__myrec)
Works too! Thx
>
>
>> I read that the following SQL in Oracle can be use to avoid prefixing
>> my select queries: 'ALTER SESSION SET CURRENT_SCHEMA ='
>>
>> So I did this:
>> - DB.run("ALTER SESSION SET CURRENT_SCHEMA = MINE")
>> - DB.fetch("select * from MYREC").first
>>
>> and it works well enough for me to be able to grab the metadata I
>> need. Neat. Dirty, but it works.
>
>
> That only works in simple cases (single-threaded, no disconnects). You want
> to run that SQL in the after_connect proc, but you have to understand that
> the after_connect proc is yielded the connection object, so you need to use
> connection specific code to run that SQL. For the JDBC adapter, you'll need
> something like:
>
> :after_connect=>proc{|conn| conn.createStatement.execute('ALTER SESSION
> SET CURRENT_SCHEMA = MINE')}
Here a bit of difference, as I was missing the createStatement (else
the rest was the same). Copying/pasting your code works out of the
box, as usual ;-)
>
>>
>> Thanks Jeremy. We still have possible issues to fix (:default_schema
>> and :after_connect (passing the alter session command) did not work as
>> expected).
>
>
> OK. After trying the above, please let me know how things work.
done. Very neat.
Muchas gracias.
--
Christian
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.