Connection and Disconnection
machbase.open(aHost, aUser, aPw, aPort)
This is a function to connect to Machbase. When the appropriate parameter value is input, it returns whether connection to the DB is successful or failed. Returns 1 on success and 0 on failure.
This is a function to close the Machbase connection. Returns 1 on success and 0 on failure.
This is a function that determines whether the declared class is connected to the server. Returns 1 when connected and 0 when not connected.
Executing Commands and User Convenience Functions
This is a command to send a query to the server when it is connected to the server. It returns 1 when it is normally executed, and 0 when it fails or an error occurs.
You can use any command except UPDATE which is not supported by Machbase.
machbase.append(aTableName, aTypes, aValues, aFormat)
This is a function that can use Append protocol supported by Machbase.
Append can be executed by inputting the table name, the dictionary of the type of each column, and the values to input in JSON format and specifying dateformat.
Returns 1 if executed normally, 0 otherwise.
Returns information about all tables in the connected server. Returns 1 if successful; 0 if unsuccessful.
Returns information about the columns in the corresponding table on the connected server. Returns 1 if successful; 0 if unsuccessful.
In the Machbase Python module, all result values are returned in JSON.
It is adopted to return the result in a form that is easy to use in various environments.
The functions described above do not represent the execution results as the return value of the function, but only return success or failure. The result of a function can be obtained only by the return value of this function.
Let's see how to use the Machbase Python module with simple examples.
You can check using $MACHBASE_HOME/sample/python files. The directory has a Makefile that makes it easy to test and a MakeData.py file that creates the data. Make sure that the value of PYPATH in the Makefile is set to Python with the Machbase Python module installed. The default is specified in Python installed in the Machbase package. Also, you need to make __init__.py file to execute the module in Python independently, so make sure that the file exists in that directory.
The following example is a simple function that connects to the server, executes the query, and returns the result. If each function returns a failure value (0), it returns an error result. If successful, the number of values in the m $ tables table is returned.
The file name is Sample1Connect.py.
Using the example below, we simply create a table using Python in Machbase, input the value, and extract the input value to check. The file name is Sample2Simple.py.
Append method to input data at high speed in Machbase can also be used by using Python module. The following example shows how to input data at high speed. We used a method of declaring a connection class db2 for the column information and initialization, and a connection class db2 for the Append, and using each function. The file name is Sample3Append.py.