MCPcopy Create free account
hub / github.com/MariaDB/server / SrcColumns

Function SrcColumns

storage/connect/myconn.cpp:394–436  ·  view source on GitHub ↗

/ SrcColumns: constructs the result blocks containing all columns */ resulting from an SQL source definition query execution. */ /

Source from the content-addressed store, hash-verified

392/* resulting from an SQL source definition query execution. */
393/************************************************************************/
394PQRYRES SrcColumns(PGLOBAL g, const char *host, const char *db,
395 const char *user, const char *pwd,
396 const char *srcdef, int port)
397 {
398 char *query;
399 int w;
400 MYSQLC myc;
401 PQRYRES qrp = NULL;
402 const char *p;
403
404 if (!port)
405 port = mysqld_port;
406
407 if (!strnicmp(srcdef, "select ", 7) || strstr(srcdef, "%s")) {
408 size_t query_sz = strlen(srcdef) + 10;
409 query = (char *)PlugSubAlloc(g, NULL, query_sz);
410
411 if ((p= strstr(srcdef, "%s")))
412 {
413 /* Replace %s with 1=1 */
414 snprintf(query, query_sz, "%.*s1=1%s",
415 (int) (p - srcdef), srcdef, p + 2); // dummy where clause
416 }
417 else
418 safe_strcpy(query, query_sz, srcdef);
419
420 if (!strnicmp(srcdef, "select ", 7))
421 safe_strcat(query, query_sz, " LIMIT 0");
422
423 } else
424 query = (char *)srcdef;
425
426 // Open a MySQL connection for this table
427 if (myc.Open(g, host, db, user, pwd, port))
428 return NULL;
429
430 // Send the source command to MySQL
431 if (myc.ExecSQL(g, query, &w) == RC_OK)
432 qrp = myc.GetResult(g, true);
433
434 myc.Close();
435 return qrp;
436 } // end of SrcColumns
437
438/* -------------------------- Class MYSQLC --------------------------- */
439

Callers 1

Calls 7

PlugSubAllocFunction · 0.85
safe_strcpyFunction · 0.85
safe_strcatFunction · 0.85
ExecSQLMethod · 0.80
OpenMethod · 0.45
GetResultMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected