From 73526e6d59cea515d174857902d27b69e8c14000 Mon Sep 17 00:00:00 2001 From: mohaned-mashaly Date: Wed, 9 Jun 2021 17:12:11 +0200 Subject: [PATCH] refactor if conditon of host and database --- src/mysql/MySQL.chpl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mysql/MySQL.chpl b/src/mysql/MySQL.chpl index c7d8588..916ecff 100644 --- a/src/mysql/MySQL.chpl +++ b/src/mysql/MySQL.chpl @@ -6,7 +6,7 @@ module MySQL { use Map; use SysCTypes; use MySQLNative; - + use Regexp; /* Enum that describes the data type held by a field in MySQL. Note: MySQL uses TINYINT(1) internally for the BOOLEAN @@ -99,7 +99,7 @@ module MySQL { var database: string; var username: string; var password: string; - + var myRegexp = compile("[[:space:]]*"); // let's extract the relevant info from the connection string for (i, str) in zip(0.., connectionString.split(';')) { select i { @@ -112,10 +112,13 @@ module MySQL { } // Throw errors if anything wrong: (TODO: can be improved) - if (host == '' || database == '') { + var host_match = myRegexp.match(host).matched; + var db_match = myRegexp.match(database).matched; + if (host_match || db_match){ throw new ConnectionStringFormatError(); } + this._autocommit = autocommit; this._prev_autocommit_state = autocommit; this._cptr_mysqlconn = mysql_init(this._cptr_mysqlconn);