New mdb_set_bind_size function overrides MDB_BIND_SIZE

This should fix long-standing complaints about the default bind size
without causing undue memory inflation in existing applications.

Could make this adjustable on the command line later.

Supersedes:

https://github.com/mdbtools/mdbtools/pull/137
This commit is contained in:
Evan Miller
2020-09-02 14:30:07 -04:00
parent b7dd44d0d4
commit fb960553e6
7 changed files with 46 additions and 34 deletions

View File

@@ -18,8 +18,7 @@
#include "mdbtools.h"
#undef MDB_BIND_SIZE
#define MDB_BIND_SIZE 200000
#define EXPORT_BIND_SIZE 200000
#define is_quote_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_DATETIME || x==MDB_BINARY || x==MDB_REPID)
#define is_binary_type(x) (x==MDB_OLE || x==MDB_BINARY || x==MDB_REPID)
@@ -191,6 +190,8 @@ main(int argc, char **argv)
if (boolean_words)
mdb_set_boolean_fmt_words(mdb);
mdb_set_bind_size(mdb, EXPORT_BIND_SIZE);
if (insert_dialect)
if (!mdb_set_default_backend(mdb, insert_dialect)) {
fputs("Invalid backend type\n", stderr);
@@ -213,7 +214,7 @@ main(int argc, char **argv)
bound_lens = (int *) g_malloc(table->num_cols * sizeof(int));
for (i = 0; i < table->num_cols; i++) {
/* bind columns */
bound_values[i] = (char *) g_malloc0(MDB_BIND_SIZE);
bound_values[i] = (char *) g_malloc0(EXPORT_BIND_SIZE);
mdb_bind_column(table, i + 1, bound_values[i], &bound_lens[i]);
}
if (header_row) {

View File

@@ -20,8 +20,7 @@
#include "base64.h"
#undef MDB_BIND_SIZE
#define MDB_BIND_SIZE 200000
#define EXPORT_BIND_SIZE 200000
#define is_quote_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_DATETIME || x==MDB_BINARY || x==MDB_REPID)
#define is_binary_type(x) (x==MDB_OLE || x==MDB_BINARY || x==MDB_REPID)
@@ -144,6 +143,8 @@ main(int argc, char **argv)
if (date_fmt)
mdb_set_date_fmt(mdb, date_fmt);
mdb_set_bind_size(mdb, EXPORT_BIND_SIZE);
table = mdb_read_table_by_name(mdb, argv[2], MDB_TABLE);
if (!table) {
fprintf(stderr, "Error: Table %s does not exist in this database.\n", argv[argc-1]);
@@ -159,7 +160,7 @@ main(int argc, char **argv)
bound_lens = (int *) g_malloc(table->num_cols * sizeof(int));
for (i=0;i<table->num_cols;i++) {
/* bind columns */
bound_values[i] = (char *) g_malloc0(MDB_BIND_SIZE);
bound_values[i] = (char *) g_malloc0(EXPORT_BIND_SIZE);
mdb_bind_column(table, i+1, bound_values[i], &bound_lens[i]);
}

View File

@@ -33,8 +33,7 @@
#include "mdbtools.h"
#undef MDB_BIND_SIZE
#define MDB_BIND_SIZE 200000
#define QUERY_BIND_SIZE 200000
void mdb_list_queries(MdbHandle *mdb, int line_break, char *delimiter);
char * mdb_get_query_id(MdbHandle *mdb,char *query);
@@ -50,21 +49,22 @@ int main (int argc, char **argv) {
int line_break=0;
int opt;
char *query_id;
size_t bind_size = QUERY_BIND_SIZE;
// variables for the msysqueries table. hopefully 256 is big enough
char *attribute = (char *) malloc(MDB_BIND_SIZE);
char *expression = (char *) malloc(MDB_BIND_SIZE);
char *flag = (char *) malloc(MDB_BIND_SIZE);
char *name1 = (char *) malloc(MDB_BIND_SIZE);
char *name2 = (char *) malloc(MDB_BIND_SIZE);
char *objectid = (char *) malloc(MDB_BIND_SIZE);
char *order = (char *) malloc(MDB_BIND_SIZE);
char *attribute = (char *) malloc(bind_size);
char *expression = (char *) malloc(bind_size);
char *flag = (char *) malloc(bind_size);
char *name1 = (char *) malloc(bind_size);
char *name2 = (char *) malloc(bind_size);
char *objectid = (char *) malloc(bind_size);
char *order = (char *) malloc(bind_size);
//variables for the generation of sql
char *sql_tables = (char *) malloc(MDB_BIND_SIZE);
char *sql_columns = (char *) malloc(MDB_BIND_SIZE);
char *sql_where = (char *) malloc(MDB_BIND_SIZE);
char *sql_sorting = (char *) malloc(MDB_BIND_SIZE);
char *sql_tables = (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);
/* see getopt(3) for more information on getopt and this will become clear */
while ((opt=getopt(argc, argv, "L1d:"))!=-1) {
@@ -102,6 +102,8 @@ int main (int argc, char **argv) {
exit(1);
}
mdb_set_bind_size(mdb, bind_size);
/* read the catalog */
if (!mdb_read_catalog (mdb, MDB_ANY)) {
fprintf(stderr,"File does not appear to be an Access database\n");