Skip to content

Commit

Permalink
- Fix MDEV-10948. Syntax error on quoted JDBC tables.
Browse files Browse the repository at this point in the history
  Was because the quoting character was always '"' instead of being
  retrieve from the JDBC source.
  modified:   storage/connect/JdbcInterface.java
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/tabjdbc.cpp
  • Loading branch information
Buggynours committed Oct 5, 2016
1 parent 98cc091 commit e6c678c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
12 changes: 12 additions & 0 deletions storage/connect/JdbcInterface.java
Expand Up @@ -340,6 +340,18 @@ public int GetMaxValue(int n) {
return m;
} // end of GetMaxValue

public String GetQuoteString() {
String qs = null;

try {
qs = dbmd.getIdentifierQuoteString();
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch

return qs;
} // end of GetQuoteString

public int GetColumns(String[] parms) {
int ncol = -1;

Expand Down
15 changes: 15 additions & 0 deletions storage/connect/jdbconn.cpp
Expand Up @@ -1011,6 +1011,21 @@ int JDBConn::Open(PJPARM sop)
return RC_FX;
} // endif Msg

jmethodID qcid = nullptr;

if (!gmID(g, qcid, "GetQuoteString", "()Ljava/lang/String;")) {
jstring s = (jstring)env->CallObjectMethod(job, qcid);

if (s != nullptr) {
char *qch = (char*)env->GetStringUTFChars(s, (jboolean)false);
m_IDQuoteChar[0] = *qch;
} else {
s = (jstring)env->CallObjectMethod(job, errid);
Msg = (char*)env->GetStringUTFChars(s, (jboolean)false);
} // endif s

} // endif qcid

if (gmID(g, typid, "ColumnType", "(ILjava/lang/String;)I"))
return RC_FX;
else
Expand Down
19 changes: 15 additions & 4 deletions storage/connect/tabjdbc.cpp
Expand Up @@ -686,6 +686,9 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
else
Prepared = true;

if (trace)
htrc("Insert=%s\n", Query->GetStr());

return false;
} // end of MakeInsert

Expand Down Expand Up @@ -733,17 +736,18 @@ bool TDBJDBC::MakeCommand(PGLOBAL g)
// If so, it must be quoted in the original query
strlwr(strcat(strcat(strcpy(name, " "), Name), " "));

if (!strstr(" update delete low_priority ignore quick from ", name))
strlwr(strcpy(name, Name)); // Not a keyword
else
if (strstr(" update delete low_priority ignore quick from ", name)) {
strlwr(strcat(strcat(strcpy(name, qc), Name), qc));
k += 2;
} else
strlwr(strcpy(name, Name)); // Not a keyword

if ((p = strstr(qrystr, name))) {
for (i = 0; i < p - qrystr; i++)
stmt[i] = (Qrystr[i] == '`') ? *qc : Qrystr[i];

stmt[i] = 0;
k = i + (int)strlen(Name);
k += i + (int)strlen(Name);

if (qtd && *(p-1) == ' ')
strcat(strcat(strcat(stmt, qc), TableName), qc);
Expand All @@ -765,6 +769,9 @@ bool TDBJDBC::MakeCommand(PGLOBAL g)
return NULL;
} // endif p

if (trace)
htrc("Command=%s\n", stmt);

Query = new(g)STRING(g, 0, stmt);
return (!Query->GetSize());
} // end of MakeCommand
Expand Down Expand Up @@ -1214,6 +1221,10 @@ int TDBJDBC::WriteDB(PGLOBAL g)
} // endif oom

Query->RepLast(')');

if (trace > 1)
htrc("Inserting: %s\n", Query->GetStr());

rc = Jcp->ExecuteUpdate(Query->GetStr());
Query->Truncate(len); // Restore query

Expand Down

0 comments on commit e6c678c

Please sign in to comment.