4 #include <stringitem.h>
7 static char buf[2][100];
13 sprintf( buf[i], "\"%s\"", (char*)t );
19 void prtuple(char *pre, Tuple *t) {
21 fprintf( stderr, "%s<%s, %s>\n", pre,
22 val(t->elements[0]), val(t->elements[1]) );
24 // fprintf( stderr, "%s< >\n", pre );
28 void prdropout(const VectorIndex index,const void *t) {
29 prtuple( ".. ", (Tuple*)t );
32 void add_Relation(Relation *r,char *p,char *c) {
33 Tuple *t = Tuple_create( 2, p, c);
34 prtuple( "Adding: ", t );
35 Vector *dropped = Relation_add( r, t );
37 fprintf( stderr, "Knockout %ld tuples\n", dropped->size );
38 Vector_dump( dropped, prdropout );
39 Vector_resize( dropped, 0, 0, 0 );
53 int main(int argc,char **argv) {
54 Relation *rltn2 = Relation_create(
56 2, Tuple_create( 2, (void*) &stringitem, (void*) &stringitem ) ) );
57 Relation_add_constraint( rltn2, 0, 1 );
58 add_Relation( rltn2, "benton", "holly" );
59 add_Relation( rltn2, "benton", "molly");
60 add_Relation( rltn2, "gully", "holly");
61 add_Relation( rltn2, "gully", "vanitha");
62 VectorIndex index = 0;
63 Tuple2 q1 = (Tuple2) { .cols = { 0, "benton", 0 }};
65 prtuple( "Simple query: ", &q1.tup );
66 for ( ; index < rltn2->content.table.size; index++ ) {
67 t = Relation_next( rltn2, &index, &q1.tup );
71 fprintf( stderr, "Null query: (null)\n" );
72 for ( index = 0 ; index < rltn2->content.table.size; index++ ) {
73 t = Relation_next( rltn2, &index, 0 );
77 q1 = (Tuple2) { .cols = { 0, 0, 0 }};
78 prtuple( "Generic query: ", &q1.tup );
79 for ( index = 0 ; index < rltn2->content.table.size; index++ ) {
80 t = Relation_next( rltn2, &index, &q1.tup );
84 q1 = (Tuple2) { .cols = { 0, "gully", 0 }};
85 prtuple( "Deletion query: ", &q1.tup );
86 Vector *deleted = Relation_delete( rltn2, &q1.tup );
87 for ( index = 0 ; index < rltn2->content.table.size; index++ ) {
88 t = Relation_next( rltn2, &index, 0 );
91 for ( index = 0 ; index < deleted->size; index++ ) {
92 Tuple **p = (Tuple**) Vector_next_used( deleted, &index );
93 prtuple( "** ", p? *p : 0 );