mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-03-10 00:20:54 +08:00
Support "SELECT TOP n [PERCENT]... " queries.
Updated the SQL parser to support "SELECT TOP n [PERCENT]... " queries, matching the Mocrosoft Access SQL language. Export these queries from databases with mdb-queries.
This commit is contained in:
@@ -62,9 +62,11 @@ int main (int argc, char **argv) {
|
||||
|
||||
//variables for the generation of sql
|
||||
char *sql_tables = (char *) malloc(bind_size);
|
||||
char *sql_predicate = (char *) malloc(bind_size);
|
||||
char *sql_columns = (char *) malloc(bind_size);
|
||||
char *sql_where = (char *) malloc(bind_size);
|
||||
char *sql_sorting = (char *) malloc(bind_size);
|
||||
int flagint;
|
||||
|
||||
/* see getopt(3) for more information on getopt and this will become clear */
|
||||
while ((opt=getopt(argc, argv, "L1d:"))!=-1) {
|
||||
@@ -148,8 +150,22 @@ int main (int argc, char **argv) {
|
||||
|
||||
while (mdb_fetch_row(table)) {
|
||||
if(strcmp(query_id,objectid) == 0) {
|
||||
flagint = atoi(flag);
|
||||
//we have a row for our query
|
||||
switch(atoi(attribute)) {
|
||||
case 3: // predicate
|
||||
if (flagint & 0x30) {
|
||||
strcpy(sql_predicate, " TOP ");
|
||||
strcat(sql_predicate, name1);
|
||||
if (flagint & 0x20) {
|
||||
strcat(sql_predicate, " PERCENT");
|
||||
}
|
||||
} else if (flagint & 0x8) {
|
||||
strcpy(sql_predicate, " DISTINCTROW");
|
||||
} else if (flagint & 0x2) {
|
||||
strcpy(sql_predicate, " DISTINCT");
|
||||
}
|
||||
break;
|
||||
case 5: // table name
|
||||
if(strcmp(sql_tables,"") == 0) {
|
||||
strcpy(sql_tables,name1);
|
||||
@@ -193,9 +209,9 @@ int main (int argc, char **argv) {
|
||||
|
||||
/* print out the sql statement */
|
||||
if(strcmp(sql_where,"") == 0) {
|
||||
fprintf(stdout,"SELECT %s FROM %s %s\n",sql_columns,sql_tables,sql_sorting);
|
||||
fprintf(stdout,"SELECT%s %s FROM %s %s\n",sql_predicate,sql_columns,sql_tables,sql_sorting);
|
||||
} else {
|
||||
fprintf(stdout,"SELECT %s FROM %s WHERE %s %s\n",sql_columns,sql_tables,sql_where,sql_sorting);
|
||||
fprintf(stdout,"SELECT%s %s FROM %s WHERE %s %s\n",sql_predicate,sql_columns,sql_tables,sql_where,sql_sorting);
|
||||
}
|
||||
|
||||
mdb_free_tabledef(table);
|
||||
|
||||
Reference in New Issue
Block a user