66 Commits

Author SHA1 Message Date
Johan Wikman
a925be4e2a Turn off error in qc_sqlite built
GCC on CentOS6 thinks there is an array-bounds error in the sqlite
code. As that code is outside our hands, it is easiest to instruct
GCC not to treat it as an error.
2017-03-08 17:18:06 +02:00
Johan Wikman
07ae37f179 Update commit/rollback rules
Now that WORK is recognized as a parser token, the BEGIN and regular
COMMIT and ROLLBACK rules should use them as well.
2017-03-07 11:49:30 +02:00
Johan Wikman
a6ae60c808 Merge branch '2.0' into 2.1 2017-03-07 11:45:49 +02:00
Markus Mäkelä
dd07feda07 MXS-1025: Parse SAVEPOINT statements
The various forms of the SAVEPOINT/RELEASE/ROLLBACK statements are now
fully parsed.
2017-03-07 08:44:21 +02:00
Johan Wikman
d834c1bbdc Compile sqlite explicitly in single thread mode
As every thread has a separate (in-memory) database, i.e. not
just a separate _connection_, sqlite can be compiled in singe-thread
mode, which means that there will be *no* locking.
2017-02-27 10:39:20 +02:00
Johan Wikman
5648f708af Update license to BSL 1.1 2017-02-14 21:42:28 +02:00
Johan Wikman
8aa76727d2 Remove explicit long indicator of size defines 2017-01-19 10:42:05 +02:00
Johan Wikman
16a76fcd28 Rename qc_get_type() to qc_get_type_mask()
To make it plain that it is a mask that is returned and not a
specific value from the enum qc_query_type_t.
2017-01-18 08:34:53 +02:00
Johan Wikman
ded9f668f1 QC: Parse statements in COM_STMT_PREPARE packets 2017-01-18 08:34:53 +02:00
Markus Mäkelä
3d92263cb3 Format query classifier modules
Formatted query classifier modules with Astyle.
2017-01-17 14:48:43 +02:00
Johan Wikman
cc6a3e629e Implement qc_get_preparable_stmt
Now returns the preparable statement as a GWBUF on which the
other qc-functions can be used.
2017-01-17 10:10:38 +02:00
Johan Wikman
8a95a0f045 Remove qc_get_prepare_operation
Since the whole preparable statement will be available, it is
superfluous to provide a function using which the operation of
the preparable statement can be obtained.
2017-01-17 10:10:38 +02:00
Johan Wikman
e349319400 Add qc_get_preparable_stmt
This function will return the preparable statement of a PREPARE
statement as a COM_QUERY GWBUF. That is, once obtained, the normal
query classifier functions can be used for obtaining information
about the preparable statement itself.
2017-01-17 10:10:38 +02:00
Johan Wikman
7fee90a399 Streamline query classifier API interface
- Only types of fixed size used in API interface
- The actual function return value specifies whether the parsing
  process succeeded, while "logical" return values are returned
  as out arguments.

The wrapper function currently ignores the function return value.
2017-01-17 10:10:38 +02:00
Johan Wikman
0ce7632f57 QC: Remove qc_is_real_query
Not used.
2017-01-16 14:17:56 +02:00
Johan Wikman
2fa12f796b Rename MYSQL_GET_PACKET_LEN to MYSQL_GET_PAYLOAD_LEN
The function returns the length of the payload, not the length of
the entire packet.
2017-01-12 14:24:14 +02:00
Johan Wikman
482fbe6400 qc: Implement qc_get_function_info for qc_mysqlembedded
MXS-1070

Now both qc_mysqlembedded and qc_sqlite return the same stuff
for the same statement, and both include also operators in
addition to pure functions. Whether that is the right approach,
is still subject to debate.

However, if we want to make it possible to disable e.g. the
use of concat as in "select concat(a) from t", where a is a string,
to prevent the bypassing of the masking filter, then conceptually
it should be possible to prevent "select a+0 from t", where a is an
int, as well.
2017-01-09 09:17:38 +02:00
Johan Wikman
0d561df880 QC: Implement qc_get_function_info for qc_sqlite 2017-01-09 09:17:38 +02:00
Johan Wikman
d078f56dc5 qc: Reveal function usage
MXS-1070

