Connection String for Connecting
CLI를 통해 접속을 하기 위해서는 연결 스트링을 만들어야 하며, 각각의 내용은 다음과 같다.
연결 스트링 항목명
항목 설명
DSN
데이터 소스 명을 지정한다.
ODBC에서는 리소스가 담긴 파일의 섹션 명을 기술하고, CLI에서는 서버명 혹은 IP 주소를 지정한다.
DBNAME
Machbase의 DB명을 기술한다.
SERVER
Machbase가 위치하는 서버의 호스트 명 혹은 IP 주소를 가리킨다.
NLS_USE
서로 사용할 언어 종류를 설정한다.(현재 사용되지 않으며, 차후 확장을 위해 유지한다.)
UID
사용자 아이디
PWD
사용자 패스워드
PORT_NO
접속할 포트 번호
PORT_DIR
유닉스에서 Unix domain으로 접속할 경우 사용되는 파일 경로를 지정한다.
(서버에서 수정했을 경우에 지정하며, 디폴트로는 지정하지 않아도 동작한다.)
CONNTYPE
클라이언트와 서버의 접속 방법을 지정한다.
1: TCP/IP INET 으로 접속
2: Unix Domain 으로 접속
COMPRESS
Append 프로토콜을 압축할 것인지 나타낸다.
이 값이 0일 경우에는 압축하지 않고 전송한다.
이 값이 0보다 큰 임의의 값일 경우에는 그 값보다 Append 레코드가 클 경우에만 압축한다.
예) COMPRESS=512
레코드 사이즈가 512보다 클 경우에만 압축하여 동작한다.
원격 접속일 경우 압축하면 전송 성능이 향상된다
To connect through the CLI, you need to create a connection string. The contents of each are as follows.
Connection String Item Name | Item Description |
---|---|
DSN | Specifies the data source name. ODBC specifies the section name of the file containing the resource, and CLI specifies the server name or IP address. |
DBNAME | Describes the DB name of Machbase. |
SERVER | Indicates the host name or IP address of the server where Machbase is located. |
NLS_USE | Sets the language type to use with each other (currently unused, kept for future expansion). |
UID | User ID |
PWD | User password |
PORT_NO | Port number to connect to |
PORT_DIR | Specifies the file path to use when connecting to a Unix domain from Unix. (It is specified when modified from the server, and it works even if it is not specified by default.) |
CONNTYPE | Specifies the connection method between the client and the server. 1: Connection with TCP / IP INET |
COMPRESS | Indicates whether to compress the Append protocol. If this value is 0, it is transmitted without compression. Ex) COMPRESS = 512 For remote connection, compression improves transmission performance. |
SHOW_HIDDEN_COLS | 숨겨진 컬럼Decides whether to show the hidden column (_arrival_time) 을 when executing it with select * 로 수행시 보여줄 것인지 결정한다.0일 경우에는 보이지 않으며, 1일 경우에 해당 컬럼의 정보가 출력된다. If it is 0, it is not shown. If it is 1, information of the corresponding column is output. |
CONNECTION_TIMEOUT | 최초 연결시에 얼마나 대기할 것이지 설정한다. 디폴트로는 30초가 설정되어 있다. 만일 최초 연결시 서버의 응답이 30초 보다 더 느려지는 경우를 고려하면, 이 값을 더 크게 설정해야 한다. CONNECTION_TIMEOUT에서 0 값은 Timeout에 제한이 없음을 의미하며 연결이 실패할 때에도 무한정으로 대기하므로 되도록이면 사용하지 않는 편이 좋다Sets how long to wait on the first connection. The default setting is 30 seconds. |
SOCKET_TIMEOUT | This is a timeout that occurs when Protocol I/O에 시간이 걸리면 발생하는 timeout이다. Client에서 검사하여 대기 후 Disconnect를 수행한다. ORACLE의 Read Timeout과 같다. (MYSQL, MSSQL에서는 동일하게 SOCKET_TIMEOUT이라는 이름으로 사용한다.) Connection String에서 O takes time. The client checks and waits , then performing Disconnect. Same as Read Timeout of ORACLE. (In MYSQL and MSSQL, uses SOCKET_TIMEOUT as same as Machbase.) Set SOCKET_TIMEOUT=NN (초)로 설정하며 기본값은 30분seconds) in Connection String, and the default value is set to 30 minutes (1800)으로 설정된다. |
ALTERNATIVE_SERVERS | cluster 버전을 사용 시, 여러 대의 브로커의 정보를 추가적으로 가지게 되는 설정이다. 다중의 브로커를 등록해두었을 시, 접속되어있던 브로커가 혹시 내려가게 된 경우에도 다른 브로커에 접속한 뒤, 입력하던 데이터를 계속해서 입력하게 된다. 여러개의 브로커를 등록할 수 있으며, <서버 주소>:<서버 포트>의 값을 ',' 단위로 이어서 작성한다When using the cluster version, it is a setting to have the information of several brokers additionally. When multiple brokers are registered, even if the connected broker is terminated, the data is continuously input after connecting to another broker. Multiple brokers can be registered, and the values of <server address>:<server port> are separated by commas. ex) ALTERNATIVE_SERVERS=192.168.0.10:20320,192.168.0.11:20320; |
CLI 접속 예제는 다음과 같다An example of CLI connection is as follows.
Code Block | ||
---|---|---|
| ||
sprintf(connStr,"SERVER=127.0.0.1;COMPRESS=512;UID=SYS;PWD=MANAGER;CONNTYPE=1;PORT_NO=%d", MACHBASE_PORT_NO); if (SQL_ERROR == SQLDriverConnect( gCon, NULL, (SQLCHAR *)connStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT )) { ... } |
Extension CLI
함수Function (APPEND)
CLI 확장 함수는 Machbase 서버에 데이터를 초고속으로 입력하기 위해 제공되는 Append 프로토콜을 구현하기 위한 함수이다.
이 함수는 크게 4가지의 함수로 구성되어 있는데, 채널의 오픈, 채널에 대한 데이터 입력, 채널의 플러쉬, 채널 클로징이다.
Append 프로토콜의 이해
Machbase에서 제공하는 Append 프로토콜은 비동기 방식으로 동작한다. 비동기라 함은 클라이언트가 서버에게 요청한 특정 작업에 대한 응답이 서로 완전히 동기화되지 않고, 임의의 이벤트가 발생하는 순간에 발생하는 것을 의미한다. 즉, 클라이언트가 Append를 수행했다고 하더라도, 그 수행에 대한 결과를 바로 얻거나 확인할 수 없으며, 서버에서 준비가 되는 임의의 시점에 그것을 확인할 수 있다는 것이다. 이런 이유로 Append 프로토콜을 활용해서 응용 프로그램을 개발하는 개발자는 다음과 같은 내부 동작에 대한 이해를 가져야 한다. 이후의 설명은 클라이언트가 언제 어떻게 서버에서 발생하는 비동기 에러를 검출하고 사용자에게 되돌여주는지에 대한 것이다.
Append 데이터의 전송
SQLExecute 혹은 SQLExecDirect()와 같은 일반적인 호출에서 Machbase는 즉시 그 결과를 클라이언트에게 되돌려주는 동기화 방식을 사용한다. 그러나, SQLAppendDataV2()는 사용자 데이터가 입력된 이후 즉시 요청을 보내지 않는다. 대신, 클라이언트 통신 버퍼가 모두 찰 때 까지 대기하고 있다가 모두 차면 그 이후에 한꺼번에 데이터를 클라이언트로 전송하게 된다. 이렇게 설계된 이유는 Append를 사용하는 클라이언트의 입력 데이터가 초당 수만에서 수십만 레코드를 가정하였기 때문에 고속의 데이터 전송을 위한 버퍼링 방식을 활용한 것이다. 이런 이유로 만일 사용자가 임의로 해당 버퍼의 내용을 전송하고자 할 경우에는 SQLAppendFlush() 함수를 호출하여, 명시적으로 데이터를 입력할 수 있다.
Append 데이터의 에러 확인
앞에서 언급한 바와 같이 Append 프로토콜은 버퍼링되어 비동기로 동작한다. 특히, 서버에서 에러가 발생하지 않았을 경우에는 아무런 응답을 받지 않고, 에러가 발생했을 경우에만 에러를 검출하는 방식을 취하기 때문에 에러가 언제 어떻게 검출되는지 이해하는 것이 매우 중요하다. 또한, 에러를 검출하는 비용이 상대적으로 매우 크기 때문에 레코드 입력시마다 매번 검사하는 것이 매우 비효율적으로 판단되어, 현재 Machbase에서는 명시적으로 다음과 같은 경우에만 에러를 검출하도록 되어 있다. 에러가 검출될 경우에는 사용자가 설정한 에러 콜백 함수를 매번 호출하게 된다.
전송 버퍼가 모두 차고, 서버에게 명시적으로 데이터를 전송한 이후 검사
SQLAppendFlush() 내부에서 서버에게 명시적으로 데이터를 전송한 이후 검사
SQLAppendClose() 내부에서 종료 직전에 검사
즉, 기본적으로 위의 3가지 경우에만 에러를 검출하도록 되어 있어, I/O의 발생을 최소화하도록 설계되었다.
서버 에러 검사를 위한 부가 옵션
성능을 최대한으로 달성하기 위해 기본적으로 설정된 에러 검출 기법은 사용자가 원하는 경우 좀 더 빈번하게 검사하고, 이를 활용할 수 있다. 즉, SQLAppendOpen() 함수의 마지막 인자인 aErrorCheckCount를 조절함으로서 가능한다. 이 값이 0일 경우에는 별도의 확인 동작을 하지 않고, 기본으로 동작한다. 그러나, 만일 이 값이 0보다 클 경우에는 SQLAppendData()의 호출 횟수마다 명시적으로 에러를 검사하도록 되어있다. 다시 말해 이 값이 10일 경우에는 10번의 Append 동작마다 에러를 검사하는 비용을 지불한다. 따라서, 이 값이 작을 경우에는 에러 검출을 위한 시스템 리소스를 많이 사용하기 때문에 적절한 숫자로 조절하여 사용해야 한다.
서버 에러 발생시 Trace 로그 남기기
만일 에러가 발생한 Append 데이터에 대해서 별도로 Trace 로그를 남기고자 할 경우에는 서버에 준비된 프로퍼티 DUMP_APPEND_ERROR 를 1로 설정한다. 이렇게 설정하면, mach.trc 파일에 해당 에러를 발생시킨 레코드에 대한 명세가 파일로 기록된다. 단, 에러의 횟수가 과도할 경우 시스템 리소스의 사용량이 급격히 늘어나, Machbase의 전체 성능을 떨어뜨릴 수 있으므로 주의하여 사용해야 한다.
APPEND 함수 설명The CLI extension function is a function for implementing the Append protocol provided to input data to the Machbase server at high speed.
This function consists of four functions: channel open, channel data input, channel flush, and channel closing.
Understanding Append Protocol
The Append protocol provided by Machbase works asynchronously. The term asynchronous means that the response to a specific job requested by the client to the server does not completely synchronize with each other but occurs at the moment when an arbitrary event occurs. That is, even if a client has performed an append, you can not immediately get or verify the results of that execution, and you can check it at any time when the server is ready. For this reason, developers who develop applications using the Append protocol should have an understanding of the following internal behaviors. The following discussion is about how and when a client detects asynchronous errors that occur in the server.
Append Data Transfer
In a typical call such as SQLExecute or SQLExecDirect (), Machbase uses a synchronous scheme that returns the results back to the client immediately. However, SQLAppendDataV2 () does not send a request immediately after user data is entered. Instead, it waits until all of the client communication buffers are full, and then it sends the data to the client all at once. The reason for this design is that the input data of the client using Append assumes tens to hundreds of thousands of records per second, so it utilizes the buffering method for high-speed data transmission. For this reason, if the user wants to transmit the contents of the buffer at will, the user can input data explicitly by calling SQLAppendFlush () function.
Append Data Error Check
As mentioned earlier, the Append protocol is buffered and operates asynchronously. In particular, it is very important to understand when and how an error is detected because it takes a method to detect an error only when an error occurs, without receiving any response when an error does not occur in the server. In addition, since the cost of detecting an error is relatively large, it is very inefficient to check each time a record is input, and currently Machbase is designed to detect an error only in the following cases explicitly. When an error is detected, the error callback function set by the user is called every time.
Checks after all the transmit buffers are full and the data has been explicitly sent to the server,
Checks after explicitly sending data to the server from within SQLAppendFlush ()
Checks just before shut down from within SQLAppendClose ()
In other words, it is basically designed to detect errors only in the above three cases, and is designed to minimize the occurrence of I/O.
Additional Options for Checking Server Errors
In order to achieve the maximum performance, the default error detection technique can be more frequently checked and utilized by the user if desired. This can be done by adjusting the last argument to the SQLAppendOpen () function, aErrorCheckCount. When this value is 0, it does not perform any checking operation and operates basically. However, if this value is greater than 0, SQLAppendData () is explicitly checked for errors every time it is called. In other words, if this value is 10, you pay the cost of checking for errors every 10 appends. Therefore, when this value is small, system resources for error detection are used much, so it should be adjusted to an appropriate number.
Leaving Trace Log When Server Error Occurs
If you want to leave a trace log for the append data where an error occurs, set the prepared property DUMP_APPEND_ERROR to 1 on the server. With this setting, the specification of the record that generated the error in the mach.trc file is written to the file. However, if the number of errors is excessive, the amount of system resources used will increase drastically, which may degrade the overall performance of Machbase.
APPEND Function Description
SQLAppendOpen
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendOpen(SQLHSTMT aStatementHandle, SQLCHAR *aTableName, SQLINTEGER aErrorCheckCount ); |
이 함수는 대상 테이블에 대한 채널을 오픈한다. 이후 이 채널을 닫아 주지 않으면 지속적으로 열린 상태가 유지된다.
하나의 연결에 대해 최대 1024개의 Statement 설정이 가능하다. 각 Statement마다 SQLAppendOpen을 사용하면 된다.
aStatementHandle : Append를 수행할 Statement의 핸들을 나타낸다.
aTableName : Append를 수행할 대상 테이블의 이름을 나타낸다.
This function opens a channel for the target table. If this channel is not closed afterwards, it is kept open continuously.
A maximum of 1024 statements can be set for one connection. You can use SQLAppendOpen for each statement.
aStatementHandle: Represents the handle of the Statement to be appended.
aTableName: Indicates the name of the table to which Append will be performed.
aErrorCheckCount: Decides whether to check the server for errors whenever several data are input. If this value is 0, no error is checked arbitrarily.
SQLAppendData (deprecated)
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendData(SQLHSTMT StatementHandle, void *aData[]); |
이 함수는 해당 채널에 대해 데이터를 입력하는 함수이다.
This function is a function that inputs data for the channel.
- aData is an array containing pointers to the data to be input. The number of arrays must match the number of columns held by the table specified at Open.
- The return value can be SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, or SQL_ERROR가 가능하다ERROR.
특히In particular, if SQL_SUCCESS_WITH_INFO가 반환되었을 경우에는 입력된 특정 컬럼의 길이가 길어 잘리는 등의 오류가 있을 수 있으므로 결과를 다시 확인하여야 한다.
데이터 타입에 따른 설정
숫자형 및 문자형
- INFO is returned, there may be errors such as a lengthy input column being truncated, so check the result again.
Configuration According to Data Type
Numeric and character types
- Types such as float, double, short, int, long long, char * 과 같은 타입은 해당 값에 대한 포인터 설정 만으로 잘 동작한다.
주소형
- ipv4 의 경우에는 5 바이트 무부호 문자(unsigned char)의 배열로 넘긴다.
- 첫 번째 바이트는 4로 설정하고, 이후의 4바이트는 연속되는 주소값으로 설정한다.
- 예를 들어, and char * work well with pointers to their values.
Address type
- 0x04, 0x7f, 0x00, 0x00, 0x01 are entered in this order.
- In the case of ipv4, it is passed as an array of 5-byte unsigned char.
- The first byte is set to 4, the next 4 bytes are set to consecutive address values.
- For example, in the case of 127.0.0.1의 경우에는 5바이트 배열 1, five byte arrays 0x04, 0x7f, 0x00, 0x00, 0x01 의 순으로 들어가게 된다and 0x01 are entered in order.
Code Block | ||
---|---|---|
| ||
// 4개의For 컬럼tables 정보를with 가지는four 테이블의column 경우information (short (16), int (32), long (64), varchar) testAppendIPFunc() { short val1 = 0; int val2 = 1; long long val3 = 2; char *val4 = "my string"; void *valueArray[4]; valueArray[0] = (void *)&val1; valueArray[1] = (void *)&val2; valueArray[2] = (void *)&val3; valueArray[3] = (void *)val4; SQLAppendData(aStmt, valueArray); } |
Configuration According to Data Type
datetime 형 type
- Machbase 는 내부적으로 나노 단위 시간 해상도 값을 가지기 때문에 클라이언트에서 시간을 설정할 때는 변환과정을 거쳐야 하며, 64비트 부호없는 정수형 값으로 표현된다.
따라서 적절한 변환을 위해서는 유닉스 라이브러리인 mktime을 이용하여 초로 변환한 이후에 나노 값을 더해주어야 한다.
※ Machbase의 시간 = (1970년 1월 1일 이후로부터의 총 시간 (초)Since Machbase internally has a nano-unit time resolution value, it must be converted when setting the time on the client, and it is expressed as a 64-bit unsigned integer value.
Therefore, for proper conversion, you need to add nano values after converting to seconds using the UNIX library mktime.
※ Machbase time = (total time (seconds) since January 1, 1970) * 1,000,000,000 +
milimilli-second * 1,000,000 + micro-second * 1000 + nano-second;
Code Block | ||
---|---|---|
| ||
// Code if Date String이 String is entered as "연도-월-일 시:분:초 밀리:마이크로:나노" 형태로 입력될 경우 코드Year - Month - Date: Minute: Second Millis: Micro: Nano" testAppendDateStrFunc(char *aDateString) { int yy, int mm, int dd, int hh, int mi, int ss; unsigned long t1; void *valueArray[5]; sscanf(aDateString, "%d-%d-%d %d:%d:%d %d:%d:%d", &yy, &mm, &dd, &hh, &mi, &ss, &mmm, &uuu, &nnn); sTm.tm_year = yy - 1900; sTm.tm_mon = mm - 1; sTm.tm_mday = dd; sTm.tm_hour = hh; sTm.tm_min = mi; sTm.tm_sec = ss; t1 = mktime(&sTm); t1 = t1 * 1000000000L; t1 = t1 + (mmm*1000000L) + (uuu*1000) + nnn; valueArray[4] = &t1; SQLAppendData(aStmt, valueArray); } |
SQLAppendDataByTime(deprecated)
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendDataByTime(SQLHSTMT StatementHandle, SQLBIGINT aTime, void *aData[]); |
이 함수는 해당 채널에 대해 데이터를 입력하는 함수이며, DB에 저장되는 _arrival_time 값을 현재 시간이 아닌 특정 시간의 값으로 설정할 수 있다.
예를 들면, 1개월전 로그 파일에 있는 날짜를 그 당시의 날짜로 입력하고자 할때 사용된다.
- aTime은 _arrival_time으로 설정된 time 값이다.
- aData는 입력될 데이터의 포인터를 담고 있는 배열이다.
- 배열의 개수는 Open시에 지정한 테이블이 보유하고 있는 컬럼의 개수와 일치해야 한다.
This function is a function to input data for the corresponding channel, and the value of _arrival_time stored in the DB can be set to a specific time value instead of the current time.
For example, you want to enter the date in the log file a month ago as the date.
- aTime is a time value set to _arrival_time.
- aData is an array containing pointers to the data to be input.
- The number of arrays must match the number of columns held by the table specified at Open.
For the rest, refer to the SQLAppendData () function.
Code Block | ||
---|---|---|
| ||
// 4개의For 컬럼tables 정보를with 가지는four 테이블의column 경우 information (short (16), int (32), long (64), varchar) testAppendFuncWithTime() { long long sTime = 1; short val1 = 0; int val2 = 1; long long val3 = 2; char *val4 = "my string"; void *valueArray[4]; valueArray[0] = (void *)&val1; valueArray[1] = (void *)&val2; valueArray[2] = (void *)&val3; valueArray[3] = (void *)val4; SQLAppendDataByTime(aStmt, sTime, valueArray); } |
SQLAppendDataV2
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendDataV2(SQLHSTMT StatementHandle, SQL_APPEND_PARAM *aData); |
이 함수는 This function is a newly introduced Append function since Machbase 2.0 부터 새로 도입된 Append 함수로서, 기존의 함수에서 불편했던 입력 방식을 편리하게 대폭 개선한 함수이다.
특히, 2.0에서 도입된 TEXT와 BINARY 타입의 경우는 SQLAppendDataV2() 함수에서만 입력이 가능하다.
각 타입에 맞는 NULL 입력 가능
VARCHAR 입력시 스트링 길이 입력 가능
IPv4, IPv6 입력시 바이너리 및 스트링 형태의 데이터 입력 가능
TEXT, BINARY 타입에 대한 데이터 길이 지정 가능
함수 인자는 다음과 같이 구성된다.
. It is a convenient function that improves the input method inconvenient in existing functions.
In the case of TEXT and BINARY type introduced in 2.0 especially, input is possible only in SQLAppendDataV2 () function.
Can input NULL for each type
Can input string length when inputting VARCHAR
Can input binary and string data when inputting IPv4 or IPv6
Can specify data length for TEXT, BINARY type
The function arguments are structured as follows.
- aData is a pointer to an array of arguments called SQL_APPEND_PARAM. The number of this array must match the number of columns held by the table specified at Open.
- The return value can be SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, or SQL_ERROR 가 가능하다. 특히 In particular, if SQL_SUCCESS_WITH_INFO가 반환되었을 경우에는 입력된 특정 컬럼의 길이가 길어 잘리는 등의 오류가 있을 수 있으므로 결과를 다시 확인하여야 한다.
- INFO is returned, there may be errors such as a lengthy input column being truncated, so check the result again.
Below is the definition of SQL_APPEND_PARAM
의 정의이며, 이 내용은 that will actually be used in V2 , which is included in machbase_sqlcli.h
에 포함되어 있다..
Code Block | ||
---|---|---|
| ||
typedef struct machAppendVarStruct { unsigned int mLength; void *mData; } machAppendVarStruct; /* for IPv4, IPv6 as bin or string representation */ typedef struct machbaseAppendIPStruct { unsigned char mLength; /* 0:null, 4:ipv4, 6:ipv6, 255:string representation */ unsigned char mAddr[16]; char *mAddrString; } machbaseAppendIPStruct; /* Date time*/ typedef struct machbaseAppendDateTimeStruct { long long mTime; #if defined(SUPPORT_STRUCT_TM) struct tm mTM; #endif char *mDateStr; char *mFormatStr; } machbaseAppendDateTimeStruct; typedef union machbaseAppendParam { short mShort; unsigned short mUShort; int mInteger; unsigned int mUInteger; long long mLong; unsigned long long mULong; float mFloat; double mDouble; machbaseAppendIPStruct mIP; machbaseAppendVarStruct mVar; /* for all varying type */ machbaseAppendVarStruct mVarchar; /* alias */ machbaseAppendVarStruct mText; /* alias */ machbaseAppendVarStruct mBinary; /* binary */ machbaseAppendVarStruct mBlob; /* reserved alias */ machbaseAppendVarStruct mClob; /* reserved alias */ machbaseAppendDateTimeStruct mDateTime; } machbaseAppendParam; #define SQL_APPEND_PARAM machbaseAppendParam |
위에서 볼 수 있듯이 내부적으로 machbaseAppendParam
이라는 공용 구조체가 하나의 인자를 담고 있는 구조이다. 각 데이터 타입에 대해 데이터 및 스트링에 대한 길이 및 값을 명시적으로 입력할 수 있도록 되어 있다. 실제 사용 예는 다음과 같다.
고정 길이 숫자형 타입의 입력
고정 길이 숫자형 타입이라 함은As you can see from the above, there is a structure in which a shared structure machbaseAppendParam
which internally contains one argument. The length and value for the data and string can be explicitly entered for each data type. Examples of actual use are as follows.
Fixed-Length Numeric Type Input
Fixed-length numeric types are short, ushort, integer, uinteger, long, ulong, float, and double 을 말한다. 이 타입의 경우 . This type can be entered by directly assigning a value to the structure member of SQL_APPEND_PARAM의 구조체 멤버에 직접 값을 대입함으로써 입력 가능하다PARAM.
데이터베이스 타입Database Type | NULL 매크로Macro | SQL_APPEND_PARAM 멤버Member |
---|---|---|
SHORT | SQL_APPEND_SHORT_NULL | mShort |
USHORT | SQL_APPEND_USHORT_NULL | mUShort |
INTEGER | SQL_APPEND_INTEGER_NULL | mInteger |
UINTEGER | SQL_APPEND_UINTEGER_NULL | mUInteger |
LONG | SQL_APPEND_LONG_NULL | mLong |
ULONG | SQL_APPEND_ULONG_NULL | mULong |
FLOAT | SQL_APPEND_FLOAT_NULL | mFloat |
DOUBLE | SQL_APPEND_DOUBLE_NULL | mDouble |
다음은 실제 값을 입력하는 예제이다The following is an example of entering actual values.
Code Block | ||
---|---|---|
| ||
// Assume that the Table Schema Schema가consists of 8개의eight 컬럼이고columns, 각각 SHORT, USHORT, INTEGER, UINTEGER, LONG, ULONG, FLOAT, DOUBLE로and 이루어진 것으로 가정한다DOUBLE, respectively. void testAppendExampleFunc() { SQL_APPEND_PARAM sParam[8]; /* fixed column */ sParam[0].mShort = SQL_APPEND_SHORT_NULL; sParam[1].mUShort = SQL_APPEND_USHORT_NULL; sParam[2].mInteger = SQL_APPEND_INTEGER_NULL; sParam[3].mUInteger = SQL_APPEND_UINTEGER_NULL; sParam[4].mLong = SQL_APPEND_LONG_NULL; sParam[5].mULong = SQL_APPEND_ULONG_NULL; sParam[6].mFloat = SQL_APPEND_FLOAT_NULL; sParam[7].mDouble = SQL_APPEND_DOUBLE_NULL; SQLAppendDataV2(Stmt, sParam); /* FIXED COLUMN Value */ sParam[0].mShort = 2; sParam[1].mUShort = 3; sParam[2].mInteger = 4; sParam[3].mUInteger = 5; sParam[4].mLong = 6; sParam[5].mULong = 7; sParam[6].mFloat = 8.4; sParam[7].mDouble = 10.9; SQLAppendDataV2(Stmt, sParam); } |
날짜형 타입의 입력
아래는 DATETIME형의 데이터를 입력하는 예이다. 편의를 위해 몇가지의 매크로가 준비되어 있다.
Date Type Input
Below is an example of inputting data of DATETIME type. Several macros are available for convenience.
Performs operations on the mDateTime member in SQL_APPEND_PARAM에서 mDateTime 멤버에 대한 조작을 수행한다. 아래의 매크로는 mDateTime 구조체에서 mTime이라는 64비트 정수값에 대해 설정함으로써 날짜를 지정할 수 있다PARAM. The following macro can specify a date by setting a 64-bit integer value called mTime in the mDateTime structure.
Code Block | ||
---|---|---|
| ||
typedef struct machbaseAppendDateTimeStruct { long long mTime; #if defined(SUPPORT_STRUCT_TM) struct tm mTM; #endif char *mDateStr; char *mFormatStr; } machbaseAppendDateTimeStruct; |
매크로Macro | 설명Description | ||
---|---|---|---|
SQL_APPEND_DATETIME_NOW | 현재의 클라이언트 시간을 입력한다Enters the current client time. | ||
SQL_APPEND_DATETIME_STRUCT_TM | mDateTime의 struct tm 구조체인 mTM에 값을 설정하고, 그 값을 데이터베이스로 입력한다Sets a value to mTM, the struct tm structure of mDateTime, and inputs the value to the database. | ||
SQL_APPEND_DATETIME_STRING | mDateTime의 스트링형에 대한 값을 설정하고, 이를 데이터베이스로 입력한다Sets a value for the string type of mDateTime and enters it into the database. mDateStr: 실제 날짜 스트링 값이 할당real date string value assigned | ||
SQL_APPEND_DATETIME_NULL | 날짜 컬럼의 값을 NULL로 입력한다. | 임의의 64비트 값 | Enters the value of the date column as NULL. |
Any 64-bit Value | This value is entered as the actual datetime. This value represents an integer value in nanoseconds since January 1, 1970. , it represents 0: 1: 1 on January 1, 1970. (GMT) |
Code Block | ||
---|---|---|
| ||
// 다음은 각각의 경우에 대해 실제 값을 입력하는 예제이다. 하나의 DATETIME 컬럼이 존재한다고 가정한다. Assume that the table schema consists of eight columns, SHORT, USHORT, INTEGER, UINTEGER, LONG, ULONG, FLOAT, and DOUBLE, respectively. void testAppendDateTimeFunc() { SQL_mach_PARAM sParam[1]; /* NULL 입력Insert */ sParam[0].mDateTime.mTime = SQL_APPEND_DATETIME_NULL; SQLAppendDataV2(Stmt, sParam); /* 현재Current 시간 입력Time */ sParam[0].mDateTime.mTime = SQL_APPEND_DATETIME_NOW; SQLAppendDataV2(Stmt, sParam); /* 임의의nano 값second 입력since :1970.1.1일 이후로부터의 현재까지 나노세컨드의 값 1970/01/01 */ sParam[0].mDateTime.mTime = 1234; SQLAppendDataV2(Stmt, sParam); /* String 스트링format 포맷time 기준 입력 */ sParam[0].mDateTime.mTime = SQL_APPEND_DATETIME_STRING; sParam[0].mDateTime.mDateStr = "23/May/2014:17:41:28"; sParam[0].mDateTime.mFormatStr = "DD/MON/YYYY:HH24:MI:SS"; SQLAppendDataV2(Stmt, sParam); /* struct tm의tm 값을based 변경하여 입력time */ sParam[0].mDateTime.mTime = SQL_APPEND_DATETIME_STRUCT_TM; sParam[0].mDateTime.mTM.tm_year = 2000 - 1900; sParam[0].mDateTime.mTM.tm_mon = 11; sParam[0].mDateTime.mTM.tm_mday = 31; SQLAppendDataV2(Stmt, sParam); } |
인터넷 주소형 타입의 입력
아래는 IPv4와 IPv6 형의 데이터를 입력하는 예이다. 이 역시 편의를 위해 몇가지의 매크로가 준비되어 있다. SQL_APPEND_PARAM에서 mLength 멤버에 대한 조작을 수행한다Internet Address Type Input
The following is an example of inputting IPv4 and IPv6 type data. There are also several macros available for your convenience. Performs operations on the mLength member in SQL_APPEND_PARAM.
Code Block | ||
---|---|---|
| ||
/* for IPv4, IPv6 as bin or string representation */ typedef struct machbaseAppendIPStruct { unsigned char mLength; /* 0:null, 4:ipv4, 6:ipv6, 255:string representation */ unsigned char mAddr[16]; char *mAddrString; } machbaseAppendIPStruct; |
매크로 Macro (set on mLength 에 설정) | 설명Description | |
---|---|---|
SQL_APPEND_IP_NULL | 해당 컬럼에 NULL 값을 입력 | Enters a NULL value in the corresponding column |
SQL_APPEND_IP_IPV4 | mAddr이 IPv4를 가지고 있음mAddr has IPv4 | |
SQL_APPEND_IP_IPV6 | mAddr이 IPv6를 가지고 있음mAddr has IPv6 | |
SQL_APPEND_IP_STRING | mAddrString이 주소 문자열을 가지고 있음. |
mAddrString has an address string. |
The following is an example of entering actual values for each case.
Code Block | ||
---|---|---|
| ||
void testAppendIPFunc() { SQL_APPEND_PARAM sParam[1]; /* NULL */ sParam[0].mIP.mLength = SQL_APPEND_IP_NULL; SQLAppendDataV2(Stmt, sParam); /* 배열을Direct 직접array 수정access */ sParam[0].mIP.mLength = SQL_APPEND_IP_IPV4; sParam[0].mIP.mAddr[0] = 127; sParam[0].mIP.mAddr[1] = 0; sParam[0].mIP.mAddr[2] = 0; sParam[0].mIP.mAddr[3] = 1; SQLAppendDataV2(Stmt, sParam); /* IPv4 from binary */ sParam[0].mIP.mLength = SQL_APPEND_IP_IPV4; *(in_addr_t *)(sParam[0].mIP.mAddr) = inet_addr("192.168.0.1"); SQLAppendDataV2(Stmt, sParam); /* IPv4 : ipv4 from string */ sParam[0].mIP.mLength = SQL_APPEND_IP_STRING; sParam[0].mIP.mAddrString = "203.212.222.111"; SQLAppendDataV2(Stmt, sParam); /* IPv4 : ipv4 from invalid string */ sParam[0].mIP.mLength = SQL_APPEND_IP_STRING; sParam[0].mIP.mAddrString = "ip address is not valid"; SQLAppendDataV2(Stmt, sParam); // invalid IP value /* IPv6 : ipv6 from binary bytes */ sParam[0].mIP.mLength = SQL_APPEND_IP_IPV6; sParam[0].mIP.mAddr[0] = 127; sParam[0].mIP.mAddr[1] = 127; sParam[0].mIP.mAddr[2] = 127; sParam[0].mIP.mAddr[3] = 127; sParam[0].mIP.mAddr[4] = 127; sParam[0].mIP.mAddr[5] = 127; sParam[0].mIP.mAddr[6] = 127; sParam[0].mIP.mAddr[7] = 127; sParam[0].mIP.mAddr[8] = 127; sParam[0].mIP.mAddr[9] = 127; sParam[0].mIP.mAddr[10] = 127; sParam[0].mIP.mAddr[11] = 127; sParam[0].mIP.mAddr[12] = 127; sParam[0].mIP.mAddr[13] = 127; sParam[0].mIP.mAddr[14] = 127; sParam[0].mIP.mAddr[15] = 127; SQLAppendDataV2(Stmt, sParam); sParam[0].mIP.mLength = SQL_APPEND_IP_STRING; sParam[0].mIP.mAddrString = "::127.0.0.1"; SQLAppendDataV2(Stmt, sParam); sParam[0].mIP.mLength = SQL_APPEND_IP_STRING; sParam[0].mIP.mAddrString = "FFFF:FFFF:1111:2222:3333:4444:7733:2123"; SQLAppendDataV2(Stmt, sParam); } |
Info |
---|
IP 타입을 문자열 (STRING) 로 입력할경우 SQLAppendDataV2 이후에 각각 자료형에 맞게 mLength가 4 또는 6으로 바뀌게 된다. |
Variable Data Types (Character and Binary Data) Input
Variable data types include VARCHAR and TEXT, and BLOB and CLOB. In existing functions, only VARCHAR was supported, and there was no way for the user to enter the length of the string. For that reason, we had to get the length through the strlen () function each time, but from function V2, the user can directly specify the length for the variable data type. Thus, if the user knows the length in advance, data can be input more quickly. Internally, the variable data type is a structure. However, for convenience of development, members are created separately for each data type.
Code Block | ||
---|---|---|
| ||
typedef struct machAppendVarStruct { unsigned int mLength; void *mData; } machAppendVarStruct; |
가변 데이터형의 입력시에는 데이터의 길이를 mLength에 설정하고, 원시 데이터 포인터를 mData로 설정하면 된다. 만일 mLength의 길이가 정의된 스키마보다 클 경우에는 자동으로 잘려서 입력된다. 이때 SQLAppendDataV2() 함수는 When inputting a variable data type, set the length of the data to mLength and set the primitive data pointer to mData. If mLength is greater than the defined schema, it is automatically truncated. At this time, SQLAppendDataV2 () returns SQL_SUCCESS_WITH_INFO을 리턴하게 되고, 더불어 관련 경고 메시지를 내부 구조체에 채운다. 이 경고 메시지를 확인하기 위해서는 SQLError() 함수를 이용하면 된다.
데이터베이스 타입
and also fills the internal structure with a related warning message. To see this warning message, use SQLError () function.
Database Type | NULL Macro | SQL_APPEND_PARAM 멤버Member |
---|---|---|
VARCHAR | SQL_APPEND_VARCHAR_NULL | mVarchar |
TEXT | SQL_APPEND_TEXT_NULL | mText |
BINARY | SQL_APPEND_BINARY_NULL | mBinary |
BLOB | SQL_APPEND_BLOB_NULL | mBlob |
CLOB | SQL_APPEND_CLOB_NULL | mClob |
다음은 각각의 환경에 대해 실제 값을 입력하는 예제이다. 하나의 VARCHAR 컬럼이 존재한다고 가정한다The following is an example of entering actual values for each environment. Assumes that there is one VARCHAR column.
Code Block | ||
---|---|---|
| ||
CREATE TABLE ttt (name VARCHAR(10)); |
Code Block | ||
---|---|---|
| ||
void testAppendVarcharFunc() { SQL_mach_PARAM sParam[1]; /* VARCHAR : NULL */ sParam[0].mVarchar.mLength = SQL_APPEND_VARCHAR_NULL SQLAppendDataV2(Stmt, sParam); /* OK */ /* VARCHAR : string */ strcpy(sVarchar, "MY VARCHAR"); sParam[0].mVarchar.mLength = strlen(sVarchar); sParam[0].mVarchar.mData = sVarchar; SQLAppendDataV2(Stmt, sParam); /* OK */ /* VARCHAR : Truncation! */ strcpy(sVarchar, "MY VARCHAR9"); /* Truncation! */ sParam[0].mVarchar.mLength = strlen(sVarchar); sParam[0].mVarchar.mData = sVarchar; SQLAppendDataV2(Stmt, sParam); /* SQL_SUCCESS_WITH_INFO */ } |
다음은 Text 타입에 대한 입력 예제이다The following is an input example for Text type.
Code Block | ||
---|---|---|
| ||
CREATE TABLE ttt (doc TEXT); |
Code Block | ||
---|---|---|
| ||
void testAppendFunc() { SQL_mach_PARAM sParam[1]; /* VARCHAR : NULL */ sParam[0].mText.mLength = SQL_APPEND_TEXT_NULL SQLAppendDataV2(Stmt, sParam); /* OK */ /* VARCHAR : string */ strcpy(sText, "This is the sample document for tutorial."); sParam[0].mVar.mLength = strlen(sText); sParam[0].mVar.mData = sText; SQLAppendDataV2(Stmt, sParam); /* OK */ } |
SQLAppendDataByTimeV2
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendDataByTimeV2(SQLHSTMT StatementHandle, SQLBIGINT aTime, SQL_APPEND_PARAM *aData); |
이 함수는 해당 채널에 대해 데이터를 입력하는 함수이며, DB에 저장되는 _arrival_time 값을 현재 시간이 아닌 특정 시간의 값으로 설정할 수 있다. 예를 들면, 1개월전 로그 파일에 있는 날짜를 그 당시의 날짜로 입력하고자 할때 사용된다.
- aTime은 _arrival_time으로 설정될 time값이다. 1970년 1월 1일 이후로부터의 현재까지 nano second 값을 입력해야 한다. 또한 입력되는 값이 과거부터 현재순으로 순차적으로 정렬되어 있어야 한다.
- aData는 입력될 데이터의 포인터를 담고 있는 배열이다. 배열의 개수는 Open시에 지정한 테이블이 보유하고 있는 컬럼의 개수와 일치해야 한다.
This function is a function to input data for the corresponding channel, and the value of _arrival_time stored in the DB can be set to a specific time value instead of the current time. For example, you want to enter the date in the log file a month ago as the date.
- aTime is the time value to be set to _arrival_time. You must enter the nano second value from January 1, 1970 to the present. Also, input values must be sorted in order from the past to the present.
- aData is an array containing pointers to the data to be input. The number of arrays must match the number of columns held by the table specified at Open.
For the rest, refer to the SQLAppendDataV2 () function.
SQLAppendFlush
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendFlush(SQLHSTMT StatementHandle); |
이 함수는 현재 채널 버퍼에 쌓여있는 데이터를 Machbase 서버로 즉시 전송한다This function immediately sends the data accumulated in the current channel buffer to the Machbase server.
SQLAppendClose
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendClose(SQLHSTMT aStmtHandle, SQLBIGINT* aSuccessCount, SQLBIGINT* aFailureCount); |
이 함수는 현재 열린 채널을 닫는다. 만일 열려지지 않은 채널이 존재할 경우 에러가 발생한다.
This function closes the currently open channel. If an unopened channel exists, an error occurs.
- aSuccessCount: The number of successful Append records.
- aFailureCount: The number of failed Append records.
SQLAppendSetErrorCallback
Code Block | ||
---|---|---|
| ||
SQLRETURN SQLAppendSetErrorCallback(SQLHSTMT aStmtHandle, SQLAppendErrorCallback aFunc); |
이 함수는 SQLAppendOpen()이 성공한 다음 Append시 에러가 발생했을 때 호출되는 콜백 함수를 설정한다. 만일 이 함수를 설정하지 않을 경우에는 서버에 에러가 발생하더라도, 클라이언트에서는 무시하게 된다.
- aStmtHandle : 에러를 확인할 Statement를 지정한다.
- aFunc : Append 실패시 호출할 함수 포인터를 지정한다.
This function sets the callback function that is called when an error occurs during append. If you do not set this function, the client will ignore any errors that occur in the server.
- aStmtHandle: Specifies a Statement to check for errors.
- aFunc: Specifies the function pointer to call on Append failure.
The prototype for SQLAppendErrorCallback is:
Code Block | ||
---|---|---|
| ||
typedef void (*SQLAppendErrorCallback)(SQLHSTMT aStmtHandle, SQLINTEGER aErrorCode, SQLPOINTER aErrorMessage, SQLLEN aErrorBufLen, SQLPOINTER aRowBuf, SQLLEN aRowBufLen); |
- aStatementHandle: 에러를 발생한 Statement 핸들
- aErrorCode : 에러의 원인이 된 32비트 에러 코드
- aErrorMessage : 해당 에러코드에 대한 문자열
- aErrorBufLen : aErrorMessage의 길이
- aRowBuf : 에러를 발생시킨 레코드의 상세 명세가 담긴 문자열
- aRowBufLen : aRowBuf의 길이
- the statement handle that generated the error
- aErrorCode: 32-bit error code that caused the error
- aErrorMessage: string for the error code
- aErrorBufLen: the length of aErrorMessage
- aRowBuf: a string containing the detailed description of the record that caused the error
- aRowBufLen: length of aRowBuf
Example of Using Error Callback (dumpError)
Code Block | ||
---|---|---|
| ||
void dumpError(SQLHSTMT aStmtHandle, SQLINTEGER aErrorCode, SQLPOINTER aErrorMessage, SQLLEN aErrorBufLen, SQLPOINTER aRowBuf, SQLLEN aRowBufLen) { char sErrMsg[1024] = {0, }; char sRowMsg[32 * 1024] = {0, }; if (aErrorMessage != NULL) { strncpy(sErrMsg, (char *)aErrorMessage, aErrorBufLen); } if (aRowBuf != NULL) { strncpy(sRowMsg, (char *)aRowBuf, aRowBufLen); } fprintf(stdout, "Append Error : [%d][%s]\n[%s]\n\n", aErrorCode, sErrMsg, sRowMsg); } ...... if( SQLAppendOpen(m_IStmt, TableName, aErrorCheckCount) != SQL_SUCCESS ) { fprintf(stdout, "SQLAppendOpen error\n"); exit(-1); } // 콜백을Setting 설정한다Callback. assert(SQLAppendSetErrorCallback(m_IStmt, dumpError) == SQL_SUCCESS); doAppend(sMaxAppend); if( SQLAppendClose(m_IStmt, &sSuccessCount, &sFailureCount) != SQL_SUCCESS ) { fprintf(stdout, "SQLAppendClose error\n"); exit(-1); } } |
SQLSetConnectAppendFlush
Code Block | ||
---|---|---|
| ||
SQLRETURN SQL_API SQLSetConnectAppendFlush(SQLHDBC hdbc, SQLINTEGER option) |
Append에 의해서 입력된 데이터는 통신 버퍼에 기록되어 전송대기 상태에서 사용자가 SQLAppendFlush 함수를 호출하거나 통신 버퍼가 가득 차게 되면 서버로 전송된다. 사용자가 버퍼가 가득 차 있지 않아도 일정 주기로 서버에게 Append에 의한 데이터를 전송하게 하려면 이 함수를 이용하면 된다. 이 함수는 매 100ms 주기로 마지막으로 전송한 시간과 현재 시간의 차이를 계산하여 지정된 시간(설정하지 않은 경우에는 1초)가 지난 경우 통신 버퍼의 내용을 서버에 전달한다.
매개변수는 다음과 같다.
- hdbc : DB의 connection handle이다.
- option : 0이면 auto flush를 off, 0이 아닌 값이면 auto flush를 on으로 한다.
The data input by Append is written to the communication buffer and is sent to the server when the user calls the SQLAppendFlush function in the waiting state or the communication buffer becomes full. You can use this function if you want the user to send data by append to the server at regular intervals even if the buffer is not full. This function computes the difference between the last transmitted time and the current time every 100ms, and transfers the contents of the communication buffer to the server when the specified time (1 second if not set) has passed.
The parameters are:
- hdbc: DB connection handle.
- If option: 0, auto flush is off; otherwise, auto flush is on.
Executing on an unconnected hdbc will result in an error.
SQLSetStmtAppendInterval
Code Block | ||
---|---|---|
| ||
SQLRETURN SQL_API SQLSetStmtAppendInterval(SQLHSTMT hstmt, SQLINTEGER fValue) |
SQLSetConnectAppendFlush를 이용해서 시간 단위 flush기능을 켰을 경우, 특정 statement에 대해서는 자동 flush를 끄거나 flush 주기를 조정하고 싶을 경우 이 함수를 사용한다.
매개변수는 다음과 같다.
- hstmt : flush주기를 조정하고자 하는 statement handle이다.
- fValue : flush주기를 조정하고자 하는 값이다. 0이면 flush를 하지 않으며 단위는 ms이다. 100ms마다 flush할지를 결정하는 스레드가 실행되므로 100의 배수로 설정한다. 정확히 원하는 시점에 자동 flush가 실행되지는 않는다. 1000이 기본 값이다.
시간 기반 flush가 실행중이지 않은 경우라도 이 함수의 실행은 성공한다.
Error 확인 및 설명
Append 관련 함수를 사용할때 에러를 확인하는 방법과 코드에 대한 설명이다. CLI 함수에서 return 값이 SQL_SUCCESS가 아닌 경우 아래 코드를 이용하여 에러 메시지를 확인할 수 있다Uses SQLSetConnectAppendFlush to turn off automatic flushing or flushing for a particular statement when you turn on flushing on a time unit.
The parameters are:
- hstmt: This is the statement handle that you want to adjust the flush interval.
- fValue: The value to which you want to adjust the flush interval. If 0, flush is not performed and the unit is ms. Set to a multiple of 100 since the thread that determines whether to flush every 100ms is executed. It does not automatically flush at exactly the right time. 1000 is the default value .
Execution of this function will succeed even if time-based flush is not running.
Error Check and Description
This is a description of the code and how to check for errors when using the Append related functions. If the return value in the CLI function is not SQL_SUCCESS, you can check the error message using the following code.
Code Block | ||
---|---|---|
| ||
SQLINTEGER errNo; int msgLength; char sqlState[6]; char errMsg[1024]; if (SQL_SUCCESS == SQLError ( env, con, stmt, (SQLCHAR *)sqlState, &errNo, (SQLCHAR *)errMsg, 1024, &msgLength )) { //errorset code값을five 5자리length 숫자로error 지정한다.code printf("ERROR-%05d: %s\n", errNo, errMsg); } |
Append관련 함수에서 리턴되는 에러 메시지는 아래와 같다The error message returned from the Append related function is as follows.
함수 | message | 설명 |
---|---|---|
SQLAppendOpen | statement is already opened.중복으로 SQLAppendOpen을 하는 경우 발생함 | Occurs when SQLAppendOpen is executed in duplicate. |
Failed to close stream protocol. | 스트림 프로토콜 종료에 실패함Stream protocol termination failed. | |
Failed to read protocol.네트워크 | 읽기 오류가 발생함A network read error occurred. | |
cannot read column meta. | Invalid column meta 정보 구조가 잘못됨information structure | |
cannot allocate memory.내부 버퍼 메모리 할당 오류가 발생함 | An internal buffer memory allocation error occurred. | |
cannot allocate compress memory.압축 버퍼 | 메모리 할당 오류가 발생함Compressed buffer memory allocation error occurred. | |
invalid return after reading column meta. | return값에 오류가 있음Return value has an error. | |
SQLAppendData | statement is not opened. | AppendOpen을 하지 않고 AppendData를 call함Called AppendData without AppendOpen. |
column() truncated : | varchar 타입 컬럼에 지정된 사이즈 보다 큰 데이터를 입력하는 경우 발생함Occurs when you enter data that is larger than the size specified in the varchar type column. | |
Failed to add binary.통신버퍼에 쓰기 | 오류가 발생함Write error in communication buffer occurred. | |
SQLAppendClose | statement is not opened. | AppendOpen상태가 아님Not in AppendOpen state. |
Failed to close stream protocol. | 스트림 프로토콜 종료에 실패함Stream protocol termination failed. | |
Failed to close buffer protocol. | 버퍼 프로토콜 종료에 실패함Buffer protocol termination failed. | |
cannot read column meta.column meta정보 구조가 | 잘못됨The column meta information structure is incorrect. | |
invalid return after reading column meta. | return값에 오류가 있음Return value has an error. | |
SQLAppendFlush | statement is not opened. | AppendOpen상태가 아님Not in AppendOpen state |
Failed to close stream protocol. | 네트워크 쓰기 오류가 발생함A network write error occurred. | |
SQLSetErrorCallback | statement is not opened. | AppendOpen상태가 아님Not in AppendOpen state. |
Protocol Error (not APPEND_DATA_PROTOCOL) | 통신버퍼 읽기 결과 Communication buffer read result is not APPEND_DATA_PROTOCOL 값이 아님value. | |
SQLAppendDataV2 | Invalid date format or date string. | datetime 형식이 틀릴 경우 발생함Occurs when the datetime type is wrong. |
statement is not opened. | AppendOpen상태가 아님Not in AppendOpen state | |
column() truncated : | binary 타입 컬럼에 지정된 사이즈 보다 큰 데이터를 입력하는 경우 발생함This occurs when you enter data that is larger than the size specified in the binary type column. | |
column() truncated : | varchar, text 타입 컬럼에 지정된 사이즈 보다 큰 데이터를 입력하는 경우 발생함Occurs when you enter data that is larger than the size specified in the varchar and text type column. | |
Failed to add stream.통신 버퍼에 | 쓰기 오류가 발생함Write error in communication buffer occurred. | |
IP address length is invalid. | The mLength value of the IPv4, IPv6 타입 구조체의 mLength 값이 잘못 지정됨. | |
IP string is invalid. | IPv4, IPv6 형식의 데이터가 아님. | |
Unknown data type has been specified. | Machbase에서 사용하는 data type이 아님. |
이를 위해서 Machbase 5.5 이후 버전에서는 열 형색 매개변수 바인딩을 지원한다. (행 형식 매개변수 바인딩은 아직 지원되지 않는다.)
함수 SQLSetStmtAttr()의 인자 Attribute에 SQL_ATTR_PARAM_BIND_TYPE을 설정하고 인자 param에IPv6 type structure is specified incorrectly. | |
IP string is invalid. | Not in IPv4 or IPv6 format. |
Unknown data type has been specified. | Not the data type used by Machbase. |
Column wise parameter binding
The SQLAppend function, which is used to enter a large amount of data into Machbase quickly, can be used only when entering a log / tag table, and the SQLAppend function cannot be used to perform a bulk update on a lookup or volatile table.
For this purpose, Machbase 5.5 and later versions support column wise parameter binding. (Row wise format parameter binding is not yet supported.)
Set SQL_ATTR_PARAM_BIND_TYPE in the argument Attribute of the function SQLSetStmtAttr () and SQL_PARAM_BIND_BY_COLUMN을 설정한다. 바인드할 각 칼럼에 대해서 매개변수를 배열로 설정하고, 지시자 변수 또한 배열로 설정한다. 이후 SQLBindParameter()를 이 매개변수를 전달하여 호출한다.아래 그림은 각 매개변수 배열에 대해 열 형식 바인딩이 동작하는 방식을 보여준다COLUMN in the parameter param.
For each column to bind, set the parameter to an array and the indicator variable to an array. Then call SQLBindParameter () with this parameter.
The figure below shows how columnar binding works for each parameter array.
Column A (parameter A) | Column B (parameter B) | Column C (parameter C) | |||
---|---|---|---|---|---|
Value_Array | Indicator/ length array | Value_Array | Indicator/ length array | Value_Array | Indicator/ length array |
아래 예제는 열 형식 매개변수 바인딩을 이용하여 대량의 데이터를 삽입하는 예제이다The following example inserts a large amount of data using column wise parameter binding.
Code Block | ||
---|---|---|
| ||
#define DESC_LEN 51 #define ARRAY_SIZE 10 SQLCHAR * Statement = "INSERT INTO Parts (PartID, Description, Price) VALUES (?, ?, ?)"; /* Array of 바인드할parameters 매개변수to 배열bind */ SQLUINTEGER PartIDArray[ARRAY_SIZE]; SQLCHAR DescArray[ARRAY_SIZE][DESC_LEN]; SQLREAL PriceArray[ARRAY_SIZE]; /* 바인드할 지사자 변수 배열Array of predicate variables to bind */ SQLINTEGER PartIDIndArray[ARRAY_SIZE], DescLenOrIndArray[ARRAY_SIZE], PriceIndArray[ARRAY_SIZE]; SQLUSMALLINT i, ParamStatusArray[ARRAY_SIZE]; SQLUINTEGER ParamsProcessed; // Set the SQL_ATTR_PARAM_BIND_TYPE statement attribute to use // column-wise binding. SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0); // Specify the number of elements in each parameter array. SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, ARRAY_SIZE, 0); // Specify an array in which to return the status of each set of // parameters. SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, 0); // Specify an SQLUINTEGER value in which to return the number of sets of // parameters processed. SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed, 0); // Bind the parameters in column-wise fashion. SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, PartIDArray, 0, PartIDIndArray); SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, DESC_LEN - 1, 0, DescArray, DESC_LEN, DescLenOrIndArray); SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_REAL, 7, 0, PriceArray, 0, PriceIndArray); |
지원되는 문자열
마크베이스는 기본적으로Supported Strings
Machbase stores string data using UTF-8 방식을 사용하여 문자열 데이터를 저장한다.UTF-8 이외의 방식으로 문자열을 입/출력하는 Windows의 경우 ODBC에서 아래와 같이 변환한다by default.
In the case of Windows that inputs/outputs strings in methods other than UTF-8, ODBC converts them as follows.
OS | Unicode/Non-Unicode | 문자열 변환String Conversion | Note |
---|---|---|---|
Windows | Unicode (UTF-16) | UTF-16 ⟷ UTF-8 | N/A |
Windows | Non-Unicode (MBCS) | MBCS ⟷ UTF-8 | Windows 설정의 Use the default string of Non-Unicode 어플리케이션의 기본 문자열을 사용함application in Windows settings |
Linux | UTF-8 | N/A | UTF-8 만 지원됨only supported |