Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

murphy db

Janos Kovacs edited this page May 1, 2012 · 4 revisions

Murphy Database

Overview

db-layers.png

Murphy DB components

Low level API

High Level API

Preprocessor Definitions

MQI_BIT ::
#define MQI_BIT (((mqi_bitfld_t)1) << (b))
MQI_COLUMN_AUTOINCR ::
#define MQI_COLUMN_AUTOINCR (1UL << 1)
MQI_COLUMN_KEY ::
#define MQI_COLUMN_KEY (1UL << 0)
MQI_COLUMN_MAX ::
#define MQI_COLUMN_MAX ((int)(sizeof(mqi_bitfld_t) * 8))
MQI_COND_MAX ::
#define MQI_COND_MAX 64
MQI_DIMENSION ::
#define MQI_DIMENSION (sizeof(array) / sizeof(array[0]))
MQI_HANDLE_INVALID ::
#define MQI_HANDLE_INVALID (~((mqi_handle_t)0))
MQI_OFFSET ::
#define MQI_OFFSET ((int)((void *)((&((structure *)0)->member)) - (void *)0))
MQI_QUERY_RESULT_MAX ::
#define MQI_QUERY_RESULT_MAX 8192
MQI_TXDEPTH_MAX ::
#define MQI_TXDEPTH_MAX 16
MQL_BINDABLE ::
#define MQL_BINDABLE (1 << (MQL_BIND_INDEX_BITS + 0))
MQL_BIND_INDEX ::
#define MQL_BIND_INDEX ((v) & MQL_BIND_INDEX_MASK)
MQL_BIND_INDEX_BITS ::
#define MQL_BIND_INDEX_BITS 8
MQL_BIND_INDEX_MASK ::
#define MQL_BIND_INDEX_MASK (MQL_BIND_INDEX_MAX - 1)
MQL_BIND_INDEX_MAX ::
#define MQL_BIND_INDEX_MAX (1 << MQL_BIND_INDEX_BITS)
MQL_PARAMETER_MAX ::
#define MQL_PARAMETER_MAX 16

Type definitions

Enumerations

Structures and Unions

Functions

mql_exec_file()

SYNOPSIS
int mql_exec_file(const char *file)

mql_exec_file() execute a series of MQL statements stored in a file

DESCRIPTION

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.

mql_exec_string()

SYNOPSIS
mql_result_t* mql_exec_string(mql_result_type_t result_type, const char *statement)

mql_exec_string() execute an MQL statement

DESCRIPTION

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().

mql_precompile()

SYNOPSIS
mql_statement_t* mql_precompile(const char *statement)

mql_precompile() precompile an MQL statement

DESCRIPTION

statement is the string of the MQL statement to execute

Precompilation is the parsing of the ASCII MQL statement, making all the necessary lookups, generating the data structures what the the underlying MQI interface needs for the execution and packing all these information into a dynamically allocated memory block.

mql_bind_value() can be used to assign values for parameters of the preecompiled statement, if any.

A precompiled statement can be executed by mql_exec_statement().

Precompiled statements should be freed by mql_statement_free() when they are not needed any more.

Murphy Query Language

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