Paste: odbc main

Author: Jim Mack
Mode: factor
Date: Wed, 10 Mar 2010 16:10:24
Plain Text |
! 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 ;
: <odbc-db> ( dsn -- odbc-db )
    odbc-db swap >>dsn odbc-init >>env ;

<PRIVATE
TUPLE: odbc-db-connection < db-connection ;

: <odbc-db-connection> ( 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 <odbc-db-connection> ;

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 <simple-statement> ( str in out -- obj ) <prepared-statement> ;

M: odbc-db-connection <prepared-statement> ( 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 ;

New Annotation

Summary:
Author:
Mode:
Body: