-
Notifications
You must be signed in to change notification settings - Fork 10
plugin developer guide murphy database
blah blah
Murphy DB components
blah blah
MQI_COLUMN_MAX |
the maximum number columns a table can have |
MQI_COND_MAX |
maximum length of a condition table (i.e. array of mqi_cond_entry_t) |
MQI_HANDLE_INVALID |
mqi_handle_t value for nonexisting handle. Zero is a valid handle thus casting a zero to mqi_handle_t will produce a valid handle (remeber this when using static mqi_handle_t). |
MQI_QUERY_RESULT_MAX |
maximum number of rows a query can produce |
MQI_TXDEPTH_MAX |
maximum depth for nested transactions |
mql_result_type_t - types of mql_result_t structure
mql_result_error |
error code + error message |
mql_result_dontcare |
will default |
mql_result_columns |
column description of a table |
mql_result_rows |
select'ed rows |
mql_result_string |
zero terminated ASCII string |
mql_result_list |
array of basic types, (integer, string, etc) |
mql_result_s - generic return type of MQL opertaions.
struct mql_result_s { mql_result_type_t type; uint8_t data[0]; };
Where
type |
type of the result |
data |
opaque result data |
mql_result_type_t is the generic return type of mql_exec_string() and mql_exec_statement(). It is either the return status of the MQL operation or the resulting data. For instance, executing an insert statement will return a status (ie. mql_result_error type), while the execution of a select statement will return the selected rows (ie. mql_result_rows or mql_result_string depending on what type was requested by mql_exec_string() or mql_exec_statement())
To access the opaque data use the mql_result_xxx() functions
mql_exec_file - execute a series of MQL statements stored in a file
int mql_exec_file``(const char *``file)
Where
file |
is the path of the file, eg. "~/mql/create_table.mql" |
This function is to execute a series of MQL statements stored in a file. The MQL statements supposed to separated with ';'. No ';' shall follow the last statement. In case of an error the the execution of the statements will stop, errno is set and the function will return -1. Error messages will be written to stderr. Currently there is no programmatic way to figure out what statement failed and how many statement were sucessfully executed.
If the execution failed mql_exec_file() returns -1 and errno is set. It returns 0 if all the statements in the file were successfully executed.
mql_exec_string - execute an MQL statement
mql_result_t *mql_exec_string``(mql_result_type_t ``result_type, const char *statement)
Where
result_type |
specifies the expected type of the returned result. However, if the execution failed for some reason the returned result will have mql_result_error type. |
statement |
is the string of the MQL statement to execute |
This function is to execute a single MQL statement. The result of the operation is returned in a data structure. The returned result can be either the type of the requested result or an error result. It is recommended that the returned result will be checked first by calling mql_result_is_success() function.
To process a result the relevant mql_result_xxx() functions are to use. Values returned by the mql_result_xxx() functions are valid till the next MQL commit or rollback. For instance accessing the returned strings after a commit might lead to segfaults.
The returned result should be freed by mql_result_free().
#include <stdio.h>
#include <murphy-db/mql.h>
const char *statement = "SELECT * FROM persons WHERE name = 'murphy'";
mql_result_t *r = mql_exec_string(mql_result_type_string, statement);
if (mql_result_is_success(r))
printf("the result of the query:\n%s\n", r->mql_result_string_get(r));
blah blah
whitespace = 1*(SP / HTAB / CRLF)
SHOW = "SHOW"
BEGIN = "BEGIN"
COMMIT = "COMMIT"
ROLLBACK = "ROLLBACK"
TRANSACTION = "TRANSACTION"
TRANSACTIONS = "TRANSACTIONS"
CREATE = "CREATE"
UPDATE = "UPDATE"
REPLACE = "REPLACE"
DELETE = "DELETE"
DROP = "DROP"
DESCRIBE = "DESCRIBE"
TABLE = "TABLE"
TABLES = "TABLES"
INDEX = "INDEX"
ROWS = "ROWS"
COLUMN = "COLUMN"
TRIGGER = "TRIGGER"
INSERT = "INSERT"
SELECT = "SELECT"
INTO = "INTO"
FROM = "FROM"
WHERE = "WHERE"
VALUES = "VALUES"
SET = "SET"
ON = "ON"
IN = "IN"
OR = "OR"
PERSISTENT = "PERSISTENT"
TEMPORARY = "TEMPORARY"
CALLBACK = "CALLBACK"
VARCHAR = "VARCHAR"
INTEGER = "INTEGER"
UNSIGNED = "UNSIGNED"
REAL = "REAL"
BLOB = "BLOB"
parameter = "%" ("s" / "d" / "u" / "f")
not_squote = ALPHA / DIGIT / %x20-26 / %x28-2f / %x3a /
%x3c-40 / %x5b-60 / %x7b-7e
not_dquote = ALPHA / DIGIT / %x20-21 / %x23-2f / %x3a /
%x3c-40 / %x5b-60 / %x7b-7e
number = 1*DIGIT
floating = DIGIT "." *DIGIT
identifier = ALPHA *(*(ALPHA / DIGIT / "_" / "-") (ALPHA /
DIGIT))
quoted_string = ("'" *NOT_SQUOTE "'") / (DQUOTE *NOT_DQUOTE
DQUOTE)
statement_list = statement *(";" statement)
statement = show_statement / create_statement /
drop_statement / begin_statement /
commit_statement / rollback_statement /
describe_statement / insert_statement /
update_statement / delete_statement /
select_statement / error
show_statement = SHOW [PERSISTENT / TEMPORARY] TABLES
create_statement = create_table_statement / create_index_statement
/ create_trigger_statement
create_table_statement = CREATE [PERSISTENT / TEMPORARY] TABLE identifier
"(" column_defs ")"
create_index_statement = CREATE INDEX ON identifier "(" column_list ")"
create_trigger_statement = create_transaction_trigger /
create_table_trigger / create_row_trigger /
create_column_trigger
column_defs = column_def *("," column_def)
column_def = identifier column_type
column_type = VARCHAR "(" number ")" / INTEGER / UNSIGNED /
floating / BLOB "(" number ")"
create_transaction_trigger = CREATE TRIGGER identifier ON TRANSACTIONS
CALLBACK identifier
create_table_trigger = CREATE TRIGGER identifier ON TABLES CALLBACK
identifier
create_row_trigger = CREATE TRIGGER identifier ON ROWS IN identifier
CALLBACK identifier SELECT ("*" / column_list)
create_column_trigger = CREATE TRIGGER identifier ON COLUMN identifier
IN identifier CALLBACK identifier [SELECT ("*" /
column_list)]
drop_statement = drop_table_statement / drop_index_statement
drop_table_statement = DROP TABLE identifier
drop_index_statement = DROP INDEX identifier
begin_statement = BEGIN [TRANSACTION] identifier
commit_statement = COMMIT [TRANSACTION] identifier
rollback_statement = ROLLBACK [TRANSACTION] identifier
describe_statement = DESCRIBE identifier
insert_statement = (INSERT [OR REPLACE] INTO / REPLACE INTO)
identifier ["(" column_list ")"] VALUES "("
input_value_list ")"
input_value_list = input_value *("," input_value)
update_statement = UPDATE identifier SET assignment_list [WHERE
conditional_expression]
assignment_list = assignment *("," assignment)
assignment = identifier "=" input_value
delete_statement = DELETE FROM identifier [WHERE
conditional_expression]
select_statement = SELECT ("*" / column_list) FROM identifier
[WHERE conditional_expression]
column_list = identifier *("," identifier)
input_value = quoted_string / ("+" / "-") number / number /
(floating / ("+" / "-") floating) / parameter
conditional_expression = relational_expression / relational_expression
("&" / "|") relational_expression
relational_expression = value ("<" / "<=" / "=" / ">=" / ">") value
value = identifier / quoted_string / ("+" / "-") number
/ number / floating_value / parameter / "("
conditional_expression ")" / "!" value