* squile patches
@ 2004-08-02 8:37 Ken Restivo
2004-08-08 9:44 ` Dave Lambert
0 siblings, 1 reply; 2+ messages in thread
From: Ken Restivo @ 2004-08-02 8:37 UTC (permalink / raw)
[-- Attachment #1.1.1: Type: text/plain, Size: 564 bytes --]
I have been using squile for scripting a few MySQL database maintenance operations.
I've made two patches to squile: to use 4-digit Y2K years, and to accept a portnumber argument in mysql mode, for connections to servers on non-default ports.
The patches are attached and also at http://www.restivo.org/projects/squile/
squile looks like it's been unmaintained since 1998(!). I have no idea if anyone else is using it these days. Oh well, it works great for me.
-ken
--
---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
[-- Attachment #1.1.2: squile-date-1900.patch --]
[-- Type: text/plain, Size: 2002 bytes --]
Index: sql_imp.c
===================================================================
RCS file: /mnt/kens/cvsroot/kens/scheme/squile/sql_imp.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -B -w -p -r1.1 -r1.2
--- sql_imp.c 3 Jan 2004 02:36:23 -0000 1.1
+++ sql_imp.c 5 Jan 2004 01:38:56 -0000 1.2
@@ -218,7 +218,7 @@ SCM gh_sql_mysql_sql2scm(MYSQL_RES *res,
* structure and then make list
* representations of the times in scm */
strptime(row[pos], "%Y-%m-%d", &time);
- return gh_sql_time_list(time.tm_year, time.tm_mon + 1, time.tm_mday,
+ return gh_sql_time_list(time.tm_year + 1900, time.tm_mon + 1, time.tm_mday,
-1, -1, -1);
break;
case (FIELD_TYPE_TIME):
@@ -228,7 +228,7 @@ SCM gh_sql_mysql_sql2scm(MYSQL_RES *res,
break;
case (FIELD_TYPE_DATETIME):
strptime(row[pos], "%Y-%m-%d %T", &time);
- return gh_sql_time_list(time.tm_year, time.tm_mon + 1, time.tm_mday,
+ return gh_sql_time_list(time.tm_year + 1900, time.tm_mon + 1, time.tm_mday,
time.tm_hour, time.tm_min, time.tm_sec);
break;
case (FIELD_TYPE_TIMESTAMP):
@@ -238,7 +238,7 @@ SCM gh_sql_mysql_sql2scm(MYSQL_RES *res,
snprintf(buf, 32, "%.4s-%.2s-%.2s %.2s:%.2s:%.2s", s, s + 4, s + 6,
s + 8, s + 10, s + 12);
strptime(buf, "%Y-%m-%d %T", &time);
- return gh_sql_time_list(time.tm_year, time.tm_mon + 1, time.tm_mday,
+ return gh_sql_time_list(time.tm_year + 1900, time.tm_mon + 1, time.tm_mday,
time.tm_hour, time.tm_min, time.tm_sec);
break;
default:
@@ -285,7 +285,7 @@ SCM gh_sql_msql_sql2scm(m_result *res, c
* representations of the times in scm */
if (strlen(row[pos])) {
strptime(row[pos], "%d-%b-%Y", &time);
- return gh_sql_time_list(time.tm_year, time.tm_mon + 1, time.tm_mday,
+ return gh_sql_time_list(time.tm_year + 1900, time.tm_mon + 1, time.tm_mday,
-1, -1, -1);
} else
return gh_sql_time_list(-1, -1, -1, -1, -1, -1);
[-- Attachment #1.1.3: squile-mysql-portnumber.patch --]
[-- Type: text/plain, Size: 5972 bytes --]
Index: sql.c
===================================================================
RCS file: /mnt/kens/cvsroot/kens/scheme/squile/sql.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -B -w -p -r1.1 -r1.2
--- sql.c 3 Jan 2004 02:36:21 -0000 1.1
+++ sql.c 2 Aug 2004 06:14:02 -0000 1.2
@@ -81,11 +81,11 @@ int gh_sql_realloc_dbs(int old_size, int
}
int gh_sql_init_db(void *db, char *db_name, char *host_name,
- char *user_name, char *pass) {
+ char *user_name, char *pass, char *port) {
char buf[GH_SQL_BUF_LEN];
- if (!(gh_sql_imp_connect(db, host_name, user_name, pass))) {
+ if (!(gh_sql_imp_connect(db, db_name, host_name, user_name, pass, port))) {
snprintf(buf, GH_SQL_BUF_LEN, "gh_sql_init: Unable to connect to "
"server: %s \n", gh_sql_imp_error(db));
gh_sql_error(buf);
@@ -107,7 +107,7 @@ int gh_sql_init_db(void *db, char *db_na
#define GH_DB_GROW 2
SCM gh_sql_create(char *db_name, char *host_name, char *user_name,
- char *pass) {
+ char *pass, char *port) {
int i;
@@ -144,7 +144,7 @@ SCM gh_sql_create(char *db_name, char *h
/* initialize the mutex */
if (!gh_sql_init_db(gh_sql_dbs[i], db_name,
- host_name, user_name, pass)) {
+ host_name, user_name, pass, port)) {
free(gh_sql_dbs[i]);
gh_sql_dbs[i] = NULL;
return SCM_BOOL_F;
@@ -170,9 +170,9 @@ char *gh_sql_create_param(SCM arg) {
/* gh_sql_create_prim returns the index of a newly allocated and
initalized mutex from the mutex table. */
SCM gh_sql_create_prim (SCM scm_db_name, SCM scm_host_name,
- SCM scm_user_name, SCM scm_pass) {
+ SCM scm_user_name, SCM scm_pass, SCM scm_port) {
- char *db_name, *host_name = NULL, *user_name = NULL, *pass = NULL;
+ char *db_name, *host_name = NULL, *user_name = NULL, *pass = NULL, *port = NULL;
SCM ret;
if (scm_host_name != SCM_UNDEFINED) {
@@ -181,13 +181,16 @@ SCM gh_sql_create_prim (SCM scm_db_name,
user_name = gh_sql_create_param(scm_user_name);
if (scm_pass != SCM_UNDEFINED) {
pass = gh_sql_create_param(scm_pass);
+ if (scm_port != SCM_UNDEFINED) {
+ port = gh_sql_create_param(scm_port);
+ }
}
}
}
if (gh_string_p(scm_db_name)) {
db_name = gh_scm2newstr(scm_db_name, NULL);
- ret = gh_sql_create(db_name, host_name, user_name, pass);
+ ret = gh_sql_create(db_name, host_name, user_name, pass, port);
free(db_name);
} else {
gh_sql_error("gh_sql_create_prim: Argument to db-create is not a "
@@ -201,6 +204,8 @@ SCM gh_sql_create_prim (SCM scm_db_name,
free(user_name);
if (pass)
free(pass);
+ if (port)
+ free(port);
return ret;
}
@@ -258,7 +263,7 @@ SCM gh_sql_destroy_prim (SCM arg) {
/* begin sql-query section */
-/* send a query to the sql engine and return a scm list in the
+/* send a query to the sql engine and return a scm vector in the
* following format: [[field1 field2 ...] [data1 data2 ...] ... ]
*
* If there is an error, return NULL. If the resultset is empty, the
Index: sql.h
===================================================================
RCS file: /mnt/kens/cvsroot/kens/scheme/squile/sql.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -B -w -p -r1.1 -r1.2
--- sql.h 3 Jan 2004 02:36:22 -0000 1.1
+++ sql.h 2 Aug 2004 06:14:03 -0000 1.2
@@ -27,7 +27,7 @@ SCM gh_sql_query_prim(SCM db_id, SCM que
/* create a database */
SCM gh_sql_create_prim(SCM db_name, SCM host_name, SCM user_name,
- SCM passwd);
+ SCM pass, SCM port);
/* destroy a database */
SCM gh_sql_destroy_prim(SCM db_id);
Index: sql_imp.c
===================================================================
RCS file: /mnt/kens/cvsroot/kens/scheme/squile/sql_imp.c,v
retrieving revision 1.3
retrieving revision 1.5
diff -u -b -B -w -p -r1.3 -r1.5
--- sql_imp.c 21 Mar 2004 16:35:50 -0000 1.3
+++ sql_imp.c 2 Aug 2004 06:19:19 -0000 1.5
@@ -38,13 +38,17 @@
int gh_sql_msql_affected_rows;
#endif
-int gh_sql_imp_connect(void *db, char *host, char *name, char *pass) {
+int gh_sql_imp_connect(void *dbh, char *dbname, char *host, char *user, char *pass, char *port) {
#ifdef GH_SQL_MYSQL
- return (int)mysql_connect((MYSQL *)db, host, name, pass);
+ int realport = port ? atoi(port) : 0;
+
+ mysql_init((MYSQL *)dbh);
+ return (int)mysql_real_connect((MYSQL *)dbh, host, user, pass,
+ dbname, realport, NULL, 0);
#elif defined GH_SQL_MSQL
- *((int *)db) = msqlConnect(host);
- return (*((int *)db) >= 0);
+ *((int *)dbh) = msqlConnect(host);
+ return (*((int *)dbh) >= 0);
#endif
}
Index: sql_imp.h
===================================================================
RCS file: /mnt/kens/cvsroot/kens/scheme/squile/sql_imp.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -B -w -p -r1.1 -r1.2
--- sql_imp.h 3 Jan 2004 02:36:24 -0000 1.1
+++ sql_imp.h 2 Aug 2004 06:14:05 -0000 1.2
@@ -26,8 +26,8 @@
#include <guile/gh.h>
-int gh_sql_imp_connect(void *db, char *host_name, char *user_name,
- char *pass);
+int gh_sql_imp_connect(void *db, char *dbname, char *host, char *user,
+ char *pass, char *port);
int gh_sql_imp_select_db(void *db, char *db_name);
char *gh_sql_imp_error(void *db);
void gh_sql_imp_close(void *db);
Index: squile.c
===================================================================
RCS file: /mnt/kens/cvsroot/kens/scheme/squile/squile.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -B -w -p -r1.1 -r1.2
--- squile.c 3 Jan 2004 02:36:25 -0000 1.1
+++ squile.c 2 Aug 2004 06:14:06 -0000 1.2
@@ -34,7 +34,7 @@ inner_main (void *closure, int argc, cha
{
gh_new_procedure("sql-query", gh_sql_query_prim, 2, 0, 0);
- gh_new_procedure("sql-create", gh_sql_create_prim, 1, 3, 0);
+ gh_new_procedure("sql-create", gh_sql_create_prim, 1, 4, 0);
gh_new_procedure("sql-destroy", gh_sql_destroy_prim, 1, 0, 0);
/* module initializations would go here */
[-- Attachment #1.2: Type: application/pgp-signature, Size: 232 bytes --]
[-- Attachment #2: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: squile patches
2004-08-02 8:37 squile patches Ken Restivo
@ 2004-08-08 9:44 ` Dave Lambert
0 siblings, 0 replies; 2+ messages in thread
From: Dave Lambert @ 2004-08-08 9:44 UTC (permalink / raw)
Cc: guile-user
> squile looks like it's been unmaintained since 1998(!). I have no idea if
> anyone else is using it these days. Oh well, it works great for me.
Ahem. It's been _poorly_ maintained by myself for a few years now. I now have
no personal need for Squile, and I've been busy enough that finding time to
work on it is tricky, but I have received enough patches from users that I'm
compelled to re-start work on it.
The current (if you consider two years old "current") version is available from
http://guile-simplesql.sourceforge.net/.
Thanks for you interest,
Dave
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-08-08 9:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-02 8:37 squile patches Ken Restivo
2004-08-08 9:44 ` Dave Lambert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).