! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors namespaces odbc.lib db db.tuples db.types db.queries db.tuples.private db.private odbc.ffi ; IN: odbc TUPLE: odbc-db env dsn ; : ( dsn -- odbc-db ) odbc-db swap >>dsn odbc-init >>env ; ( handle -- db-connection ) odbc-db-connection new-db-connection swap >>handle ; PRIVATE> M: odbc-db db-open ( db -- db-connection ) [ env>> ] [ dsn>> ] bi odbc-connect ; M: odbc-db-connection db-close ( handle -- ) odbc-disconnect ; TUPLE: odbc-statement < statement ; TUPLE: odbc-result-set < result-set has-more? ; M: odbc-db-connection ( str in out -- obj ) ; M: odbc-db-connection ( str in out -- obj ) odbc-statement new-statement ; ! M: odbc-statement dispose ( statement -- ) odbc-free-statement ; ! M: odbc-result-set dispose ( result-set -- ) f >>handle drop ; : odbc-query-with-columns ( string dsn -- results ) V{ } clone columns set odbc-init swap odbc-connect [ swap odbc-prepare dup odbc-execute dup odbc-get-all-columns swap odbc-free-statement ] keep odbc-disconnect ; : odbc-query ( string dsn -- result ) odbc-init swap odbc-connect [ swap odbc-prepare dup odbc-execute dup odbc-get-all-rows swap odbc-free-statement ] keep odbc-disconnect ;