From e4dca1a08632829ceefdcf922d3428c7a26bfc64 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 16 Mar 2018 16:41:40 +0100 Subject: [PATCH] Implement support for MySQL useSSL=true|false option. The MySQL connection string parameter for SSL usage is useSSL, so map an option name to our expected values for sslmode in database connection strings. See #748. --- docs/ref/mysql.rst | 17 +++++++++++++++++ src/parsers/command-mysql.lisp | 24 +++++++++++++++++++++++- src/sources/csv/csv-guess.lisp | 2 +- test/mysql/f1db.load | 2 +- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/docs/ref/mysql.rst b/docs/ref/mysql.rst index b484d5b..193e5c5 100644 --- a/docs/ref/mysql.rst +++ b/docs/ref/mysql.rst @@ -73,7 +73,24 @@ See the `SOURCE CONNECTION STRING` section above for details on how to write the connection string. The MySQL connection string accepts the same parameter *sslmode* as the PostgreSQL connection string, but the *verify* mode is not implemented (yet). + +:: + + mysql://[user[:password]@][netloc][:port][/dbname][?option=value&...] + + + - *options* + + The same notation rules as found in the *Connection String* parts of the + documentation apply, and we have a specific MySQL option: `useSSL`. The + value for `useSSL` can be either `false` or `true`. + + If both `sslmode` and `useSSL` are used in the same connection string, + pgloader behavior is undefined. +The MySQL connection string also accepts the *useSSL* parameter with values +being either *false* or *true*. + Environment variables described in can be used as default values too. If the user is not provided, then it defaults to diff --git a/src/parsers/command-mysql.lisp b/src/parsers/command-mysql.lisp index 9ccf9c4..703515f 100644 --- a/src/parsers/command-mysql.lisp +++ b/src/parsers/command-mysql.lisp @@ -98,11 +98,33 @@ (defrule mysql-dsn-dbname (and "/" maybe-quoted-namestring) (:lambda (m-d-d) (list :dbname (text (second m-d-d))))) +(defrule mysql-dsn-option-usessl-true "true" (:constant :yes)) +(defrule mysql-dsn-option-usessl-false "false" (:constant :no)) + +(defrule mysql-dsn-option-usessl (and "useSSL" "=" + (or mysql-dsn-option-usessl-true + mysql-dsn-option-usessl-false)) + (:lambda (ssl) + (cons :use-ssl (third ssl)))) + +(defrule mysql-dsn-option (or dsn-option-ssl + mysql-dsn-option-usessl + dsn-option-host + dsn-option-port + dsn-option-dbname + dsn-option-user + dsn-option-pass + dsn-option-table-name)) + +(defrule mysql-dsn-options (and "?" (and mysql-dsn-option + (* (and "&" mysql-dsn-option)))) + (:lambda (opts) (cdr (flatten-option-list opts)))) + (defrule mysql-uri (and mysql-prefix (? dsn-user-password) (? dsn-hostname) mysql-dsn-dbname - (? dsn-options)) + (? mysql-dsn-options)) (:lambda (uri) (destructuring-bind (&key type user diff --git a/src/sources/csv/csv-guess.lisp b/src/sources/csv/csv-guess.lisp index 2b40bd1..b009534 100644 --- a/src/sources/csv/csv-guess.lisp +++ b/src/sources/csv/csv-guess.lisp @@ -6,7 +6,7 @@ (defparameter *separators* '(#\Tab #\, #\; #\| #\% #\^ #\! #\$) "Common CSV separators to try when guessing file parameters.") -(defparameter *escape-quotes* '("\\\"" "\"\"") +(defparameter *escape-quotes* '("\"\"" "\\\"") "Common CSV quotes to try when guessing file parameters.") (defun get-file-sample (filename &key (sample-size 10)) diff --git a/test/mysql/f1db.load b/test/mysql/f1db.load index 305f3ae..526f67c 100644 --- a/test/mysql/f1db.load +++ b/test/mysql/f1db.load @@ -1,3 +1,3 @@ load database - from mysql://root@localhost/f1db + from mysql://root@localhost/f1db?useSSL=false into pgsql:///plop;