Paste: MySQL Connection

Author: tgunr
Mode: factor
Date: Tue, 4 Nov 2014 18:16:35
Plain Text |
USING: accessors combinators db db.mysql.ffi db.mysql.lib
db.private db.queries db.tuples db.tuples.private db.types
destructors interpolate io.streams.string kernel locals math
math.parser mysql.ffi mysql.lib namespaces nmake random
sequences sequences.deep slots.syntax strings ;

IN: db.mysql

TUPLE: mysql-db
    mysqlconn
    { host string initial: "127.0.0.1" }
    { user string initial: "root" }
    { password string }
    { database string initial: "test" }
    { port integer initial: 3306 }
    { unixsocket string }
    { clientflag integer }
    resulthandle ;


: <mysql-db> ( host user password -- mysql-db )
    [ mysql-db new ] 3dip
    set-slots[ password user host ]  
;

: init-with-db ( mysql-db db -- mysql-db )
    >>database ;

TUPLE: mysql-db-connection < db-connection ;

: <mysql-db-connection> ( -- db-connection )
    mysql-db-connection new-db-connection
    f mysql_init >>handle ;

M:: mysql-db db-open  ( db -- db-connection )
    db <mysql-db-connection> [ >>mysqlconn ] keep
    handle>>
    swap slots[ host user password database port unixsocket clientflag ]
    mysql_real_connect
    db swap >>resulthandle
    mysqlconn>>
    ;

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

TUPLE: mysql-statement < statement ;

TUPLE: mysql-result-set < result-set has-more? ;

New Annotation

Summary:
Author:
Mode:
Body: