Update of /cvsroot/pure-data/externals/hcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv916
Modified Files: sql_query.c sql_query-help.pd Log Message: parses ? placeholders and generates inlets; crashes when you try to do just about anything
Index: sql_query-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/sql_query-help.pd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sql_query-help.pd 22 Dec 2007 02:53:43 -0000 1.1 --- sql_query-help.pd 22 Dec 2007 07:24:36 -0000 1.2 *************** *** 1,4 **** ! #N canvas 403 84 613 618 10; ! #X obj 118 105 sql_query this is a test? more ?; #X obj 362 244 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144 -1 -1 0 1; --- 1,3 ---- ! #N canvas 238 82 613 618 10; #X obj 362 244 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144 -1 -1 0 1; *************** *** 25,34 **** #X obj 119 322 sql_query insert into table (name , age) values (? , ?); ! #X connect 4 0 5 0; ! #X connect 4 1 6 0; ! #X connect 4 1 7 0; ! #X connect 9 0 12 0; ! #X connect 10 0 12 0; ! #X connect 11 0 12 0; ! #X connect 12 0 4 0; ! #X connect 12 1 4 1; --- 24,38 ---- #X obj 119 322 sql_query insert into table (name , age) values (? , ?); ! #X obj 118 105 sql_query this is a test? more ? ? ? ?; ! #X msg 39 235 bang; ! #X connect 0 0 11 1; ! #X connect 1 0 11 1; ! #X connect 3 0 4 0; ! #X connect 3 1 5 0; ! #X connect 3 1 6 0; ! #X connect 8 0 11 0; ! #X connect 9 0 11 0; ! #X connect 10 0 11 0; ! #X connect 11 0 3 0; ! #X connect 11 1 3 1; ! #X connect 13 0 11 0;
Index: sql_query.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/sql_query.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sql_query.c 22 Dec 2007 02:53:43 -0000 1.1 --- sql_query.c 22 Dec 2007 07:24:36 -0000 1.2 *************** *** 45,48 **** --- 45,57 ---- static t_class *sql_query_class;
+ static t_class *proxy_inlet_class; + + typedef struct _proxy_inlet + { + t_pd pd; + void *owner; + unsigned int id; + } t_proxy_inlet; + typedef struct _sql_query { *************** *** 51,55 **** t_binbuf* x_query_binbuf;
! int inlet_count;
t_outlet* x_data_outlet; --- 60,66 ---- t_binbuf* x_query_binbuf;
! unsigned int placeholder_count; ! struct _proxy_inlet*inlets; ! t_atom** atoms;
t_outlet* x_data_outlet; *************** *** 58,86 ****
/*------------------------------------------------------------------------------ * PROXY INLET FUNCTIONS */ - static t_class *proxy_inlet_class = NULL;
! typedef struct _proxy_inlet ! { ! t_pd pd; ! void *owner; ! unsigned int id; ! } t_proxy_inlet; ! ! static void proxy_inlet_new(t_proxy_inlet *p, void *owner, unsigned int id) { p->pd = proxy_inlet_class; p->owner = owner; p->id = id; }
! static void proxy_inlet_anything(t_proxy_inlet *x, t_symbol *s, int argc, t_atom *argv) { ! int i; ! char buf[MAXPDSTRING]; ! post("proxy_inlet_anything: %s", s -> s_name); }
--- 69,93 ----
+ /*------------------------------------------------------------------------------ + * FUNCTION PROTOTYPES + */ + static void sql_query_set_atom(t_sql_query *x, int atom_num, t_symbol *s, t_atom *atom);
/*------------------------------------------------------------------------------ * PROXY INLET FUNCTIONS */
! static void proxy_inlet_new(t_proxy_inlet *p, t_object *owner, unsigned int id) { p->pd = proxy_inlet_class; p->owner = owner; p->id = id; + inlet_new(owner, &p->pd, 0, 0); }
! static void proxy_inlet_anything(t_proxy_inlet *p, t_symbol *s, int argc, t_atom *argv) { ! post("proxy_inlet_anything: %s %d", s->s_name, argc); ! sql_query_set_atom(p->owner, p->id, s, argv); }
*************** *** 102,106 **** */
! static void *sql_query_free(t_sql_query *x) { binbuf_free(x->x_query_binbuf); --- 109,139 ---- */
! static void sql_query_set_atom(t_sql_query *x, int atom_num, t_symbol *s, t_atom *atom) ! { ! char *buf; ! int bufsize; ! if( (&s == &s_symbol) || (&s == &s_list) ) ! { ! atom_string(atom, buf, bufsize); ! } ! else ! { ! atom_string(atom, buf, bufsize); ! } ! post("set atom %s", buf); ! x->atoms[atom_num] = atom; ! } ! ! static void sql_query_anything(t_sql_query *x, t_symbol *s, int argc, t_atom *argv) ! { ! sql_query_set_atom(x, 0, s, argv); ! } ! ! static void sql_query_bang(t_sql_query *x) ! { ! ! } ! ! static void sql_query_free(t_sql_query *x) { binbuf_free(x->x_query_binbuf); *************** *** 110,117 **** { DEBUG(post("sql_query_new");); ! char *buf; int bufsize; char *current = NULL; - unsigned int total_inlets = 0; t_sql_query *x = (t_sql_query *)pd_new(sql_query_class);
--- 143,150 ---- { DEBUG(post("sql_query_new");); ! unsigned int i; int bufsize; + char *buf; char *current = NULL; t_sql_query *x = (t_sql_query *)pd_new(sql_query_class);
*************** *** 121,132 **** buf[bufsize] = 0;
current = strchr(buf, PLACEHOLDER); while (current != NULL) { post("found placeholder %c", PLACEHOLDER); ! total_inlets++; current = strchr(current + 1, PLACEHOLDER); } ! post("creating %d inlets", total_inlets); x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); --- 154,174 ---- buf[bufsize] = 0;
+ x->placeholder_count = 0; current = strchr(buf, PLACEHOLDER); while (current != NULL) { post("found placeholder %c", PLACEHOLDER); ! x->placeholder_count++; current = strchr(current + 1, PLACEHOLDER); } ! post("creating %d inlets", x->placeholder_count); ! x->inlets = getbytes(x->placeholder_count * sizeof(t_proxy_inlet)); ! x->atoms = getbytes(x->placeholder_count * sizeof(t_atom *)); ! for(i=1; i< x->placeholder_count; ++i) ! { ! proxy_inlet_new(&x->inlets[i], (t_object *)x, x->placeholder_count); ! post("\tinlet %d", i); ! } ! x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); *************** *** 140,144 **** sql_query_class = class_new(gensym("sql_query"), (t_newmethod)sql_query_new, ! (t_newmethod)sql_query_free, sizeof(t_sql_query), 0, --- 182,186 ---- sql_query_class = class_new(gensym("sql_query"), (t_newmethod)sql_query_new, ! (t_method)sql_query_free, sizeof(t_sql_query), 0, *************** *** 147,152 ****
/* add inlet datatype methods */ ! // class_addbang(sql_query_class, (t_method) sql_query_bang); ! // class_addanything(sql_query_class, (t_method) sql_query_anything); }
--- 189,194 ----
/* add inlet datatype methods */ ! class_addbang(sql_query_class, (t_method) sql_query_bang); ! class_addanything(sql_query_class, (t_method) sql_query_anything); }