If the Machbase package was installed, the sample program will be installed in the following path.
Compile and Link
Executing the following for a given sample creates an executable file.
You can write your application as necessary by modifying the sample Makefile above.
We will create an example program to connect using the CLI.
The sample file name is sample1_connect.c.
MACHBASE_PORT_NO must be the same as the PORT_NO value in the $MACHBASE_HOME/conf/machbase.conf file.
If you register sample1_connect.c in Makefile, compile and run it, it will appear as follows.
Data Input and Output Example
In the example source below, we created a table using the CREATE TABLE statement, arbitrarily create simple data values, input data using the INSERT statement, and output the data using the SELECT statement. You will be able to see how to configure each type when entering and checking values directly.
The sample file name is sample2_insert.c.
If you register sample2_insert.c in the Makefile, compile and run it, it will appear as follows.
Prepare Execute Example
Let's write an example program that binds and INSERTs data.
You can enter a value by binding data in Machbase. When you use this, you need to specify the types of data values clearly. In case of long string types, you must specify the length value.
The following example shows how to bind data for each type.
The file name is sample3_prepare.c.
If you register sample3_prepare.c in the Makefile, compile and run it, it will appear as follows.
Extension Function Append Example
In Machbase, the append protocol is provided by reading a large amount of data from a file and inputting it at a high speed. Let's write an example program that uses this Append protocol.
First, let's look at an example of how to append to the various types provided by Machbase. The Append method has its own settings for each type. Therefore, if you know how to use every method, you will be able to write programs more efficiently. All the methods are listed in the example code at the bottom.
The file name is sample4_append1.c.
If you register sample4_append1.c in the Makefile, compile and run it, it will appear as follows.
Now let's use a fast append method using a file. This is an example useful for fast input of large amounts of logs, packets, etc. used in business. The file name is sample4_append2.c.
You have to save the data to be entered in advance in data.txt.
Modifying the given make_data.c gives you the opportunity to create a data.txt file for your situation.
If you register sample4_append2.c in the Makefile, compile and run it, it will appear as follows.
Acquiring Table Column Information Example
There are a number of ways to obtain table column information, but we will look at how to use SQLDescribeCol and SQLColumns.
SQLDescribeCol is a function that retrieves the number, name, buffer size, length, and type of table columns.
The sample file name is sample5_describe.c.
If you add the above file and run make, you can see the contents of the column as shown below.
SQLColumns is a function that can find the information of the columns existing in the current table. Machbase also supports the above functions and can be used to find out the information of each column.
The file name is sample6_columns.c.
Add the above file and run make. The results are as follows.Multi-Thread Append Example
An example of using multiple threads in one program to append to multiple tables.
The file name is sample8_multi_session_multi_table.c.
Add the make code and run the executable file. Because the threads are used, the output order may be different. The results are as follows.
You can see the result through machsql as below.