Merge git://factorcode.org/git/erg
commit
a4209c2804
|
@ -10,7 +10,6 @@ C: <db> db ( handle -- obj )
|
||||||
! HOOK: db-create db ( str -- )
|
! HOOK: db-create db ( str -- )
|
||||||
! HOOK: db-drop db ( str -- )
|
! HOOK: db-drop db ( str -- )
|
||||||
GENERIC: db-open ( db -- )
|
GENERIC: db-open ( db -- )
|
||||||
GENERIC: db-close ( db -- )
|
|
||||||
|
|
||||||
TUPLE: statement sql params handle bound? ;
|
TUPLE: statement sql params handle bound? ;
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,18 @@
|
||||||
! See http://factorcode.org/license.txt
|
! Copyright (C) 2007 Berlin Brown, 2008 Doug Coleman.
|
||||||
! Copyright (C) 2007 Berlin Brown
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
! Date: 1/17/2007
|
|
||||||
!
|
|
||||||
! libs/mysql/libmysql.factor
|
|
||||||
!
|
|
||||||
! Adapted from mysql.h and mysql.c
|
! Adapted from mysql.h and mysql.c
|
||||||
! Tested with MySQL version - 5.0.24a
|
! Tested with MySQL version - 5.0.24a
|
||||||
|
USING: alien alien.syntax combinators kernel system ;
|
||||||
|
IN: db.mysql.ffi
|
||||||
|
|
||||||
IN: mysql
|
<< "mysql" {
|
||||||
USING: alien kernel ;
|
|
||||||
|
|
||||||
"mysql" {
|
|
||||||
{ [ win32? ] [ "libmySQL.dll" "stdcall" ] }
|
{ [ win32? ] [ "libmySQL.dll" "stdcall" ] }
|
||||||
{ [ macosx? ] [ "libmysqlclient.14.dylib" "cdecl" ] }
|
{ [ macosx? ] [ "libmysqlclient.14.dylib" "cdecl" ] }
|
||||||
{ [ unix? ] [ "libmysqlclient.so.14" "cdecl" ] }
|
{ [ unix? ] [ "libmysqlclient.so.14" "cdecl" ] }
|
||||||
} cond add-library
|
} cond add-library >>
|
||||||
|
|
||||||
LIBRARY: mysql
|
LIBRARY: mysql
|
||||||
|
|
||||||
! ===============================================
|
|
||||||
! mysql.c
|
|
||||||
! ===============================================
|
|
||||||
|
|
||||||
FUNCTION: void* mysql_init ( void* mysql ) ;
|
FUNCTION: void* mysql_init ( void* mysql ) ;
|
||||||
FUNCTION: char* mysql_error ( void* mysql ) ;
|
FUNCTION: char* mysql_error ( void* mysql ) ;
|
||||||
FUNCTION: void* mysql_real_connect ( void* mysql, char* host, char* user, char* passwd, char* db, int port, char* unixsocket, long clientflag ) ;
|
FUNCTION: void* mysql_real_connect ( void* mysql, char* host, char* user, char* passwd, char* db, int port, char* unixsocket, long clientflag ) ;
|
||||||
|
@ -32,4 +23,3 @@ FUNCTION: void mysql_free_result ( void* result ) ;
|
||||||
FUNCTION: char** mysql_fetch_row ( void* result ) ;
|
FUNCTION: char** mysql_fetch_row ( void* result ) ;
|
||||||
FUNCTION: int mysql_num_fields ( void* result ) ;
|
FUNCTION: int mysql_num_fields ( void* result ) ;
|
||||||
FUNCTION: ulong mysql_affected_rows ( void* mysql ) ;
|
FUNCTION: ulong mysql_affected_rows ( void* mysql ) ;
|
||||||
|
|
|
@ -1,39 +1,25 @@
|
||||||
|
! Copyright (C) 2007 Berlin Brown, 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for license.
|
! See http://factorcode.org/license.txt for license.
|
||||||
! Copyright (C) 2007 Berlin Brown
|
|
||||||
! Date: 1/17/2007
|
|
||||||
!
|
|
||||||
! libs/mysql/mysql.factor
|
|
||||||
!
|
|
||||||
! Adapted from mysql.h and mysql.c
|
! Adapted from mysql.h and mysql.c
|
||||||
! Tested with MySQL version - 5.0.24a
|
! Tested with MySQL version - 5.0.24a
|
||||||
|
USING: kernel alien io prettyprint sequences
|
||||||
IN: mysql
|
namespaces arrays math db.mysql.ffi system ;
|
||||||
USING: kernel alien errors io prettyprint
|
IN: db.mysql.lib
|
||||||
sequences namespaces arrays math tools generic ;
|
|
||||||
|
|
||||||
SYMBOL: my-conn
|
SYMBOL: my-conn
|
||||||
|
|
||||||
TUPLE: mysql-connection mysqlconn host user password db port handle resulthandle ;
|
TUPLE: mysql-db handle host user password db port ;
|
||||||
|
TUPLE: mysql-statement ;
|
||||||
|
TUPLE: mysql-result-set ;
|
||||||
|
|
||||||
: init-mysql ( -- conn )
|
: new-mysql ( -- conn )
|
||||||
f mysql_init ;
|
f mysql_init ;
|
||||||
|
|
||||||
C: mysql-connection ( host user password db port -- mysql-connection )
|
: mysql-error-string ( mysql-connection -- str )
|
||||||
[ set-mysql-connection-port ] keep
|
mysql-db-handle mysql_error ;
|
||||||
[ set-mysql-connection-db ] keep
|
|
||||||
[ set-mysql-connection-password ] keep
|
|
||||||
[ set-mysql-connection-user ] keep
|
|
||||||
[ set-mysql-connection-host ] keep ;
|
|
||||||
|
|
||||||
: (mysql-error) ( mysql-connection -- str )
|
: mysql-error ( mysql -- )
|
||||||
mysql-connection-mysqlconn mysql_error ;
|
mysql-error-string throw ;
|
||||||
|
|
||||||
: connect-error-msg ( mysql-connection -- s )
|
|
||||||
mysql-connection-mysqlconn mysql_error
|
|
||||||
[
|
|
||||||
"Couldn't connect to mysql database.\n" %
|
|
||||||
"Message: " % %
|
|
||||||
] "" make ;
|
|
||||||
|
|
||||||
: mysql-connect ( mysql-connection -- )
|
: mysql-connect ( mysql-connection -- )
|
||||||
init-mysql swap
|
init-mysql swap
|
||||||
|
@ -91,11 +77,6 @@ C: mysql-connection ( host user password db port -- mysql-connection )
|
||||||
! Public Word Definitions
|
! Public Word Definitions
|
||||||
! =========================================================
|
! =========================================================
|
||||||
|
|
||||||
: mysql-close ( mysql-connection -- )
|
|
||||||
mysql-connection-mysqlconn mysql_close ;
|
|
||||||
|
|
||||||
: mysql-print-table ( seq -- )
|
|
||||||
[ [ write bl ] each "\n" write ] each ;
|
|
||||||
|
|
||||||
: mysql-query ( query -- ret )
|
: mysql-query ( query -- ret )
|
||||||
>r my-conn get r> (mysql-query) drop
|
>r my-conn get r> (mysql-query) drop
|
||||||
|
@ -105,20 +86,9 @@ C: mysql-connection ( host user password db port -- mysql-connection )
|
||||||
mysql-query drop
|
mysql-query drop
|
||||||
my-conn get (mysql-affected-rows) ;
|
my-conn get (mysql-affected-rows) ;
|
||||||
|
|
||||||
: mysql-error ( -- s )
|
|
||||||
#! Get the last mysql error
|
|
||||||
my-conn get (mysql-error) ;
|
|
||||||
|
|
||||||
: mysql-result>seq ( -- seq )
|
|
||||||
V{ } clone (mysql-result>seq) ;
|
|
||||||
|
|
||||||
: with-mysql ( host user password db port quot -- )
|
: with-mysql ( host user password db port quot -- )
|
||||||
[
|
[
|
||||||
>r <mysql-connection> my-conn set
|
>r <mysql-connection> my-conn set
|
||||||
my-conn get mysql-connect drop r>
|
my-conn get mysql-connect drop r>
|
||||||
[ my-conn get mysql-close ] cleanup
|
[ my-conn get mysql-close ] cleanup
|
||||||
] with-scope ; inline
|
] with-scope ; inline
|
||||||
|
|
||||||
: with-mysql-catch ( host user password db port quot -- )
|
|
||||||
[ with-mysql ] catch [ "Caught: " write print ] when* ;
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for license.
|
||||||
|
USING: alien continuations io kernel prettyprint sequences
|
||||||
|
db ;
|
||||||
|
IN: db.mysql
|
||||||
|
|
||||||
|
TUPLE: mysql-db handle host user password db port ;
|
||||||
|
|
||||||
|
M: mysql-db db-open ( mysql-db -- )
|
||||||
|
;
|
||||||
|
|
||||||
|
M: mysql-db dispose ( mysql-db -- )
|
||||||
|
mysql-db-handle mysql_close ;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
USING: io io.files io.launcher kernel namespaces
|
USING: io io.files io.launcher kernel namespaces
|
||||||
prettyprint tools.test db.sqlite db db.sql sequences
|
prettyprint tools.test db.sqlite db sequences
|
||||||
continuations ;
|
continuations ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2005, 2008 Chris Double, Doug Coleman.
|
! Copyright (C) 2005, 2008 Chris Double, Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien arrays assocs classes compiler db db.sql
|
USING: alien arrays assocs classes compiler db
|
||||||
hashtables io.files kernel math math.parser namespaces
|
hashtables io.files kernel math math.parser namespaces
|
||||||
prettyprint sequences strings tuples alien.c-types
|
prettyprint sequences strings tuples alien.c-types
|
||||||
continuations db.sqlite.lib db.sqlite.ffi ;
|
continuations db.sqlite.lib db.sqlite.ffi ;
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
! License: See http://factor.sf.net/license.txt for BSD license.
|
|
||||||
! Berlin Brown
|
|
||||||
! Date: 1/17/2007
|
|
||||||
!
|
|
||||||
! Adapted from mysql.h and mysql.c
|
|
||||||
! Tested with MySQL version - 5.0.24a
|
|
||||||
PROVIDE: libs/mysql
|
|
||||||
{ +files+ {
|
|
||||||
"libmysql.factor"
|
|
||||||
"mysql.factor"
|
|
||||||
} } ;
|
|
|
@ -1,17 +0,0 @@
|
||||||
--
|
|
||||||
-- Create three databases (development / test / production)
|
|
||||||
-- with prefix 'factordb_'
|
|
||||||
create database factordb_development;
|
|
||||||
create database factordb_test;
|
|
||||||
create database factordb_production;
|
|
||||||
|
|
||||||
grant all on factordb_development.* to 'factoruser'@'localhost' identified by 'mysqlfactor';
|
|
||||||
grant all on factordb_test.* to 'factoruser'@'localhost' identified by 'mysqlfactor';
|
|
||||||
grant all on factordb_production.* to 'factoruser'@'localhost' identified by 'mysqlfactor';
|
|
||||||
|
|
||||||
grant all on factordb_development.* to 'factoruser'@'*' identified by 'mysqlfactor';
|
|
||||||
grant all on factordb_test.* to 'factoruser'@'*' identified by 'mysqlfactor';
|
|
||||||
grant all on factordb_production.* to 'factoruser'@'*' identified by 'mysqlfactor';
|
|
||||||
|
|
||||||
-- End of the Script
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
! See http://factorcode.org/license.txt for license.
|
|
||||||
! Simple test for mysql library
|
|
||||||
! libs/mysql/test/mysql-example.factor
|
|
||||||
|
|
||||||
IN: mysql-example
|
|
||||||
REQUIRES: libs/mysql ;
|
|
||||||
USING: sequences mysql modules prettyprint kernel io math tools namespaces test ;
|
|
||||||
|
|
||||||
"Testing..." print nl
|
|
||||||
|
|
||||||
: get-drop-table ( -- s )
|
|
||||||
"DROP TABLE if exists DISCUSSION_FORUM" ;
|
|
||||||
|
|
||||||
: get-insert-table ( -- s )
|
|
||||||
{
|
|
||||||
"INSERT INTO DISCUSSION_FORUM(category, full_name, email, title, main_url, keywords, message) "
|
|
||||||
"VALUES('none', 'John Doe', 'johndoe@test.com', 'The Message', NULL, NULL, 'Testing')"
|
|
||||||
} "" join ;
|
|
||||||
|
|
||||||
: get-update-table ( -- s )
|
|
||||||
"UPDATE DISCUSSION_FORUM set category = 'my-new-category'" ;
|
|
||||||
|
|
||||||
: get-delete-table ( -- s )
|
|
||||||
"DELETE FROM DISCUSSION_FORUM where id = 2" ;
|
|
||||||
|
|
||||||
: get-create-table ( -- s )
|
|
||||||
{
|
|
||||||
"create table DISCUSSION_FORUM("
|
|
||||||
"id int(11) NOT NULL auto_increment,"
|
|
||||||
"category varchar(128),"
|
|
||||||
"full_name varchar(128) NOT NULL,"
|
|
||||||
"email varchar(128) NOT NULL,"
|
|
||||||
"title varchar(255) NOT NULL,"
|
|
||||||
"main_url varchar(255),"
|
|
||||||
"keywords varchar(255),"
|
|
||||||
"message text NOT NULL,"
|
|
||||||
"created_on DATETIME NOT NULL DEFAULT '0000-00-0000:00:00',"
|
|
||||||
"PRIMARY KEY (id));"
|
|
||||||
} "" join ;
|
|
||||||
|
|
||||||
[ "localhost" "factoruser" "mysqlfactor" "factordb_development" 0 [
|
|
||||||
get-drop-table mysql-command drop
|
|
||||||
get-create-table mysql-command drop
|
|
||||||
get-update-table mysql-command drop
|
|
||||||
get-delete-table mysql-command drop
|
|
||||||
|
|
||||||
! Insert multiple records
|
|
||||||
20 [
|
|
||||||
get-insert-table mysql-command 2drop
|
|
||||||
] each
|
|
||||||
|
|
||||||
"select * from discussion_forum order by created_on" mysql-query drop
|
|
||||||
mysql-result>seq mysql-print-table
|
|
||||||
|
|
||||||
] with-mysql ] time
|
|
||||||
|
|
||||||
"Done" print
|
|
Loading…
Reference in New Issue