Just interface changes. Implementation follow in separate changes.
2017-01-09 09:17:38 +02:00
Johan Wikman
8fc5bdc2f1 Perform query classifier initialization implicitly
The setting up and the initialization of the query classifier has
now been separated. The gateway explicitly sets up the query
classifier (i.e. chooses which one to use and what arguments to
provide), but the actual initialization is performed as part of
the general module initialization.
2017-01-09 09:16:35 +02:00
Johan Wikman
530c0e9617 QC: Setup and initialization separated
This is in preparation for using the general process/thread
initialization mechanism.
2017-01-09 09:16:35 +02:00
Johan Wikman
a2a38f952a Add [process|thread] [init|finish] functions to modules
The MXS_MODULDE object now contains optinal pointers for functions
to be called att process and thread startup and shutdown. Since the
functions were added to the end, strictly speaking, all structures
would not have needed to have been modified, but better to be
explicit. In a subsequent change, these will be called.

C++ does not support flexible arrays, so for the time being C++
modules are restricted to 10 parameters. Better approach is to
factor out the parameters to a separate array and then just store
a pointer to that array in MXS_MODULE.
2017-01-05 14:44:02 +02:00
Markus Mäkelä
2a4714500f Fix the symbols exported by query classifiers
The query classifiers only export the needed symbols and these weren't
adjusted to the changes in the entry point names.
2017-01-03 19:16:56 +02:00
Markus Mäkelä
c96bd64aa8 Rename MODULE_INFO to MXS_MODULE
The MODULE_INFO is now the main object which is used by modules to convey
information to the MaxScale core. The MXS_MODULE name is more apt as it
now contains the actual module definition.

The old MODULES structure was moved into load_utils.c as an internal
implementation and was renamed so that it is not confused with the new
MODULE structure.
2017-01-03 18:01:14 +02:00
Markus Mäkelä
b00e0328d5 Create a macro for module declarations
The modules are now declared with a common macro. This allows future
additions to the module loading process while also making the loaded
symbol name a constant.
2017-01-03 18:01:13 +02:00
Markus Mäkelä
ae0577c695 Move module object inside MODULE_INFO
This allows modules to only expose one entry point with a consistent
signature. In the future, this could be used to implement declarations of
module parameters.
2017-01-03 18:01:13 +02:00
Markus Mäkelä
6c53999c97 Combine ModuleInit and GetModuleObject
The two functions can be combined into one as both are called only
once. This removes the need for the explicit ModuleInit function.
2017-01-03 18:01:13 +02:00
Markus Mäkelä
7df29aa1ec Move version entry point into MODULE_INFO
The MODULE_INFO can easily hold the version information of the
module. This removes the need for a explicit version entry point.
2017-01-03 18:01:13 +02:00
Johan Wikman
ebca707335 QC: Always set number of returned items
qc_get_table_names() and qc_get_database_names() now always set
the number items, also in case of error. That is, it is now always
safe to start iterating using the number of items without first
checking the returned pointer.
2016-12-09 13:06:26 +02:00
Johan Wikman
994299b4f1 MXS-1043: Handle @@identity like @@last_insert_id
The type of @@identity, @@last_insert_id and last_insert_id() is
now the same, that is, QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ.
2016-12-02 11:38:27 +02:00
Johan Wikman
0218ac9e9c MXS-1043: Handle @@identity like @@last_insert_id
The type of @@identity, @@last_insert_id and last_insert_id() is
now the same, that is, QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ.
2016-12-02 11:35:50 +02:00
Johan Wikman
d9642dd5ae MXS-1025: All logging now behing the log_level
Earlier a successful parsing but failure to classify was always
logged.
2016-11-23 14:47:24 +02:00
Johan Wikman
8572eb34a0 qc_sqlite: Dequote more properly
When a backslash is encountered, the backslash should not be
copied but only the character after that.

For the sake of completeness, a few more characters would have
to be handled explicitly, but as the content of a string will not
affect the statement's classification there is not much point in
doing that.
2016-11-22 19:11:21 +02:00
Johan Wikman
9e4ee0323d Merge branch '2.0' into develop 2016-11-21 12:23:30 +02:00
Johan Wikman
ecb6680e71 MXS-976: qc_sqlite: Force initialization of sqlite3
Sqlite3 performs some lazy initialization, during which it internally
parses some SQL statements of its own. Earlier there was detection code
for noticing that, but it was costly and errorprone.

