Paste: MySQL

Author: tgunr
Mode: factor
Date: Tue, 4 Nov 2014 20:48:39
Plain Text |
IN: mysql.ffi

"mysql" "/usr/local/lib/libmysqlclient.dylib"  stdcall add-library

TYPEDEF: void* MYSQL

FUNCTION: int mysql_query ( MYSQL* mysql c-string q ) ;

M: mysql-db-connection <prepared-statement> ( str in out -- obj )
B    mysql-statement new-statement
;

M:: mysql-statement query-results ( query -- result-set )
B    query dup mysql-maybe-prepare
    handle>> mysql-result-set new-result-set
    query-results
    dup advance-row ;

: mysql-maybe-prepare ( statement -- statement )
B    dup handle>> [
        db-connection get handle>>
        >>handle
    ] unless ;

M:: mysql-result-set query-results ( result-set -- result-set )
B    result-set handle>> result-set sql>>
     mysql_query result-set swap >>n
    ;

M: mysql-result-set advance-row ( result-set -- )
B    dup handle>>
    mysql_next_result 0 = >>has-more? drop ;

M: mysql-result-set more-rows? ( result-set -- ? )
B    has-more?>> ;

M: mysql-statement dispose ( statement -- )
B    handle>> drop ;

M: mysql-db-connection db-close ( handle -- )
B    mysql_close ;

New Annotation

Summary:
Author:
Mode:
Body: