SQLite integer default values might be quoted.

Fix #351 by having a new transformation function to process SQLite
integers, that may be quoted...
This commit is contained in:
Dimitri Fontaine 2016-03-03 14:56:18 +01:00
parent 62edd5a2c8
commit 486be8c068
4 changed files with 53 additions and 8 deletions

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "PGLOADER" "1" "February 2016" "ff" ""
.TH "PGLOADER" "1" "March 2016" "ff" ""
.
.SH "NAME"
\fBpgloader\fR \- PostgreSQL data loader
@ -2480,10 +2480,10 @@ When migrating from SQLite the following Casting Rules are provided:
Numbers:
.
.IP "\(bu" 4
type tinyint to smallint
type tinyint to smallint using integer\-to\-string
.
.IP "\(bu" 4
type integer to bigint
type integer to bigint using integer\-to\-string
.
.IP "\(bu" 4
type float to float using float\-to\-string
@ -2866,6 +2866,24 @@ Out: "(48\.5513589,7\.6926827)"
.
.IP "" 0
.
.IP "\(bu" 4
\fIinteger\-to\-string\fR
.
.IP
Converts a integer string or a Common Lisp integer into a string suitable for a PostgreSQL integer\. Takes care of quoted integers\.
.
.IP "" 4
.
.nf
In: "\e"0\e""
Out: "0"
.
.fi
.
.IP "" 0
.
.IP "\(bu" 4
\fIfloat\-to\-string\fR

View File

@ -2059,8 +2059,8 @@ When migrating from SQLite the following Casting Rules are provided:
Numbers:
- type tinyint to smallint
- type integer to bigint
- type tinyint to smallint using integer-to-string
- type integer to bigint using integer-to-string
- type float to float using float-to-string
- type real to real using float-to-string
@ -2268,6 +2268,14 @@ The provided transformation functions are:
In: "POINT(48.5513589 7.6926827)"
Out: "(48.5513589,7.6926827)"
- *integer-to-string*
Converts a integer string or a Common Lisp integer into a string
suitable for a PostgreSQL integer. Takes care of quoted integers.
In: "\"0\""
Out: "0"
- *float-to-string*
Converts a Common Lisp float into a string suitable for a PostgreSQL float:

View File

@ -15,8 +15,11 @@
(:source (:type "nchar") :target (:type "text" :drop-typemod t))
(:source (:type "clob") :target (:type "text" :drop-typemod t))
(:source (:type "tinyint") :target (:type "smallint"))
(:source (:type "integer") :target (:type "bigint"))
(:source (:type "tinyint") :target (:type "smallint")
:using pgloader.transforms::integer-to-string)
(:source (:type "integer") :target (:type "bigint")
:using pgloader.transforms::integer-to-string)
(:source (:type "float") :target (:type "float")
:using pgloader.transforms::float-to-string)

View File

@ -62,7 +62,8 @@
int-to-ip
ip-range
convert-mysql-point
float-to-string
integer-to-string
float-to-string
empty-string-to-null
set-to-enum-array
right-trim
@ -186,6 +187,21 @@
(setf (aref point (position #\Space point)) #\,)
point)))
(defun integer-to-string (integer-string)
"Transform INTEGER-STRING parameter into a proper string representation of
it. In particular be careful of quoted-integers, thanks to SQLite default
values."
(declare (type (or null string fixnum) integer-string))
(when integer-string
(typecase integer-string
(integer (princ-to-string integer-string))
(string (handler-case
(parse-integer integer-string :start 0)
(condition (c)
(declare (ignore c))
(parse-integer integer-string :start 1
:end (- (length integer-string) 1))))))))
(defun float-to-string (float)
"Transform a Common Lisp float value into its string representation as
accepted by PostgreSQL, that is 100.0 rather than 100.0d0."