Now, sqlite3 is forced to perform the initialization at startup so that
we no longer need any detection code.
2016-11-18 16:04:26 +02:00
Johan Wikman
59ee5a78c9 MXS-969: Report user var modifications properly
User variable modifications are now reported as QUERY_TYPE_USERVAR_WRITE
and not as QUERY_TYPE_GSYSVAR_WRITE as earlier.
2016-11-16 15:26:06 +02:00
Markus Makela
3c15b58891 Merge branch '2.0' into develop-2.0-merge 2016-11-15 00:09:24 +02:00
Johan Wikman
15e9652c46 qc: Provide information about field usage
Together with the field names, now qc_get_field_info also returns
field usage information, that is, in what context a field is used.
This allows, for instance, the cache to take action if a a particular
field is selected (SELECT a FROM ...), but not if it is used in a
GROUP BY clause (...GROUP BY a).

This caused a significant modifications of qc_mysqlembedded that
earlier did not walk the parse-tree, but instead looped over of a
list of st_select_lex instances that, the name notwithstanding,
also contain information about other things but SELECTs. The former
approach lost all contextual information, so it was not possible
to know where a particular field was used.

Now the parse tree is walked, which means that the contextual
information is known, and thus the field usage can be updated.
2016-11-14 09:35:16 +02:00
Johan Wikman
bf62f8950a Remove qc_get_affected_fields
Function is no longer used and it was quite unoptimal, so now
removed.

qc_get_prepare_name, qc_get_prepare_operation and qc_get_field_info
that were missing from qc_dummy added at the same time.
2016-11-07 12:28:58 +02:00
Johan Wikman
add7577f08 MXS-884: Update exclusion code 2016-11-07 10:10:26 +02:00
Johan Wikman
ac4999ec76 qc_sqlite: Only exclude exact match
When checking whether a name should be excluded, there may be a match
only if the name checked against is not a qualified name.
2016-11-07 10:10:26 +02:00
Johan Wikman
75509a67d4 qc: Do not collect HAVING names
A HAVING clause can only refer to names that already have been mentioned
or if "SELECT *" is used. Either way, the HAVING names need not be separately
collected.
2016-11-07 10:10:26 +02:00
Johan Wikman
fa5a858582 MXS-884: Implement qc_get_fields_infos.
We now collect more information about a particular field and
then, if necessary, copy the data over into affected_fields if
someone is interested in that.

The comparison program is extended as well, but qc_get_fields_infos()
is not tested, because qc_mysqlembedded does not implement this yet.
2016-11-07 10:10:26 +02:00
Johan Wikman
c652f1330a qc: Add qc_get_field_info
This function returns more detailed information about the fields
of a statement. Supersedes qc_get_affected_fields() that will
be deprecated and removed.

Note that this function now introduced new kind of behaviour; the
returned data belongs to the GWBUF and remains valid for as long as
the GWBUF is alive. That means that unnecessary copying need not
be done.
2016-11-02 15:50:21 +02:00
Johan Wikman
f7c3150462 qc_sqlite: Copy preparable statement
Peeking into the token does not always work.
2016-11-01 12:11:56 +02:00
Johan Wikman
91e36ecaed Make PREPARE operation explicit
The operation of the statement to be prepared is no longer
reported as the operation of the PREPARE statement.

Instead, when the type of the statement is
QUERY_TYPE_PREPARE_NAMED_STMT, the operation can be obtained
using qc_get_prepare_operation().

The qc_mysqlembedded implementation will be provided in a
subsequent commit.
2016-10-31 13:44:48 +02:00
Johan Wikman
b76cdfd367 qc_sqlite: Pick out prepare name in DEALLOCATE stmt 2016-10-26 21:00:54 +03:00
Johan Wikman
cbef9b944d qc_sqlite: Pick out the name in an EXECUTE stmt 2016-10-26 20:47:40 +03:00
Johan Wikman
50db0db316 MXS-934: Set operation of PREPARE statement
The operation of a PREPARE statement will be that of the preparable
statement. That will make it possible to know whether an EXECUTEd
prepared statement e.g. is a SELECT or an UPDATE.
2016-10-26 20:11:26 +03:00
Johan Wikman
23fdf1776c qc: Pick out the name in a PREPARE statement 2016-10-26 14:42:25 +03:00