MXS-2026 Use qc_init(...)/qc_end()
Use qc_init(...)/qc_end() for initializing QC in test-programs.
This commit is contained in:
@ -44,9 +44,7 @@ int main()
|
|||||||
|
|
||||||
set_libdir(strdup("../qc_sqlite"));
|
set_libdir(strdup("../qc_sqlite"));
|
||||||
|
|
||||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL) &&
|
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
|
||||||
qc_process_init(QC_INIT_BOTH) &&
|
|
||||||
qc_thread_init(QC_INIT_BOTH))
|
|
||||||
{
|
{
|
||||||
const char s[] = "SELECT @@global.max_allowed_packet";
|
const char s[] = "SELECT @@global.max_allowed_packet";
|
||||||
|
|
||||||
@ -58,7 +56,7 @@ int main()
|
|||||||
// code generator.
|
// code generator.
|
||||||
qc_parse(stmt, QC_COLLECT_ALL);
|
qc_parse(stmt, QC_COLLECT_ALL);
|
||||||
|
|
||||||
qc_process_end(QC_INIT_BOTH);
|
qc_end();
|
||||||
|
|
||||||
rv = EXIT_SUCCESS;
|
rv = EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,16 +131,11 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
set_libdir(strdup(LIBDIR));
|
set_libdir(strdup(LIBDIR));
|
||||||
|
|
||||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, QC_LIB, NULL))
|
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, QC_LIB, NULL))
|
||||||
{
|
{
|
||||||
if (qc_process_init(QC_INIT_BOTH) && qc_thread_init(QC_INIT_BOTH))
|
rc = test();
|
||||||
{
|
|
||||||
rc = test();
|
qc_end();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "error: Could not perform process/thread initialization for " << QC_LIB << "." << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,10 +31,12 @@ using std::endl;
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
int rc = EXIT_FAILURE;
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
{
|
{
|
||||||
cout << "Usage: canonizer <input file> <output file>" << endl;
|
cout << "Usage: canonizer <input file> <output file>" << endl;
|
||||||
return 1;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT);
|
mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT);
|
||||||
@ -43,7 +45,7 @@ int main(int argc, char** argv)
|
|||||||
if (!utils_init())
|
if (!utils_init())
|
||||||
{
|
{
|
||||||
cout << "Utils library init failed." << endl;
|
cout << "Utils library init failed." << endl;
|
||||||
return 1;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_libdir(strdup("../../../../query_classifier/qc_sqlite/"));
|
set_libdir(strdup("../../../../query_classifier/qc_sqlite/"));
|
||||||
@ -51,43 +53,46 @@ int main(int argc, char** argv)
|
|||||||
set_langdir(strdup("."));
|
set_langdir(strdup("."));
|
||||||
set_process_datadir(strdup("/tmp"));
|
set_process_datadir(strdup("/tmp"));
|
||||||
|
|
||||||
qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL);
|
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
|
||||||
qc_process_init(QC_INIT_BOTH);
|
|
||||||
qc_thread_init(QC_INIT_BOTH);
|
|
||||||
|
|
||||||
std::ifstream infile(argv[1]);
|
|
||||||
std::ofstream outfile(argv[2]);
|
|
||||||
|
|
||||||
if (!infile || !outfile)
|
|
||||||
{
|
{
|
||||||
cout << "Opening files failed." << endl;
|
std::ifstream infile(argv[1]);
|
||||||
return 1;
|
std::ofstream outfile(argv[2]);
|
||||||
}
|
|
||||||
|
|
||||||
for (std::string line; getline(infile, line);)
|
if (infile && outfile)
|
||||||
{
|
|
||||||
while (*line.rbegin() == '\n')
|
|
||||||
{
|
{
|
||||||
line.resize(line.size() - 1);
|
for (std::string line; getline(infile, line);)
|
||||||
|
{
|
||||||
|
while (*line.rbegin() == '\n')
|
||||||
|
{
|
||||||
|
line.resize(line.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!line.empty())
|
||||||
|
{
|
||||||
|
size_t psize = line.size() + 1;
|
||||||
|
mxs::Buffer buf(psize + 4);
|
||||||
|
auto it = buf.begin();
|
||||||
|
*it++ = (uint8_t)psize;
|
||||||
|
*it++ = (uint8_t)(psize >> 8);
|
||||||
|
*it++ = (uint8_t)(psize >> 16);
|
||||||
|
*it++ = 0;
|
||||||
|
*it++ = 3;
|
||||||
|
std::copy(line.begin(), line.end(), it);
|
||||||
|
char* tok = qc_get_canonical(buf.get());
|
||||||
|
outfile << tok << endl;
|
||||||
|
free(tok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Opening files failed." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!line.empty())
|
qc_end();
|
||||||
{
|
|
||||||
size_t psize = line.size() + 1;
|
|
||||||
mxs::Buffer buf(psize + 4);
|
|
||||||
auto it = buf.begin();
|
|
||||||
*it++ = (uint8_t)psize;
|
|
||||||
*it++ = (uint8_t)(psize >> 8);
|
|
||||||
*it++ = (uint8_t)(psize >> 16);
|
|
||||||
*it++ = 0;
|
|
||||||
*it++ = 3;
|
|
||||||
std::copy(line.begin(), line.end(), it);
|
|
||||||
char* tok = qc_get_canonical(buf.get());
|
|
||||||
outfile << tok << endl;
|
|
||||||
free(tok);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qc_process_end(QC_INIT_BOTH);
|
return rc;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -186,9 +186,7 @@ int main(int argc, char* argv[])
|
|||||||
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
|
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
|
||||||
|
|
||||||
// We have to setup something in order for the regexes to be compiled.
|
// We have to setup something in order for the regexes to be compiled.
|
||||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)
|
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
|
||||||
&& qc_process_init(QC_INIT_BOTH)
|
|
||||||
&& qc_thread_init(QC_INIT_BOTH))
|
|
||||||
{
|
{
|
||||||
Tester tester(verbosity);
|
Tester tester(verbosity);
|
||||||
|
|
||||||
@ -218,8 +216,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qc_thread_end(QC_INIT_BOTH);
|
qc_end();
|
||||||
qc_process_end(QC_INIT_BOTH);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -423,9 +423,7 @@ int main(int argc, char* argv[])
|
|||||||
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
|
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
|
||||||
|
|
||||||
// We have to setup something in order for the regexes to be compiled.
|
// We have to setup something in order for the regexes to be compiled.
|
||||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)
|
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
|
||||||
&& qc_process_init(QC_INIT_BOTH)
|
|
||||||
&& qc_thread_init(QC_INIT_BOTH))
|
|
||||||
{
|
{
|
||||||
rc = EXIT_SUCCESS;
|
rc = EXIT_SUCCESS;
|
||||||
|
|
||||||
@ -451,8 +449,7 @@ int main(int argc, char* argv[])
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
qc_thread_end(QC_INIT_BOTH);
|
qc_end();
|
||||||
qc_process_end(QC_INIT_BOTH);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -397,15 +397,12 @@ int main()
|
|||||||
pConfig->n_threads = 1;
|
pConfig->n_threads = 1;
|
||||||
|
|
||||||
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
|
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
|
||||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", "")
|
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", ""))
|
||||||
&& qc_process_init(QC_INIT_BOTH)
|
|
||||||
&& qc_thread_init(QC_INIT_BOTH))
|
|
||||||
{
|
{
|
||||||
set_libdir(MXS_STRDUP_A("../"));
|
set_libdir(MXS_STRDUP_A("../"));
|
||||||
rc = test();
|
rc = test();
|
||||||
|
|
||||||
qc_thread_end(QC_INIT_BOTH);
|
qc_end();
|
||||||
qc_process_end(QC_INIT_BOTH);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -112,8 +112,7 @@ int main(int argc, char **argv)
|
|||||||
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
|
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
|
||||||
load_module("qc_sqlite", MODULE_QUERY_CLASSIFIER);
|
load_module("qc_sqlite", MODULE_QUERY_CLASSIFIER);
|
||||||
|
|
||||||
qc_setup(NULL, QC_SQL_MODE_DEFAULT, NULL, NULL);
|
qc_init(NULL, QC_SQL_MODE_DEFAULT, NULL, NULL);
|
||||||
qc_process_init(QC_INIT_BOTH);
|
|
||||||
hkinit();
|
hkinit();
|
||||||
|
|
||||||
CONFIG_CONTEXT ctx{(char*)""};
|
CONFIG_CONTEXT ctx{(char*)""};
|
||||||
|
|||||||
Reference in New Issue
Block a user