필드 | 설명 |
---|---|
State | Represents a System.Data.ConnectionState 값을 나타낸다value. |
StatusString연결된 MachCommand 로 수행하는 상태를 나타낸다. Error Message 를 꾸미는 용도로 내부에서 사용되며, 작업이 시작된 상태를 나타내기 때문에 이 값으로 쿼리 상태를 체크하는 것은 | 적절하지 않다 Indicates the state to be performed by the connected MachCommand. This is used internally to decorate the Error Message and it is not appropriate to check the status of the query with this value because it indicates the state in which the operation started. |
Database | (미구현Not yet implemented) |
DataSource | (미구현Not yet implemented) |
ServerVersion | (미구현Not yet implemented) |
Info | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Connection String각 항목은 Each item is separated by a semicolon (;) 으로 구분되며, 다음을 사용할 수 있다. Many of the keywords in the same section have the same meaning.
As an example, we can prepare the following string.
|
MachCommand : DbCommand
MachConnection 을 이용해 SQL 명령 또는 APPEND 를 수행하는 클래스이다.
DbCommand 와 같이 IDisposable 을 상속받기 때문에, Dispose() 를 통한 객체 해제나 using() 문을 이용한 객체의 자동 Dispose를 지원한다.A class that performs SQL commands or APPEND using MachConnection .
Since it inherits IDisposable like DbCommand, it supports object disposal through Dispose () or automatic disposal of object using using () statement
생성자 | 설명 |
---|---|
MachCommand(string aQueryString, MachConnection)연결할 | MachConnection 객체와 함께, 수행할 쿼리를 입력해서 생성한다Creates by typing the query to be executed along with the MachConnection object to be connected. |
MachCommand(MachConnection) | 연결할 MachConnection 객체를 입력해서 생성한다. 수행할 쿼리가 없는 경우 (e.g. APPEND) 에만 사용한다Creates a MachConnection object to connect to. Use only if there is no query to perform (eg APPEND). |
메서드 | 설명 | ||||||
---|---|---|---|---|---|---|---|
void CreateParameter() / void CreateDbParameter() | 새로운 Creates a new MachParameter 를 생성한다. | ||||||
void Cancel() | (미구현Not yet implemented) | ||||||
void Prepare() | (미구현Not yet implemented) | ||||||
MachAppendWriter AppendOpen(aTableName, aErrorCheckCount = 0, MachAppendOption = None) | Starts APPEND 를 시작한다. Returns a MachAppendWriter 객체를 반환한다object.
말하자면, 자동 APPEND-FLUSH 지점을 정하는 셈이다.MachAppendOption : 현재는 하나의 옵션만 제공하고 있다
(DateTime 객체의 Ticks 값은 100 nanosecond 까지 표현된다
| ||||||
void AppendData(MachAppendWriter aWriter, List<object> aDataList) | Through the MachAppendWriter 객체를 통해, 데이터가 들어있는 리스트를 받아 데이터베이스에 입력한다.
Ui text box |
그 값에서, 1970-01-01 을 나타내는 DateTime Tick 값을 제외한 값을 입력해야 한다 object, it takes a list containing the data and enters it into the database.
| |||||
void AppendDataWithTime(MachAppendWriter aWriter, List<object> aDataList, DateTime aArrivalTime) | AppendData() 에서, Method that explicitly puts an _arrival_time 값을 DateTime 객체로 명시적으로 넣을 수 있는 메서드이다value into a DateTime object in AppendData(). | ||||||
void AppendDataWithTime(MachAppendWriter aWriter, List<object> aDataList, ulong aArrivalTimeLong) | AppendData() 에서, Method that can explicitly put _arrival_time 값을 ulong 객체로 명시적으로 넣을 수 있는 메서드이다.ulong 값을 _arrival_time 값으로 입력할 때 발생할 수 있는 문제는 위의 AppendData() 를 참고한다value into a ulong object in AppendData(). Refer to AppendData () above for problems that may occur when typing a ulong value as an _arrival_time value . | ||||||
void AppendFlush(MachAppendWriter aWriter) | The data entered by AppendData () 로 입력한 데이터들을 즉시 서버로 보내, 데이터 입력을 강제한다.호출 빈도가 잦을 수록, 성능은 떨어지지만 시스템 오류로 인한 데이터 유실율을 낮출 수 있고 에러 검사를 빠르게 할 수 있다. The more frequently the call is made, the lower the data loss rate due to the system error and the faster the error check, although the performance is lowered. | ||||||
void AppendClose(MachAppendWriter aWriter) | Closes APPEND 를 마친다. 내부적으로 . Internally, after calling AppendFlush() 를 호출한 뒤에 실제 프로토콜을 마친다, the actual protocol is internally finished. | ||||||
int ExecuteNonQuery() | 입력받았던 쿼리를 수행한다. 쿼리가 영향을 미친 레코드 개수를 반환한다. 보통 SELECT 를 제외한 쿼리를 수행할 때 사용한다Performs the input query. Returns the number of records affected by the query. It is usually used when performing queries except SELECT. | ||||||
object ExecuteScalar() | 입력받았던 쿼리를 수행한다. 쿼리 Targetlist 의 첫 번째 값을 객체로 반환한다. 보통 SELECT 쿼리, 그 중에서도 결과가 1건만 나오는 SELECT (Scalar Query) 를 수행해 DbDataReader 없이 결과를 받고자 하는 경우 사용한다.Performs the input query. Returns the first value of the query targetlist as an object. It is usually used when you want to perform a SELECT query, especially a SELECT (Scalar Query) with only one result, and get the result without a DbDataReader | ||||||
DbDataReader ExecuteDbDataReader(CommandBehavior aBehavior) | 입력받았던 쿼리를 수행해, 해당 쿼리의 결과를 읽어 올 수 있는 DbDataReader 를 생성해 반환한다Executes the input query, generates a DbDataReader that can read the result of the query, and returns it. |
필드 | 설명 |
---|---|
Connection / DbConnection | 연결된 Connected MachConnection. |
ParameterCollection / DbParameterCollection | Binding 목적으로 사용할 MachParameterCollectionThe MachParameterCollection to use for the Binding purpose. |
CommandText | 쿼리 문자열Query string. |
CommandTimeout | 특정 작업 수행 중, 서버로부터 응답을 기다리기까지의 시간. MachConnection 에 설정된 값을 따르며, 여기서는 값 참조만 할 수 있다. |
FetchSize | 한번에 서버로부터 Fetch 할 레코드 개수. 기본값은 3000 이다. |
IsAppendOpened | APPEND 작업 중인 경우, Append 가 이미 열려있는지 아닌지를 판단한다. |
CommandType | (미구현) |
DesignTimeVisible | (미구현) |
UpdatedRowSource | (미구현) |
MachDataReader : DbDataReader
Fetch 한 결과를 읽어들이는 클래스이다. 명시적으로 생성이 불가능하고 MachCommand.ExecuteDbDataReader() 로 생성된 객체만 사용이 가능하다The amount of time it takes to perform a particular task, waiting for a response from the server. It follows the values set in MachConnection, where you can only reference values. | |
FetchSize | The number of records to fetch from the server at one time . The default value is 3000. |
IsAppendOpened | Determines if Append is already open when APPEND is at work |
CommandType | (Not yet implemented) |
DesignTimeVisible | (Not yet implemented) |
UpdatedRowSource | (Not yet implemented) |
MachDataReader : DbDataReader
This is a class that reads fetch results. Only objects created with MachCommand.ExecuteDbDataReader () that can not be explicitly created are available.
메서드 | 설명 |
---|---|
string GetName(int ordinal) | ordinal 번째 컬럼 이름을 반환한다Returns the ordinal column name. |
string GetDataTypeName(int ordinal) | ordinal 번째 컬럼의 자료형 이름을 반환한다Returns the datatype name of the ordinal column. |
Type GetFieldType(int ordinal) | ordinal 번째 컬럼의 자료형을 반환한다Returns the datatype of the ordinal column. |
int GetOrdinal(string name) | 컬럼 이름이 위치한 인덱스를 반환한다Returns the index at which the column name is located. |
object GetValue(int ordinal) | 현재 위치한 레코드의 ordinal 번째 값을 반환한다Returns the ordinal value of the current record. |
bool IsDBNull(int ordinal) | 현재 위치한 레코드의 ordinal 번째 값이 NULL 인지 여부를 반환한다Returns whether the ordinal value of the current record is NULL. |
int GetValues(object[] values) | 현재 위치한 레코드의 모든 값들을 전부 설정하고, 그 개수를 반환한다Sets all the values of the current record and returns the number. |
xxxx GetXXXX(int ordinal) | ordinal 번째 컬럼 값을, 자료형 Returns the ordinal column value according to the datatype (XXXX) 에 맞춰 반환한다.
|
bool Read() | 다음 레코드를 읽는다. 결과가 존재하지 않으면 False 를 반환한다Reads the next record. Returns False if the result does not exist. |
DataTable GetSchemaTable() | (미지원Not supported) |
bool NextResult() | (미지원Not supported) |
필드 | 설명 |
---|---|
FetchSize | 한번에 서버로부터 Fetch 할 레코드 개수. 기본값은 3000 이며 여기서는 수정할 수 없다The number of records to fetch from the server at one time. The default is 3000, which can not be modified here. |
FieldCount | 결과 컬럼 개수Number of result columns. |
this[int ordinal] | Equivalent to object GetValue (int ordinal) 와 동일하다. |
this[string name] | object Equivalent to object GetValue(GetOrdinal(name)) 와 동일하다. |
HasRows결과가 | 존재하는지 여부를 나타낸다Indicates whether the result is present. |
RecordsAffected | Unlike MachCommand 의 것과 달리, 여기서는 , here, it represents Fetch Count 를 나타낸다. |
MachParameterCollection : DbParameterCollection
MachCommand 에 필요한 파라메터를 바인딩하는 클래스이다.
바인딩한 이후에 수행하게 되면, 해당 값이 같이 수행된다This is a class that binds parameters needed by MachCommand.
If you do this after binding, the values are done together.
Info |
---|
Since the concept of Prepared Statement 개념이 구현되어 있지 않아, Binding 이후 Execute 를 해도 수행 성능은 최초 수행한 것과 같다is not implemented, execution performance after Binding is the same as the performance performed first. |
메서드 | 설명 |
---|---|
MachParameter Add(string parameterName, DbType dbType) | 파라메터 이름과 타입을 지정해, MachParameter 를 추가한다. 추가된 MachParameter 객체를 반환한다 Adds the MachParameter, specifying the parameter name and type. Returns the added MachParameter object. |
int Add(object value) | 값을 추가한다. 추가된 인덱스를 반환한다Adds a value. Returns the index added. |
void AddRange(Array values) | 단순 값의 배열을 모두 추가한다Adds an array of simple values. |
MachParameter AddWithValue(string parameterName, object value) | 파라메터 이름과 그 값을 추가한다. 추가된 MachParameter 객체를 반환한다 Adds the parameter name and its value. Returns the added MachParameter object. |
bool Contains(object value) | 해당 값이 추가되었는지 여부를 판단한다Determines whether or not the corresponding value is added. |
bool Contains(string value) | 해당 파라메터 이름이 추가되었는지 여부를 판단한다Determines whether or not the corresponding parameter name is added. |
void Clear() | 파라메터들을 모두 삭제한다Deletes all parameters. |
int IndexOf(object value) | 해당 값의 인덱스를 반환한다Returns the index of the corresponding value. |
int IndexOf(string parameterName) | 해당 파라메터 이름의 인덱스를 반환한다Returns the index of the corresponding parameter name. |
void Insert(int index, object value) | 특정 인덱스에, 해당 값을 추가한다Adds the value to a specific index. |
void Remove(object value) | 해당 값을 포함한 파라메터를 삭제한다Deletes the parameter including the value. |
void RemoveAt(int index) | 인덱스에 위치한 파라메터를 삭제한다Deletes the parameter located at the index. |
void RemoveAt(string parameterName) | 해당 이름을 가진 파라메터를 삭제한다Deletes the parameter with that name. |
Field |
---|
Description |
---|
Count |
Number of parameters |
this[int index] |
Indicates the MachParameter at index. |
this[string name] |
Indicates the MachParameter of the order in which the parameter names match. |
MachParameter : DbParameter
MachCommand 에 필요한 파라메터를 각각 바인딩한 정보를 담는 클래스이다.
특별히 메서드는 지원하지 않는다.
This is a class that contains the information that binds the necessary parameters to each MachCommand.
No special methods are supported.
Field | Description |
---|---|
ParameterName | Parameter name |
Value | Value |
Size | Value size |
Direction | ParameterDirection (Input / Output / InputOutput / ReturnValue) |
The default value is Input |
. | |
DbType | DB Type |
MachDbType | MACHBASE DB Type May differ from DB Type |
. |
IsNullable |
Whether nullable | |
HasSetDbType | Whether DB Type |
is specified |
MachException : DbException
마크베이스에서 나타나는 에러를 표시하는 클래스이다.
에러 메시지가 설정되어 있는데, 모든 에러 메시지는 MachErrorMsg 에서 확인할 수 있다This is a class that displays errors that appear in Machbase.
An error message is set, and all error messages can be found in MachErrorMsg .
필드 | 설명 |
---|---|
int MachErrorCode | MACHBASE 에서 제공하는 에러 코드Error code provided by MACHBASE |
MachAppendWriter
MachCommand 를 사용하는 별도의 클래스로 APPEND 를 지원한다.
ADO.NET 표준이 아닌, MACHBASE 의 Append Protocol 을 지원하기 위한 클래스이다.
별도의 생성자 없이 MachCommand 의 AppendOpen() 으로 생성된다APPEND is supported as a separate class using MachCommand.
This is a class to support MACHBASE Append Protocol, not ADO.NET standard.
It is created with MachCommand's AppendOpen () without a separate constructor.
메서드 | 설명 |
---|---|
void SetErrorDelegator(ErrorDelegateFuncType aFunc) | 에러가 발생했을 때 호출할 ErrorDelegateFunc 을 지정한다Specifies the ErrorDelegateFunc to call when an error occurs. |
필드 | 설명 |
---|---|
SuccessCount | 입력 성공한 레코드 개수. Number of successful records. Is set after AppendClose() 이후 설정된다. |
FailureCount | 입력 실패한 레코드 개수. The number of records that failed input. Set after AppendClose () 이후 설정된다. |
Option | AppendOpenMachAppendOption received input during AppendOpen() 때 입력받은 MachAppendOption |
ErrorDelegateFuncType
Code Block | ||
---|---|---|
| ||
public delegate void ErrorDelegateFuncType(MachAppendException e); |
MachAppendWriter 에서, APPEND 도중 MACHBASE 서버 측에서 발생하는 Error 를 감지하기 위한 함수를 지정할 수 있다.
.NET 에서는 이 함수형을 Delegator Function 으로 지정한다In MachAppendWriter, you can specify a function to detect errors occurring on the MACHBASE server side during APPEND.
In .NET, this function type is specified as a Delegator Function.
MachAppendException : MachException
Same as MachException 과 동일하지만, 다음 점이 다르다.
- 에러 메시지가 서버 측으로부터 수신된다.
- 에러가 발생한 데이터 버퍼를 획득할 수 있다. (comma-separated) 이 데이터를 가공해 다시 APPEND 하거나 기록하는 용도로 사용할 수 있다.
해당 예외는 ErrorDelegateFunc 내부에서만 획득이 가능하다, except that:
- An error message is received from the server side.
- A data buffer in which an error has occurred can be obtained. (comma-separated) can be used to process and re-append or record data.
The exception is only available within the ErrorDelegateFunc.
메서드 | 설명 |
---|---|
GetRowBuffer() | 에러가 발생한 데이터 버퍼를 획득할 수 있다A data buffer in which an error has occurred can be obtained. |
MachTransaction
지원하지 않는다Not supported.
샘플 코드Sample Code
연결Connection
MachConnection 을 만들어 You can create a MachConnection and use Open () - Close () 하면 된다.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); MachConnection sConn = new MachConnection(sConnString); sConn.Open(); //... do something sConn.Close(); |
using 구문을 사용하면, Connection 종료 작업인 Close() 를 호출하지 않아도 된다If you use the using statement, you do not need to call Close (), which is a connection closing task.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); using (MachConnection sConn = new MachConnection(sConnString)) { sConn.Open(); //... do something } // you don't need to call sConn.Close(); |
Executing Queries
MachCommand 를 만들어 쿼리를 수행하면 된다Create a MachCommand and perform the query.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); using (MachConnection sConn = new MachConnection(sConnString)) { String sQueryString = "CREATE TABLE tab1 ( col1 INTEGER, col2 VARCHAR(20) )"; MachCommand sCommand = new MachCommand(sQueryString , sConn) try { sCommand.ExecuteNonQuery(); } catch (MachException me) { throw me; } } |
이 역시 using 구문을 사용하면, MachCommand 해제 작업을 곧바로 진행할 수 있다Again, using the using statement, MachCommand release can be done immediately.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); using (MachConnection sConn = new MachConnection(sConnString)) { String sQueryString = "CREATE TABLE tab1 ( col1 INTEGER, col2 VARCHAR(20) )"; using(MachCommand sCommand = new MachCommand(sQueryString , sConn)) { try { sCommand.ExecuteNonQuery(); } catch (MachException me) { throw me; } } } |
Executing SELECT
수행SELECT 쿼리를 가진 MachCommand 를 실행해 MachDataReader 를 얻을 수 있다.MachDataReader 를 통해 레코드를 하나씩 Fetch 할 수 있다
You can get a MachDataReader by executing a MachCommand with a SELECT query.
You can fetch the records one by one through the MachDataReader.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); using (MachConnection sConn = new MachConnection(sConnString)) { String sQueryString = "SELECT * FROM tab1;"; using(MachCommand sCommand = new MachCommand(sQueryString , sConn)) { try { MachDataReader sDataReader = sCommand.ExecuteReader(); while (sDataReader.Read()) { for (int i = 0; i < sDataReader.FieldCount; i++) { Console.WriteLine(String.Format("{0} : {1}", sDataReader.GetName(i), sDataReader.GetValue(i))); } } } catch (MachException me) { throw me; } } } |
파라메터 바인딩
MachParameterCollection 을 생성한 다음, MachCommand 에 연결해서 수행할 수 있다Parameter Binding
You can create a MachParameterCollection and then link it to a MachCommand.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); using (MachConnection sConn = new MachConnection(sConnString)) { string sSelectQuery = @"SELECT * FROM tab2 WHERE CreatedDateTime < @CurrentTime AND CreatedDateTime >= @PastTime"; using (MachCommand sCommand = new MachCommand(sSelectQuery, sConn)) { DateTime sCurrtime = DateTime.Now; DateTime sPastTime = sCurrtime.AddMinutes(-1); try { sCommand.ParameterCollection.Add(new MachParameter { ParameterName = "@CurrentTime", Value = sCurrtime }); sCommand.ParameterCollection.Add(new MachParameter { ParameterName = "@PastTime", Value = sPastTime }); MachDataReader sDataReader = sCommand.ExecuteReader(); while (sDataReader.Read()) { for (int i = 0; i < sDataReader.FieldCount; i++) { Console.WriteLine(String.Format("{0} : {1}", sDataReader.GetName(i), sDataReader.GetValue(i))); } } } catch (MachException me) { throw me; } } } |
APPEND
MachCommand 에서 When you run AppendOpen () 을 수행하면, MachAppendWriter 객체를 얻을 수 있다.이 객체와 MachCommand 를 이용해, 입력 레코드 1건을 리스트로 준비해 AppendData() 를 수행하면 입력이 이뤄진다on a MachCommand, you get a MachAppendWriter object.
Using this object and MachCommand, you can get a list of one input record and perform an AppendData ().
AppendFlush () 를 하면 모든 레코드의 입력이 반영되며, will reflect the input of all records, and AppendClose () 를 통해 Append 전체 과정을 종료할 수 있다will end the entire Append process.
Code Block | ||
---|---|---|
| ||
String sConnString = String.Format("DSN={0};PORT_NO={1};UID=;PWD=MANAGER;", SERVER_HOST, SERVER_PORT); using (MachConnection sConn = new MachConnection(sConnString)) { using (MachCommand sAppendCommand = new MachCommand(sConn)) { MachAppendWriter sWriter = sAppendCommand.AppendOpen("tab2"); sWriter.SetErrorDelegator(AppendErrorDelegator); var sList = new List<object>(); for (int i = 1; i <= 100000; i++) { sList.Add(i); sList.Add(String.Format("NAME_{0}", i % 100)); sAppendCommand.AppendData(sWriter, sList); sList.Clear(); if (i % 1000 == 0) { sAppendCommand.AppendFlush(); } } sAppendCommand.AppendClose(sWriter); Console.WriteLine(String.Format("Success Count : {0}", sWriter.SuccessCount)); Console.WriteLine(String.Format("Failure Count : {0}", sWriter.FailureCount)); } } |
Code Block | ||
---|---|---|
| ||
private static void AppendErrorDelegator(MachAppendException e) { Console.WriteLine("{0}", e.Message); Console.WriteLine("{0}", e.GetRowBuffer()); } |