Rebol odbc

Discussion in 'Rebol' started by YueM, Jan 30, 2010.

  1. YueM

    YueM New Member

    I am using rebol 2.7.7 and trying to use dsn less odbc to try to connect to a microsoft access database, so far I have failed every time to get it working.

    does someone have a working example ? ( I had asked the same question in altme, before I gave up on altme)

    my sample microsoft access db is on my c drive and is called db2.mdb

    thsi is what I tried and failed. it is complaining about `odbc has no value.


    >> con-name: open [
    [ SCHEME: `ODBC
    [ target: join "{DRIVER=Microsoft Access Driver (*.mdb)}; "
    [ "DBQ=C:\db2.mdb; DefaultDir=C:;DriverId=25;FIL=MS Access;"
    [ ]
    ** Script Error: `ODBC has no value
    ** Where: halt-view
    ** Near: SCHEME: `ODBC
    target: join "{DRIVER=Microsoft Access Driver (*.mdb)}; "
    >>


    this sample is taken from the database access.html from rebol.com , still same problem.

    >> connect-name: open [
    [ scheme: `odbc
    [ target: join "{DRIVER=Microsoft Access Driver (*.mdb)}; "
    [ "DBQ=c:\db2.mdb"
    [ ]
    ** Script Error: `odbc has no value
    ** Where: halt-view
    ** Near: scheme: `odbc
    target: join "{DRIVER=Microsoft Access Driver (*.mdb)}; "
    >>
    >>
  2. YueM

    YueM New Member

    forgot one more example I tried, this one using 'odbc rather than `odbc. the "database access" web page on rebol.com uses `odbc.

    >> connect-name: open [
    [ scheme: 'odbc
    [ target: join "{DRIVER=Microsoft Access Driver (*.mdb)}; "
    [ "DBQ=c:\db2.mdb"
    [ ]
    ** Script Error: ODBC error:
    ** Where: halt-view
    ** Near: connect-name: open [
    scheme: 'odbc
    target: join "{DRIVER=Microsoft Access Driver (*.mdb)}; "
    "DBQ=c:\d...
    >>
  3. Graham

    Graham Developer Staff Member

    You have to get the connection string right first.

    From here http://www.connectionstrings.com/access I found this one

    Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;

    So, it should be something like this:

    dbase: open [ scheme: 'odbc target: "driver=Microsoft Access Driver (*.mdb);Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=" ]

    Note that the docs you refer to use the backtick ` but this is incorrect. It's a standard tick ' to indicate that odbc is a Rebol word.
  4. Graham

    Graham Developer Staff Member

  5. YueM

    YueM New Member

    Graham, thanks for the microsoft access dsn less odbc connection details and the link. they are very helpful.
    I thought that we didn't need the uid and pwd , as the example from the rebol web site didn't have it and also is using ` instead of '. Too bad nobody can change the doc on the rebol web site. I am sure this will keep on misleading some other beginners too.

    It's working great now. I hope this thread will help other beginners as well.

    I haven't used firebird, is it good ? some people wrote, it gets corrupted sometimes. at work we use Ms sql server, db2 and a little bit of access
  6. Graham

    Graham Developer Staff Member

    I don't know if username and password are required ... I didn't have an access table to test the string on.

    Firebird ... yes, pretty robust. Very little maintenance required.
  7. Jason

    Jason Developer / Handyman Staff Member

    3-4 years of Firebird from me, no problems.
  8. YueM

    YueM New Member

    Graham/Jason

    the Firebird site seems to suggest that Firebird has stored procedures .

    how do you call a stored procedure which has parameters in rebol ? and also how do you call one which doesn't have parameters?
  9. Graham

    Graham Developer Staff Member

    The essential thing to understand is that REBOL doesn't understand SQL. All it does is take your string and replace ? with a parameter from a list of supplied parameters.

    So, if you want to send any string to the sql port, it's like this

    dbase: open odbc://system-dsn-name-as-defined-somewhere
    db-port: first dbase

    var1: 1 var2: 2
    insert db-port [ {this is an expression and this is a (?) variable as is this (?) } var1 var2 ]

    which constructs this string

    insert db-port {this is an expression and this is a 1 variable as is this 2}
  10. YueM

    YueM New Member

    if my stored procedure is called SP1 and I have 2 parameters p1, p2.

    what would be the syntax to use to call the stored procedure SP1 and pass it the 2 parameters p1, p2 ?
  11. Graham

    Graham Developer Staff Member

    What is the sql syntax ?
  12. YueM

    YueM New Member

    Hi Graham,

    I don't know the sql syntax in Rebol. I suppose every language has its own way of calling a stored procedure.

    for example java hias its own way of calling stored procedure, and it is different from how you call a stored procedure in c#. I can give you an example how to call a stored procedure in java, but it won't be of any use here in rebol.

    I hope someone else has done some experiments with calling stored procedure in Rebol, and can help.
  13. Graham

    Graham Developer Staff Member

    My point was that REBOL doesn't have a sql syntax ... it just uses (?) to replace variables to create the string which is then sent to the sql db.

Share This Page