diff options
| author | Olivier Bertrand <bertrandop@gmail.com> | 2013-11-06 18:22:09 +0100 |
|---|---|---|
| committer | Olivier Bertrand <bertrandop@gmail.com> | 2013-11-06 18:22:09 +0100 |
| commit | 056f35d0c136af4437344d4fbce80172e6d96817 (patch) | |
| tree | 954befda500a4f7b1fb3b6d5b1e814a7077c3d96 /storage/connect/tabmysql.cpp | |
| parent | f1325549e9eca1311435255854da0a93923eff9b (diff) | |
| download | mariadb-git-056f35d0c136af4437344d4fbce80172e6d96817.tar.gz | |
- Move all enum AMT definitions in one place (plgdbsem.h)
modified:
storage/connect/filamtxt.h
storage/connect/filamzip.h
storage/connect/myconn.h
storage/connect/plgdbsem.h
storage/connect/taboccur.h
storage/connect/tabutil.h
storage/connect/tabxcl.h
- Add the possibility to execute several commands in one query of
an EXECSRC tables (using ...where command in (cmd list);)
modified:
storage/connect/ha_connect.cc
storage/connect/odbconn.cpp
storage/connect/odbconn.h
storage/connect/tabmysql.cpp
storage/connect/tabmysql.h
storage/connect/tabodbc.cpp
storage/connect/tabodbc.h
storage/connect/tabtbl.cpp
storage/connect/tabwmi.cpp
storage/connect/xtable.h
- Enhance retrieving column definitions in discovery:
From SRCDEF adding LIMIT 0 to the executed query
Testing if type, length, and precision are compatible
Making the distinction between CHAR and VARCHAR
modified:
storage/connect/ha_connect.cc
storage/connect/myconn.cpp
storage/connect/mysql-test/connect/r/mysql.result
storage/connect/mysql-test/connect/r/odbc_sqlite3.result
storage/connect/mysql-test/connect/r/odbc_sqlite3_grant.result
storage/connect/myutil.h
storage/connect/myutil.h
storage/connect/odbconn.cpp
storage/connect/value.h
Diffstat (limited to 'storage/connect/tabmysql.cpp')
| -rw-r--r-- | storage/connect/tabmysql.cpp | 135 |
1 files changed, 99 insertions, 36 deletions
diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index f37cb6d349e..d1f3d90fade 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -355,7 +355,9 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) if ((Srcdef = Cat->GetStringCatInfo(g, "Srcdef", NULL))) Isview = TRUE; + // Specific for command executing tables Xsrc = Cat->GetBoolCatInfo("Execsrc", FALSE); + Mxr = Cat->GetIntCatInfo("Maxerr", 0); return FALSE; } // end of DefineAM @@ -516,7 +518,7 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g) strcat(strcat(strcat(strcat(Query, " FROM "), tk), Tabname), tk); if (To_Filter) - strcat(strcat(Query, " WHERE "), To_Filter); + strcat(strcat(Query, " WHERE "), To_Filter->Body); if (trace) htrc("Query=%s\n", Query); @@ -1294,8 +1296,30 @@ void MYSQLCOL::WriteColumn(PGLOBAL g) /* ------------------------------------------------------------------- */ /***********************************************************************/ -/* Implementation of the TDBMYSQL class. */ +/* Implementation of the TDBMYEXC class. */ /***********************************************************************/ +TDBMYEXC::TDBMYEXC(PMYDEF tdp) : TDBMYSQL(tdp) +{ + Cmdlist = NULL; + Cmdcol = NULL; + Shw = false; + Havew = false; + Isw = false; + Warnings = 0; + Mxr = tdp->Mxr; + Nerr = 0; +} // end of TDBMYEXC constructor + +TDBMYEXC::TDBMYEXC(PGLOBAL g, PTDBMYX tdbp) : TDBMYSQL(g, tdbp) +{ + Cmdlist = tdbp->Cmdlist; + Cmdcol = tdbp->Cmdcol; + Shw = tdbp->Shw; + Havew = tdbp->Havew; + Isw = tdbp->Isw; + Mxr = tdbp->Mxr; + Nerr = tdbp->Nerr; +} // end of TDBMYEXC copy constructor // Is this really useful ??? PTDB TDBMYEXC::CopyOne(PTABS t) @@ -1331,23 +1355,15 @@ PCOL TDBMYEXC::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) /***********************************************************************/ /* MakeCMD: make the SQL statement to send to MYSQL connection. */ /***********************************************************************/ -char *TDBMYEXC::MakeCMD(PGLOBAL g) +PCMD TDBMYEXC::MakeCMD(PGLOBAL g) { - char *xcmd = NULL; + PCMD xcmd = NULL; if (To_Filter) { if (Cmdcol) { - char col[128], cmd[1024]; - int n; - - memset(cmd, 0, sizeof(cmd)); - n = sscanf(To_Filter, "%s = '%1023c", col, cmd); - - if (n == 2 && !stricmp(col, Cmdcol)) { - xcmd = (char*)PlugSubAlloc(g, NULL, strlen(cmd) + 1); - - strcpy(xcmd, cmd); - xcmd[strlen(xcmd) - 1] = 0; + if (!stricmp(Cmdcol, To_Filter->Body) && + (To_Filter->Op == OP_EQ || To_Filter->Op == OP_IN)) { + xcmd = To_Filter->Cmds; } else strcpy(g->Message, "Invalid command specification filter"); @@ -1357,7 +1373,7 @@ char *TDBMYEXC::MakeCMD(PGLOBAL g) } else if (!Srcdef) strcpy(g->Message, "No Srcdef default command"); else - xcmd = Srcdef; + xcmd = new(g) CMD(g, Srcdef); return xcmd; } // end of MakeCMD @@ -1368,7 +1384,7 @@ char *TDBMYEXC::MakeCMD(PGLOBAL g) int TDBMYEXC::GetMaxSize(PGLOBAL g) { if (MaxSize < 0) { - MaxSize = 1; + MaxSize = 10; // a guess } // endif MaxSize return MaxSize; @@ -1379,8 +1395,6 @@ int TDBMYEXC::GetMaxSize(PGLOBAL g) /***********************************************************************/ bool TDBMYEXC::OpenDB(PGLOBAL g) { - int rc; - if (Use == USE_OPEN) { strcpy(g->Message, "Multiple execution is not allowed"); return true; @@ -1407,20 +1421,11 @@ bool TDBMYEXC::OpenDB(PGLOBAL g) /*********************************************************************/ /* Get the command to execute. */ /*********************************************************************/ - if (!(Query = MakeCMD(g))) { + if (!(Cmdlist = MakeCMD(g))) { Myc.Close(); return true; } // endif Query - if ((rc = Myc.ExecSQL(g, Query)) == RC_NF) { - strcpy(g->Message, "Affected rows"); - AftRows = Myc.m_Rows; - } else if (rc == RC_OK) { - sprintf(g->Message, "Columns and %d rows", Myc.m_Rows); - AftRows = Myc.m_Fields; - } else - return true; - return false; } // end of OpenDB @@ -1429,7 +1434,54 @@ bool TDBMYEXC::OpenDB(PGLOBAL g) /***********************************************************************/ int TDBMYEXC::ReadDB(PGLOBAL g) { - return (++N) ? RC_EF : RC_OK; + if (Havew) { + // Process result set from SHOW WARNINGS + if (Myc.Fetch(g, -1) != RC_OK) { + Myc.FreeResult(); + Havew = Isw = false; + } else { + N++; + Isw = true; + return RC_OK; + } // endif Fetch + + } // endif m_Res + + if (Cmdlist) { + // Process query to send + int rc; + + do { + Query = Cmdlist->Cmd; + + switch (rc = Myc.ExecSQLcmd(g, Query, &Warnings)) { + case RC_NF: + AftRows = Myc.m_Afrw; + strcpy(g->Message, "Affected rows"); + break; + case RC_OK: + AftRows = Myc.m_Fields; + strcpy(g->Message, "Result set columns"); + break; + case RC_FX: + AftRows = Myc.m_Afrw; + Nerr++; + break; + case RC_INFO: + Shw = true; + } // endswitch rc + + Cmdlist = (Nerr > Mxr) ? NULL : Cmdlist->Next; + } while (rc == RC_INFO); + + if (Shw && Warnings) + Havew = (Myc.ExecSQL(g, "SHOW WARNINGS") == RC_OK); + + ++N; + return RC_OK; + } else + return RC_EF; + } // end of ReadDB /***********************************************************************/ @@ -1480,12 +1532,23 @@ void MYXCOL::ReadColumn(PGLOBAL g) { PTDBMYX tdbp = (PTDBMYX)To_Tdb; - switch (Flag) { - case 0: Value->SetValue_psz(tdbp->Query); break; - case 1: Value->SetValue(tdbp->AftRows); break; - case 2: Value->SetValue_psz(g->Message); break; - default: Value->SetValue_psz("Invalid Flag"); break; - } // endswitch Flag + if (tdbp->Isw) { + char *buf = NULL; + + if (Flag < 3) { + buf = tdbp->Myc.GetCharField(Flag); + Value->SetValue_psz(buf); + } else + Value->Reset(); + + } else + switch (Flag) { + case 0: Value->SetValue_psz(tdbp->Query); break; + case 1: Value->SetValue(tdbp->AftRows); break; + case 2: Value->SetValue_psz(g->Message); break; + case 3: Value->SetValue(tdbp->Warnings); break; + default: Value->SetValue_psz("Invalid Flag"); break; + } // endswitch Flag } // end of ReadColumn |
