mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-07-16 03:22:44 +08:00
Merge pull request #94 from ewen-naos-nz/boolean_data_as_words
mdb-export: Add boolean words option (TRUE/FALSE)
This commit is contained in:
commit
15230b5b73
@ -496,6 +496,7 @@ extern size_t mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr);
|
|||||||
extern size_t mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size);
|
extern size_t mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size);
|
||||||
extern void* mdb_ole_read_full(MdbHandle *mdb, MdbColumn *col, size_t *size);
|
extern void* mdb_ole_read_full(MdbHandle *mdb, MdbColumn *col, size_t *size);
|
||||||
extern void mdb_set_date_fmt(const char *);
|
extern void mdb_set_date_fmt(const char *);
|
||||||
|
extern void mdb_set_boolean_fmt_words();
|
||||||
extern int mdb_read_row(MdbTableDef *table, unsigned int row);
|
extern int mdb_read_row(MdbTableDef *table, unsigned int row);
|
||||||
|
|
||||||
/* dump.c */
|
/* dump.c */
|
||||||
|
@ -44,6 +44,25 @@ void mdb_set_date_fmt(const char *fmt)
|
|||||||
strncpy(date_fmt, fmt, 63);
|
strncpy(date_fmt, fmt, 63);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Some databases (eg PostgreSQL) do not understand integer 0/1 values
|
||||||
|
* as TRUE/FALSE, so provide a means to override the values used to be
|
||||||
|
* the SQL Standard TRUE/FALSE values.
|
||||||
|
*/
|
||||||
|
static char boolean_false_number[] = "0";
|
||||||
|
static char boolean_true_number[] = "1";
|
||||||
|
|
||||||
|
static char boolean_false_word[] = "FALSE";
|
||||||
|
static char boolean_true_word[] = "TRUE";
|
||||||
|
|
||||||
|
static char *boolean_false_value = boolean_false_number;
|
||||||
|
static char *boolean_true_value = boolean_true_number;
|
||||||
|
|
||||||
|
void mdb_set_boolean_fmt_words()
|
||||||
|
{
|
||||||
|
boolean_false_value = boolean_false_word;
|
||||||
|
boolean_true_value = boolean_true_word;
|
||||||
|
}
|
||||||
|
|
||||||
void mdb_bind_column(MdbTableDef *table, int col_num, void *bind_ptr, int *len_ptr)
|
void mdb_bind_column(MdbTableDef *table, int col_num, void *bind_ptr, int *len_ptr)
|
||||||
{
|
{
|
||||||
MdbColumn *col;
|
MdbColumn *col;
|
||||||
@ -168,10 +187,11 @@ mdb_xfer_bound_bool(MdbHandle *mdb, MdbColumn *col, int value)
|
|||||||
{
|
{
|
||||||
col->cur_value_len = value;
|
col->cur_value_len = value;
|
||||||
if (col->bind_ptr) {
|
if (col->bind_ptr) {
|
||||||
strcpy(col->bind_ptr, value ? "0" : "1");
|
strcpy(col->bind_ptr,
|
||||||
|
value ? boolean_false_value : boolean_true_value);
|
||||||
}
|
}
|
||||||
if (col->len_ptr) {
|
if (col->len_ptr) {
|
||||||
*col->len_ptr = 1;
|
*col->len_ptr = strlen(col->bind_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -89,6 +89,7 @@ main(int argc, char **argv)
|
|||||||
char *escape_char = NULL;
|
char *escape_char = NULL;
|
||||||
int header_row = 1;
|
int header_row = 1;
|
||||||
int quote_text = 1;
|
int quote_text = 1;
|
||||||
|
int boolean_words = 0;
|
||||||
char *insert_dialect = NULL;
|
char *insert_dialect = NULL;
|
||||||
char *date_fmt = NULL;
|
char *date_fmt = NULL;
|
||||||
char *namespace = NULL;
|
char *namespace = NULL;
|
||||||
@ -110,6 +111,7 @@ main(int argc, char **argv)
|
|||||||
{ "namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"},
|
{ "namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"},
|
||||||
{ "null", '0', 0, G_OPTION_ARG_STRING, &null_text, "Use <char> to represent a NULL value", "char"},
|
{ "null", '0', 0, G_OPTION_ARG_STRING, &null_text, "Use <char> to represent a NULL value", "char"},
|
||||||
{ "bin", 'b', 0, G_OPTION_ARG_STRING, &str_bin_mode, "Binary export mode", "strip|raw|octal"},
|
{ "bin", 'b', 0, G_OPTION_ARG_STRING, &str_bin_mode, "Binary export mode", "strip|raw|octal"},
|
||||||
|
{ "boolean-words", 'B', 0, G_OPTION_ARG_NONE, &boolean_words, "Use TRUE/FALSE in Boolean fields (default is 0/1)", NULL},
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@ -161,6 +163,9 @@ main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
null_text = g_strdup("");
|
null_text = g_strdup("");
|
||||||
|
|
||||||
|
if (boolean_words)
|
||||||
|
mdb_set_boolean_fmt_words();
|
||||||
|
|
||||||
if (str_bin_mode) {
|
if (str_bin_mode) {
|
||||||
if (!strcmp(str_bin_mode, "strip"))
|
if (!strcmp(str_bin_mode, "strip"))
|
||||||
bin_mode = MDB_BINEXPORT_STRIP;
|
bin_mode = MDB_BINEXPORT_STRIP;
|
||||||
|
Loading…
Reference in New Issue
Block a user