projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update all #include directives to the currently preferred style.
[pspp-builds.git]
/
src
/
data
/
psql-reader.c
diff --git
a/src/data/psql-reader.c
b/src/data/psql-reader.c
index 741bf36e44c079196d608df94c1a6b5f6ee7a9e4..346d214ad31e6d43050dccba941979390cb5cf33 100644
(file)
--- a/
src/data/psql-reader.c
+++ b/
src/data/psql-reader.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009
, 2010, 2011
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-16,23
+16,23
@@
#include <config.h>
#include <config.h>
-#include <data/casereader-provider.h>
-#include <libpspp/message.h>
-#include <gl/xalloc.h>
-#include <data/dictionary.h>
+#include "data/psql-reader.h"
+
+#include <inttypes.h>
#include <math.h>
#include <stdlib.h>
#include <math.h>
#include <stdlib.h>
-#include "psql-reader.h"
-#include "variable.h"
-#include "format.h"
-#include "calendar.h"
+#include "data/calendar.h"
+#include "data/casereader-provider.h"
+#include "data/dictionary.h"
+#include "data/format.h"
+#include "data/variable.h"
+#include "libpspp/message.h"
+#include "libpspp/misc.h"
+#include "libpspp/str.h"
-#include <inttypes.h>
-#include <libpspp/misc.h>
-#include <libpspp/str.h>
-
-#include "minmax.h"
+#include "gl/xalloc.h"
+#include "gl/minmax.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-54,6
+54,9
@@
psql_open_reader (struct psql_read_info *info UNUSED, struct dictionary **dict U
#include <libpq-fe.h>
#include <libpq-fe.h>
+/* Default width of string variables. */
+#define PSQL_DEFAULT_WIDTH 8
+
/* These macros must be the same as in catalog/pg_types.h from the postgres source */
#define BOOLOID 16
#define BYTEAOID 17
/* These macros must be the same as in catalog/pg_types.h from the postgres source */
#define BOOLOID 16
#define BYTEAOID 17
@@
-177,15
+180,12
@@
create_var (struct psql_reader *r, const struct fmt_spec *fmt,
{
unsigned long int vx = 0;
struct variable *var;
{
unsigned long int vx = 0;
struct variable *var;
- char name[VAR_NAME_LEN + 1];
-
- if ( ! dict_make_unique_var_name (r->dict, suggested_name, &vx, name))
- {
- msg (ME, _("Cannot create variable name from %s"), suggested_name);
- return NULL;
- }
+ char *name;
+ name = dict_make_unique_var_name (r->dict, suggested_name, &vx);
var = dict_create_var (r->dict, name, width);
var = dict_create_var (r->dict, name, width);
+ free (name);
+
var_set_both_formats (var, fmt);
if ( col != -1)
var_set_both_formats (var, fmt);
if ( col != -1)
@@
-283,8
+283,7
@@
psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
}
}
}
}
- r->postgres_epoch =
- calendar_gregorian_to_offset (2000, 1, 1, NULL, NULL);
+ r->postgres_epoch = calendar_gregorian_to_offset (2000, 1, 1, NULL);
/* Create the dictionary and populate it */
/* Create the dictionary and populate it */
@@
-376,7
+375,7
@@
psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
if ( n_tuples > 0 )
length = PQgetlength (qres, 0, i);
else
if ( n_tuples > 0 )
length = PQgetlength (qres, 0, i);
else
- length =
MAX_SHORT_STRING
;
+ length =
PSQL_DEFAULT_WIDTH
;
switch (type)
{
switch (type)
{
@@
-403,13
+402,13
@@
psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
case BPCHAROID:
fmt.type = FMT_A;
width = (info->str_width == -1) ?
case BPCHAROID:
fmt.type = FMT_A;
width = (info->str_width == -1) ?
- ROUND_UP (length,
MAX_SHORT_STRING
) : info->str_width;
+ ROUND_UP (length,
PSQL_DEFAULT_WIDTH
) : info->str_width;
fmt.w = width;
fmt.d = 0;
break;
case BYTEAOID:
fmt.type = FMT_AHEX;
fmt.w = width;
fmt.d = 0;
break;
case BYTEAOID:
fmt.type = FMT_AHEX;
- width = length > 0 ? length :
MAX_SHORT_STRING
;
+ width = length > 0 ? length :
PSQL_DEFAULT_WIDTH
;
fmt.w = width * 2;
fmt.d = 0;
break;
fmt.w = width * 2;
fmt.d = 0;
break;
@@
-448,14
+447,14
@@
psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
default:
msg (MW, _("Unsupported OID %d. SYSMIS values will be inserted."), type);
fmt.type = FMT_A;
default:
msg (MW, _("Unsupported OID %d. SYSMIS values will be inserted."), type);
fmt.type = FMT_A;
- width = length > 0 ? length :
MAX_SHORT_STRING
;
+ width = length > 0 ? length :
PSQL_DEFAULT_WIDTH
;
fmt.w = width ;
fmt.d = 0;
break;
}
if ( width == 0 && fmt_is_string (fmt.type))
fmt.w = width ;
fmt.d = 0;
break;
}
if ( width == 0 && fmt_is_string (fmt.type))
- fmt.w = width =
MAX_SHORT_STRING
;
+ fmt.w = width =
PSQL_DEFAULT_WIDTH
;
var = create_var (r, &fmt, width, PQfname (qres, i), i);
var = create_var (r, &fmt, width, PQfname (qres, i), i);
@@
-835,7
+834,7
@@
set_value (struct psql_reader *r)
case VARCHAROID:
case BPCHAROID:
case BYTEAOID:
case VARCHAROID:
case BPCHAROID:
case BYTEAOID:
- memcpy (value_str_rw (val, var_width),
(char *)
vptr,
+ memcpy (value_str_rw (val, var_width), vptr,
MIN (length, var_width));
break;
MIN (length, var_width));
break;