changeset 60:412e30336847

allowing dollars and underscores in MySQL database identifiers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Nov 2018 15:06:08 +0100
parents 318c1ccb787c
children 89a114f36c42 eedd082355f9
files Framework/MySQL/MySQLDatabase.cpp Framework/MySQL/MySQLDatabase.h MySQL/NEWS MySQL/Plugins/MySQLIndex.cpp
diffstat 4 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/MySQL/MySQLDatabase.cpp	Sun Oct 28 12:29:22 2018 +0100
+++ b/Framework/MySQL/MySQLDatabase.cpp	Mon Nov 19 15:06:08 2018 +0100
@@ -328,7 +328,7 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
 
-    if (!IsAlphanumericString(name))
+    if (!IsValidDatabaseIdentifier(name))
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
@@ -360,7 +360,7 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
 
-    if (!IsAlphanumericString(name))
+    if (!IsValidDatabaseIdentifier(name))
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
@@ -480,11 +480,14 @@
   } 
 
 
-  bool MySQLDatabase::IsAlphanumericString(const std::string& s)
+  bool MySQLDatabase::IsValidDatabaseIdentifier(const std::string& s)
   {
     for (size_t i = 0; i < s.length(); i++)
     {
-      if (!isalnum(s[i]))
+      // https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
+      if (!isalnum(s[i]) &&
+          s[i] != '$' &&
+          s[i] != '_')
       {
         return false;
       }
--- a/Framework/MySQL/MySQLDatabase.h	Sun Oct 28 12:29:22 2018 +0100
+++ b/Framework/MySQL/MySQLDatabase.h	Mon Nov 19 15:06:08 2018 +0100
@@ -92,6 +92,6 @@
 
     static void GlobalFinalization();
 
-    static bool IsAlphanumericString(const std::string& s);
+    static bool IsValidDatabaseIdentifier(const std::string& s);
   };
 }
--- a/MySQL/NEWS	Sun Oct 28 12:29:22 2018 +0100
+++ b/MySQL/NEWS	Mon Nov 19 15:06:08 2018 +0100
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Characters "$" and "_" are allowed in MySQL database identifiers
+
 
 Release 1.1 (2018-07-18)
 ========================
--- a/MySQL/Plugins/MySQLIndex.cpp	Sun Oct 28 12:29:22 2018 +0100
+++ b/MySQL/Plugins/MySQLIndex.cpp	Mon Nov 19 15:06:08 2018 +0100
@@ -56,7 +56,7 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
     }
 
-    if (!MySQLDatabase::IsAlphanumericString(parameters_.GetDatabase()))
+    if (!MySQLDatabase::IsValidDatabaseIdentifier(parameters_.GetDatabase()))
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }