Now printing the results
This commit is contained in:
parent
0b7c5a32c7
commit
6d72ac856c
|
@ -23,6 +23,15 @@
|
||||||
|
|
||||||
/* client */
|
/* client */
|
||||||
/* private */
|
/* private */
|
||||||
|
/* types */
|
||||||
|
typedef struct _Client
|
||||||
|
{
|
||||||
|
FILE * fp;
|
||||||
|
int first;
|
||||||
|
int rows;
|
||||||
|
} Client;
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _client(char const * engine, char const * cfile,
|
static int _client(char const * engine, char const * cfile,
|
||||||
char const * section);
|
char const * section);
|
||||||
|
@ -32,9 +41,12 @@ static int _usage(void);
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* client */
|
/* client */
|
||||||
|
static int _client_print(void * data, int argc, char ** argv, char ** columns);
|
||||||
|
|
||||||
static int _client(char const * engine, char const * cfile,
|
static int _client(char const * engine, char const * cfile,
|
||||||
char const * section)
|
char const * section)
|
||||||
{
|
{
|
||||||
|
Client client;
|
||||||
Config * config;
|
Config * config;
|
||||||
Database * db;
|
Database * db;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
@ -53,20 +65,44 @@ static int _client(char const * engine, char const * cfile,
|
||||||
config_delete(config);
|
config_delete(config);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
client.fp = stdout;
|
||||||
while(fgets(buf, sizeof(buf), stdin) != NULL)
|
while(fgets(buf, sizeof(buf), stdin) != NULL)
|
||||||
{
|
{
|
||||||
|
client.first = 1;
|
||||||
|
client.rows = 0;
|
||||||
/* XXX it may not have picked a complete line */
|
/* XXX it may not have picked a complete line */
|
||||||
if(database_query(db, buf, NULL, NULL) != 0)
|
if(database_query(db, buf, _client_print, &client) != 0)
|
||||||
{
|
{
|
||||||
error_print("client");
|
error_print("client");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* FIXME implement printing the results */
|
fprintf(client.fp, "(%u rows)\n", client.rows);
|
||||||
}
|
}
|
||||||
database_delete(db);
|
database_delete(db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _client_print(void * data, int argc, char ** argv, char ** columns)
|
||||||
|
{
|
||||||
|
Client * client = data;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
client->rows++;
|
||||||
|
if(argc == 0)
|
||||||
|
return 0;
|
||||||
|
if(client->first != 0)
|
||||||
|
{
|
||||||
|
client->first = 0;
|
||||||
|
for(i = 0; i < argc; i++)
|
||||||
|
fprintf(client->fp, "|%s", columns[i]);
|
||||||
|
fputs("|\n", client->fp);
|
||||||
|
}
|
||||||
|
for(i = 0; i < argc; i++)
|
||||||
|
fprintf(client->fp, "|%s", argv[i]);
|
||||||
|
fputs("|\n", client->fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user