diff --git a/LNX-docker-compose.yml b/LNX-docker-compose.yml index 4b5854a..4185fbc 100644 --- a/LNX-docker-compose.yml +++ b/LNX-docker-compose.yml @@ -11,7 +11,7 @@ services: - MYSQL_ROOT_PASSWORD=simple fakeservices.datajoint.io: <<: *net - image: raphaelguzman/nginx:v0.0.10 + image: datajoint/nginx:v0.0.16 environment: - ADD_db_TYPE=DATABASE - ADD_db_ENDPOINT=db:3306 diff --git a/distribution/mexa64/mym.mexa64 b/distribution/mexa64/mym.mexa64 index 99319fa..8a624b2 100755 Binary files a/distribution/mexa64/mym.mexa64 and b/distribution/mexa64/mym.mexa64 differ diff --git a/distribution/mexmaci64/mym.mexmaci64 b/distribution/mexmaci64/mym.mexmaci64 index 2ad0b14..1b4fe6a 100755 Binary files a/distribution/mexmaci64/mym.mexmaci64 and b/distribution/mexmaci64/mym.mexmaci64 differ diff --git a/distribution/mexw64/mym.mexw64 b/distribution/mexw64/mym.mexw64 index 2e18b02..8e55861 100644 Binary files a/distribution/mexw64/mym.mexw64 and b/distribution/mexw64/mym.mexw64 differ diff --git a/local-docker-compose.yml b/local-docker-compose.yml index daa5bb0..163afd0 100644 --- a/local-docker-compose.yml +++ b/local-docker-compose.yml @@ -16,7 +16,7 @@ services: # - ./mysql/data:/var/lib/mysql fakeservices.datajoint.io: <<: *net - image: raphaelguzman/nginx:v0.0.10 + image: datajoint/nginx:v0.0.16 environment: - ADD_db_TYPE=DATABASE - ADD_db_ENDPOINT=db:3306 diff --git a/src/mym.cpp b/src/mym.cpp index 848aeba..eef6eea 100644 --- a/src/mym.cpp +++ b/src/mym.cpp @@ -354,7 +354,7 @@ static void updateplugindir() { mxDestroyArray(mym_fileparts[2]); } /********************************************************************** - *mysql(): Execute the actual action + * mysql(): Execute the actual action * Which action we perform is based on the first input argument, * which must be present and must be a character string: * 'open', 'close', 'use', 'status', or a legitimate MySQL query. @@ -694,11 +694,11 @@ void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[]) { } //******************PLACEHOLDER PROCESSING****************** // global placeholders variables and constant - const unsigned nex = nrhs-jarg-1; // expected number of placeholders + const unsigned expectedNumberOfPlaceholders = nrhs-jarg-1; // expected number of placeholders unsigned query_flags = 0; unsigned nb_flags = 0; unsigned nac = 0; // actual number - size_t lq = strlen(query); // original query length, needed at some point + size_t lengthOfQuery = strlen(query); // Length of the query which is needed for mysql_real_query later // Check for presence of query flags. This needs to be expanded once we have additional flags for (int i=nrhs-1; i > jarg; --i) { if (mxIsChar(prhs[i]) && (strcasecmp(getstring(prhs[i]), ML_FLAG_BIGINT_TO_DOUBLE)==0)) { @@ -709,7 +709,8 @@ void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[]) { } } - if (nex) { + // If there is placeholders, parse them accordingly + if (expectedNumberOfPlaceholders) { // local placeholders variables and constant char** po = 0; // pointer to placeholders openning symbols char** pc = 0; // pointer to placeholders closing symbols @@ -718,10 +719,10 @@ void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[]) { unsigned* ps = 0; // pointer to placeholders size (in bytes) pfserial* pf = 0; // pointer to serialization function // LOOK FOR THE PLACEHOLDERS - po = (char**)mxCalloc(nex+1, sizeof(char*)); - pc = (char**)mxCalloc(nex+1, sizeof(char*)); + po = (char**)mxCalloc(expectedNumberOfPlaceholders+1, sizeof(char*)); + pc = (char**)mxCalloc(expectedNumberOfPlaceholders+1, sizeof(char*)); if ((po[nac++] = strstr(query, PH_OPEN))) - while (po[nac-1]&&nac<=nex) { + while (po[nac-1]&&nac<=expectedNumberOfPlaceholders) { pc[nac-1] = strstr(po[nac-1]+1, PH_CLOSE); if (pc[nac-1]==0) mexErrMsgTxt("Placeholders are not correctly closed!"); @@ -730,10 +731,10 @@ void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[]) { } nac--; // Adjust placeholders based on the number of flags present - if ((nac < nex) && (nac >= (nex-nb_flags))) { - nb_flags = nex-nac; + if ((nac < expectedNumberOfPlaceholders) && (nac >= (expectedNumberOfPlaceholders-nb_flags))) { + nb_flags = expectedNumberOfPlaceholders-nac; } - else if (nac != nex) { + else if (nac != expectedNumberOfPlaceholders) { mexErrMsgTxt("The number of placeholders differs from that of additional arguments!"); } // now we have the correct number of placeholders @@ -789,7 +790,7 @@ void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[]) { nb += plen[i]; } // create new query - char* nq = (char*)mxCalloc(2*nb+lq+1, sizeof(char)); // new query + char* nq = (char*)mxCalloc(2*nb+lengthOfQuery+1, sizeof(char)); // new query char* pnq = nq; // running pointer to new query const char* poq = query; // running pointer to old query for (unsigned i = 0; i (jarg+1)) mexErrMsgTxt("Version command does not take additional inputs"); if (nlhs == 0) { @@ -1423,7 +1452,6 @@ char* serializeArray(size_t &rnBytes, const mxArray *rpArray, const char *rpArg, - // Serialize a sparse matrix char* serializeSparse(size_t &rnBytes, const mxArray *rpArray, const char *rpArg, const bool rhead) diff --git a/src/mym.h b/src/mym.h index 0168441..1e4a102 100644 --- a/src/mym.h +++ b/src/mym.h @@ -34,7 +34,7 @@ // mym version information #define MYM_VERSION_MAJOR 2 #define MYM_VERSION_MINOR 8 -#define MYM_VERSION_BUGFIX 0 +#define MYM_VERSION_BUGFIX 1 // some local defintion diff --git a/tests/Main.m b/tests/Main.m index abd263b..e06bea7 100644 --- a/tests/Main.m +++ b/tests/Main.m @@ -1,5 +1,6 @@ classdef Main < ... TestConnection & ... + TestDeclare & ... TestExternal & ... TestInsertFetch & ... TestTls diff --git a/tests/TestDeclare.m b/tests/TestDeclare.m new file mode 100644 index 0000000..3a79a9a --- /dev/null +++ b/tests/TestDeclare.m @@ -0,0 +1,25 @@ +classdef TestDeclare < Prep + % TestDeclare tests typical connection scenarios. + methods (Test) + function TestDeclare_delcareTable(testCase) + % Test table declare with comments that has \{ or \} + st = dbstack; + disp(['---------------' st(1).name '---------------']); + conn1 = mym(-1, 'open', testCase.CONN_INFO.host, ... + testCase.CONN_INFO.user, testCase.CONN_INFO.password, ... + 'false'); + + mym(conn1, ['create database `' testCase.PREFIX '_declare`']); + mym(['create table {S}(id int, data varchar(30) default null) COMMENT "\{username\}_\{subject_nickname\}"'], ... + sprintf('`%s_%s`.`%s`', testCase.PREFIX, 'declare', 'test_table')); + query_string = mym(sprintf('SHOW CREATE TABLE `%s_%s`.`%s`', testCase.PREFIX, 'declare', 'test_table')); + + if ~strfind(query_string.('Create Table'){1}, 'COMMENT=''{username}_{subject_nickname}''') + throw(MException('TestDeclare:invalidDeclareTable',... + 'Table comments got inserted incorrectly')); + end + mym(conn1, ['drop database `' testCase.PREFIX '_declare`']); + mym(conn1, 'close'); + end + end +end \ No newline at end of file