some sample code to mod-mysql.c
added a test script file t/h-001.hawk. there is still a reference handling bug regarding hawk::call()
This commit is contained in:
parent
11fe4e17ad
commit
c7961f84d2
@ -308,6 +308,7 @@ static stmt_node_t* get_stmt_list_node_with_arg (hawk_rtx_t* rtx, sql_list_t* sq
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
/*
|
/*
|
||||||
|
BEGIN {
|
||||||
mysql = mysql::open();
|
mysql = mysql::open();
|
||||||
|
|
||||||
if (mysql::connect(mysql, "localhost", "username", "password", "database") <= -1)
|
if (mysql::connect(mysql, "localhost", "username", "password", "database") <= -1)
|
||||||
@ -315,8 +316,8 @@ static stmt_node_t* get_stmt_list_node_with_arg (hawk_rtx_t* rtx, sql_list_t* sq
|
|||||||
print "connect error -", mysql::errmsg();
|
print "connect error -", mysql::errmsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mysql::escape_string(mysql, "hawk", name);
|
||||||
if (mysql::query(mysql, "select * from mytable") <= -1)
|
if (mysql::query(mysql, sprintf("select * from mytable where name like '%%%s%%'", name)) <= -1)
|
||||||
{
|
{
|
||||||
print "query error -", mysql::errmsg();
|
print "query error -", mysql::errmsg();
|
||||||
}
|
}
|
||||||
@ -337,6 +338,42 @@ static stmt_node_t* get_stmt_list_node_with_arg (hawk_rtx_t* rtx, sql_list_t* sq
|
|||||||
mysql::free_result(result);
|
mysql::free_result(result);
|
||||||
|
|
||||||
mysql::close(mysql);
|
mysql::close(mysql);
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
mysql = mysql::open();
|
||||||
|
|
||||||
|
if (mysql::connect(mysql, "localhost", "username", "password", "database") <= -1)
|
||||||
|
{
|
||||||
|
print "connect error -", mysql::errmsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt = mysql::stmt_init(mysql);
|
||||||
|
if (stmt <= -1)
|
||||||
|
{
|
||||||
|
print "stmt initialization error - ", mysql::errmsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mysql::stmt_prepare(stmt, "select name,id,location from mytable where name like ?") <= -1)
|
||||||
|
{
|
||||||
|
print "stmt preparation error - ", mysql::errmsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
result = mysql::stmt_execute(stmt, "%hawk%");
|
||||||
|
if (result <= -1)
|
||||||
|
{
|
||||||
|
print "statement execution error - ", mysql::errmsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (mysql::stmt_fetch(result, name, id, loc) > 0)
|
||||||
|
{
|
||||||
|
print "name=", name, "id=", id, "location=", loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql::stmt_close (stmt);
|
||||||
|
mysql::close(mysql);
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||||
@ -1303,7 +1340,7 @@ static int fnc_stmt_execute (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
param_count = mysql_stmt_param_count(stmt_node->stmt);
|
param_count = mysql_stmt_param_count(stmt_node->stmt);
|
||||||
if (nparams != param_count)
|
if (nparams != param_count)
|
||||||
{
|
{
|
||||||
set_error_on_sql_list (rtx, sql_list, HAWK_T("invalid number of pramaters"));
|
set_error_on_sql_list (rtx, sql_list, HAWK_T("invalid number of paramaters"));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ AM_CPPFLAGS = \
|
|||||||
AM_LDFLAGS = -L$(abs_builddir)/../lib -L$(libdir)
|
AM_LDFLAGS = -L$(abs_builddir)/../lib -L$(libdir)
|
||||||
LDADD = $(PTHREAD_LIBS)
|
LDADD = $(PTHREAD_LIBS)
|
||||||
|
|
||||||
|
noinst_SCRIPTS = h-001.hawk
|
||||||
|
|
||||||
##bin_PROGRAMS = t-001 t-002 t-003 t-004
|
##bin_PROGRAMS = t-001 t-002 t-003 t-004
|
||||||
bin_PROGRAMS = t-001 t-002 t-005
|
bin_PROGRAMS = t-001 t-002 t-005
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
@SET_MAKE@
|
@SET_MAKE@
|
||||||
|
|
||||||
|
|
||||||
VPATH = @srcdir@
|
VPATH = @srcdir@
|
||||||
am__is_gnu_make = { \
|
am__is_gnu_make = { \
|
||||||
if test -z '$(MAKELEVEL)'; then \
|
if test -z '$(MAKELEVEL)'; then \
|
||||||
@ -122,6 +123,7 @@ t_002_OBJECTS = $(am_t_002_OBJECTS)
|
|||||||
am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||||
am_t_005_OBJECTS = t-005.$(OBJEXT)
|
am_t_005_OBJECTS = t-005.$(OBJEXT)
|
||||||
t_005_OBJECTS = $(am_t_005_OBJECTS)
|
t_005_OBJECTS = $(am_t_005_OBJECTS)
|
||||||
|
SCRIPTS = $(noinst_SCRIPTS)
|
||||||
AM_V_P = $(am__v_P_@AM_V@)
|
AM_V_P = $(am__v_P_@AM_V@)
|
||||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||||
am__v_P_0 = false
|
am__v_P_0 = false
|
||||||
@ -355,6 +357,7 @@ AM_CPPFLAGS = \
|
|||||||
|
|
||||||
AM_LDFLAGS = -L$(abs_builddir)/../lib -L$(libdir)
|
AM_LDFLAGS = -L$(abs_builddir)/../lib -L$(libdir)
|
||||||
LDADD = $(PTHREAD_LIBS)
|
LDADD = $(PTHREAD_LIBS)
|
||||||
|
noinst_SCRIPTS = h-001.hawk
|
||||||
t_001_SOURCES = t-001.c
|
t_001_SOURCES = t-001.c
|
||||||
t_002_SOURCES = t-002.c
|
t_002_SOURCES = t-002.c
|
||||||
t_002_LDADD = -lhawk $(LDADD)
|
t_002_LDADD = -lhawk $(LDADD)
|
||||||
@ -598,7 +601,7 @@ distdir-am: $(DISTFILES)
|
|||||||
done
|
done
|
||||||
check-am: all-am
|
check-am: all-am
|
||||||
check: check-am
|
check: check-am
|
||||||
all-am: Makefile $(PROGRAMS)
|
all-am: Makefile $(PROGRAMS) $(SCRIPTS)
|
||||||
installdirs:
|
installdirs:
|
||||||
for dir in "$(DESTDIR)$(bindir)"; do \
|
for dir in "$(DESTDIR)$(bindir)"; do \
|
||||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||||
|
60
hawk/t/h-001.hawk
Normal file
60
hawk/t/h-001.hawk
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
@pragma entry main
|
||||||
|
|
||||||
|
function ensure (a, b, desc)
|
||||||
|
{
|
||||||
|
if (a != b)
|
||||||
|
{
|
||||||
|
print "FAILURE", desc;
|
||||||
|
exit (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function call_by_ref_1(&a, b, &c)
|
||||||
|
{
|
||||||
|
c = "hello, world";
|
||||||
|
return b * a;
|
||||||
|
}
|
||||||
|
|
||||||
|
function call_by_ref_2(a, &b)
|
||||||
|
{
|
||||||
|
b[1] = b[1] * a;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
function main()
|
||||||
|
{
|
||||||
|
|
||||||
|
x = 20;
|
||||||
|
y = 90;
|
||||||
|
r = call_by_ref_1(x, y, z);
|
||||||
|
ensure (r, 1800);
|
||||||
|
ensure (x, 20);
|
||||||
|
ensure (y, 90);
|
||||||
|
ensure (z, "hello, world");
|
||||||
|
|
||||||
|
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
|
||||||
|
|
||||||
|
{
|
||||||
|
@local b;
|
||||||
|
call_by_ref_2(99, b);
|
||||||
|
ensure (b[1], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
@local b;
|
||||||
|
b[1] = 1;
|
||||||
|
r = call_by_ref_2(99, b);
|
||||||
|
ensure (r, 99);
|
||||||
|
ensure (b[1], 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
@local b;
|
||||||
|
b[1] = 1;
|
||||||
|
r = hawk::call("call_by_ref_2", 99, b);
|
||||||
|
ensure (r, 99);
|
||||||
|
ensure (b[1], 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
print "SUCCESS"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user