TD-1214 change csharp driver in win32
This commit is contained in:
parent
8db3120147
commit
bd16bb3d23
|
@ -354,7 +354,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, SMnodeMsg
|
||||||
mDebug("db:%s, already exist, ignore exist is set", pCreate->db);
|
mDebug("db:%s, already exist, ignore exist is set", pCreate->db);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
mError("db:%s, is already exist, ignore exist not set", pCreate->db);
|
mError("db:%s, already exist, ignore exist not set", pCreate->db);
|
||||||
return TSDB_CODE_MND_DB_ALREADY_EXIST;
|
return TSDB_CODE_MND_DB_ALREADY_EXIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -518,7 +518,7 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
|
||||||
SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
|
SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
|
||||||
if (pDnode != NULL) {
|
if (pDnode != NULL) {
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
mError("dnode:%d is already exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort);
|
mError("dnode:%d, already exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort);
|
||||||
return TSDB_CODE_MND_DNODE_ALREADY_EXIST;
|
return TSDB_CODE_MND_DNODE_ALREADY_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,46 +81,46 @@ namespace TDengineDriver
|
||||||
{
|
{
|
||||||
public const int TSDB_CODE_SUCCESS = 0;
|
public const int TSDB_CODE_SUCCESS = 0;
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_init", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_init", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public void Init();
|
static extern public void Init();
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_cleanup", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_cleanup", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public void Cleanup();
|
static extern public void Cleanup();
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_options", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_options", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public void Options(int option, string value);
|
static extern public void Options(int option, string value);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_connect", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_connect", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public long Connect(string ip, string user, string password, string db, short port);
|
static extern public IntPtr Connect(string ip, string user, string password, string db, short port);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_errstr", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_errstr", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern private IntPtr taos_errstr(long res);
|
static extern private IntPtr taos_errstr(IntPtr res);
|
||||||
static public string Error(long res)
|
static public string Error(IntPtr res)
|
||||||
{
|
{
|
||||||
IntPtr errPtr = taos_errstr(res);
|
IntPtr errPtr = taos_errstr(res);
|
||||||
return Marshal.PtrToStringAnsi(errPtr);
|
return Marshal.PtrToStringAnsi(errPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_errno", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_errno", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public int ErrorNo(long res);
|
static extern public int ErrorNo(IntPtr res);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_query", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_query", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public long Query(long conn, string sqlstr);
|
static extern public IntPtr Query(IntPtr conn, string sqlstr);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_affected_rows", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_affected_rows", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public int AffectRows(long res);
|
static extern public int AffectRows(IntPtr res);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_field_count", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_field_count", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public int FieldCount(long res);
|
static extern public int FieldCount(IntPtr res);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_fetch_fields", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_fetch_fields", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern private IntPtr taos_fetch_fields(long res);
|
static extern private IntPtr taos_fetch_fields(IntPtr res);
|
||||||
static public List<TDengineMeta> FetchFields(long res)
|
static public List<TDengineMeta> FetchFields(IntPtr res)
|
||||||
{
|
{
|
||||||
const int fieldSize = 68;
|
const int fieldSize = 68;
|
||||||
|
|
||||||
List<TDengineMeta> metas = new List<TDengineMeta>();
|
List<TDengineMeta> metas = new List<TDengineMeta>();
|
||||||
if (res == 0)
|
if (res == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
return metas;
|
return metas;
|
||||||
}
|
}
|
||||||
|
@ -142,13 +142,13 @@ namespace TDengineDriver
|
||||||
return metas;
|
return metas;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_fetch_row", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_fetch_row", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public IntPtr FetchRows(long res);
|
static extern public IntPtr FetchRows(IntPtr res);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_free_result", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_free_result", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public IntPtr FreeResult(long res);
|
static extern public IntPtr FreeResult(IntPtr res);
|
||||||
|
|
||||||
[DllImport("taos.dll", EntryPoint = "taos_close", CallingConvention = CallingConvention.StdCall)]
|
[DllImport("taos.dll", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern public int Close(long taos);
|
static extern public int Close(IntPtr taos);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@ namespace TDengineDriver
|
||||||
private long batchRows;
|
private long batchRows;
|
||||||
private long beginTimestamp = 1551369600000L;
|
private long beginTimestamp = 1551369600000L;
|
||||||
|
|
||||||
private long conn = 0;
|
private IntPtr conn = IntPtr.Zero;
|
||||||
private long rowsInserted = 0;
|
private long rowsInserted = 0;
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
|
@ -191,7 +191,7 @@ namespace TDengineDriver
|
||||||
{
|
{
|
||||||
string db = "";
|
string db = "";
|
||||||
this.conn = TDengine.Connect(this.host, this.user, this.password, db, this.port);
|
this.conn = TDengine.Connect(this.host, this.user, this.password, db, this.port);
|
||||||
if (this.conn == 0)
|
if (this.conn == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Connect to TDengine failed");
|
Console.WriteLine("Connect to TDengine failed");
|
||||||
ExitProgram();
|
ExitProgram();
|
||||||
|
@ -211,8 +211,8 @@ namespace TDengineDriver
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
sql.Append("create database if not exists ").Append(this.dbName);
|
sql.Append("create database if not exists ").Append(this.dbName);
|
||||||
long res = TDengine.Query(this.conn, sql.ToString());
|
IntPtr res = TDengine.Query(this.conn, sql.ToString());
|
||||||
if (res != 0)
|
if (res != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql.ToString() + " success");
|
Console.WriteLine(sql.ToString() + " success");
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ namespace TDengineDriver
|
||||||
sql.Clear();
|
sql.Clear();
|
||||||
sql.Append("use ").Append(this.dbName);
|
sql.Append("use ").Append(this.dbName);
|
||||||
res = TDengine.Query(this.conn, sql.ToString());
|
res = TDengine.Query(this.conn, sql.ToString());
|
||||||
if (res != 0)
|
if (res != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql.ToString() + " success");
|
Console.WriteLine(sql.ToString() + " success");
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ namespace TDengineDriver
|
||||||
sql.Clear();
|
sql.Clear();
|
||||||
sql.Append("create table if not exists ").Append(this.stableName).Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10)) tags(t1 int)");
|
sql.Append("create table if not exists ").Append(this.stableName).Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10)) tags(t1 int)");
|
||||||
res = TDengine.Query(this.conn, sql.ToString());
|
res = TDengine.Query(this.conn, sql.ToString());
|
||||||
if (res != 0)
|
if (res != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql.ToString() + " success");
|
Console.WriteLine(sql.ToString() + " success");
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ namespace TDengineDriver
|
||||||
sql = sql.Append("create table if not exists ").Append(this.tablePrefix).Append(i)
|
sql = sql.Append("create table if not exists ").Append(this.tablePrefix).Append(i)
|
||||||
.Append(" using ").Append(this.stableName).Append(" tags(").Append(i).Append(")");
|
.Append(" using ").Append(this.stableName).Append(" tags(").Append(i).Append(")");
|
||||||
res = TDengine.Query(this.conn, sql.ToString());
|
res = TDengine.Query(this.conn, sql.ToString());
|
||||||
if (res != 0)
|
if (res != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql.ToString() + " success");
|
Console.WriteLine(sql.ToString() + " success");
|
||||||
}
|
}
|
||||||
|
@ -297,8 +297,8 @@ namespace TDengineDriver
|
||||||
.Append(rows)
|
.Append(rows)
|
||||||
.Append(", 5, 6, 7, 'abc', 'def')");
|
.Append(", 5, 6, 7, 'abc', 'def')");
|
||||||
}
|
}
|
||||||
long res = TDengine.Query(conn, sql.ToString());
|
IntPtr res = TDengine.Query(this.conn, sql.ToString());
|
||||||
if (res == 0)
|
if (res == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
|
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
|
||||||
}
|
}
|
||||||
|
@ -327,13 +327,13 @@ namespace TDengineDriver
|
||||||
System.DateTime start = new System.DateTime();
|
System.DateTime start = new System.DateTime();
|
||||||
long queryRows = 0;
|
long queryRows = 0;
|
||||||
|
|
||||||
for (int i = 0; i < this.tableCount; ++i)
|
for (int i = 0; i < 1/*this.tableCount*/; ++i)
|
||||||
{
|
{
|
||||||
String sql = "select * from " + this.dbName + "." + tablePrefix + i;
|
String sql = "select * from " + this.dbName + "." + tablePrefix + i;
|
||||||
Console.WriteLine(sql);
|
Console.WriteLine(sql);
|
||||||
|
|
||||||
long res = TDengine.Query(conn, sql);
|
IntPtr res = TDengine.Query(conn, sql);
|
||||||
if (res == 0)
|
if (res == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql + " failure, reason: " + TDengine.Error(res));
|
Console.WriteLine(sql + " failure, reason: " + TDengine.Error(res));
|
||||||
ExitProgram();
|
ExitProgram();
|
||||||
|
@ -350,20 +350,21 @@ namespace TDengineDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
IntPtr rowdata;
|
IntPtr rowdata;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero)
|
while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
queryRows++;
|
queryRows++;
|
||||||
for (int fields = 0; fields < fieldCount; ++fields)
|
for (int fields = 0; fields < fieldCount; ++fields)
|
||||||
{
|
{
|
||||||
TDengineMeta meta = metas[fields];
|
TDengineMeta meta = metas[fields];
|
||||||
int offset = 8 * fields;
|
int offset = IntPtr.Size * fields;
|
||||||
IntPtr data = Marshal.ReadIntPtr(rowdata, offset);
|
IntPtr data = Marshal.ReadIntPtr(rowdata, offset);
|
||||||
|
|
||||||
//Console.Write("---");
|
builder.Append("---");
|
||||||
|
|
||||||
if (data == IntPtr.Zero)
|
if (data == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
//Console.Write("NULL");
|
builder.Append("NULL");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,47 +372,53 @@ namespace TDengineDriver
|
||||||
{
|
{
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_BOOL:
|
case TDengineDataType.TSDB_DATA_TYPE_BOOL:
|
||||||
bool v1 = Marshal.ReadByte(data) == 0 ? false : true;
|
bool v1 = Marshal.ReadByte(data) == 0 ? false : true;
|
||||||
//Console.Write(v1);
|
builder.Append(v1);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_TINYINT:
|
case TDengineDataType.TSDB_DATA_TYPE_TINYINT:
|
||||||
byte v2 = Marshal.ReadByte(data);
|
byte v2 = Marshal.ReadByte(data);
|
||||||
//Console.Write(v2);
|
builder.Append(v2);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_SMALLINT:
|
case TDengineDataType.TSDB_DATA_TYPE_SMALLINT:
|
||||||
short v3 = Marshal.ReadInt16(data);
|
short v3 = Marshal.ReadInt16(data);
|
||||||
//Console.Write(v3);
|
builder.Append(v3);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_INT:
|
case TDengineDataType.TSDB_DATA_TYPE_INT:
|
||||||
int v4 = Marshal.ReadInt32(data);
|
int v4 = Marshal.ReadInt32(data);
|
||||||
//Console.Write(v4);
|
builder.Append(v4);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_BIGINT:
|
case TDengineDataType.TSDB_DATA_TYPE_BIGINT:
|
||||||
long v5 = Marshal.ReadInt64(data);
|
long v5 = Marshal.ReadInt64(data);
|
||||||
//Console.Write(v5);
|
builder.Append(v5);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_FLOAT:
|
case TDengineDataType.TSDB_DATA_TYPE_FLOAT:
|
||||||
float v6 = (float)Marshal.PtrToStructure(data, typeof(float));
|
float v6 = (float)Marshal.PtrToStructure(data, typeof(float));
|
||||||
//Console.Write(v6);
|
builder.Append(v6);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_DOUBLE:
|
case TDengineDataType.TSDB_DATA_TYPE_DOUBLE:
|
||||||
double v7 = (double)Marshal.PtrToStructure(data, typeof(double));
|
double v7 = (double)Marshal.PtrToStructure(data, typeof(double));
|
||||||
//Console.Write(v7);
|
builder.Append(v7);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_BINARY:
|
case TDengineDataType.TSDB_DATA_TYPE_BINARY:
|
||||||
string v8 = Marshal.PtrToStringAnsi(data);
|
string v8 = Marshal.PtrToStringAnsi(data);
|
||||||
//Console.Write(v8);
|
builder.Append(v8);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP:
|
case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
long v9 = Marshal.ReadInt64(data);
|
long v9 = Marshal.ReadInt64(data);
|
||||||
//Console.Write(v9);
|
builder.Append(v9);
|
||||||
break;
|
break;
|
||||||
case TDengineDataType.TSDB_DATA_TYPE_NCHAR:
|
case TDengineDataType.TSDB_DATA_TYPE_NCHAR:
|
||||||
string v10 = Marshal.PtrToStringAnsi(data);
|
string v10 = Marshal.PtrToStringAnsi(data);
|
||||||
//Console.Write(v10);
|
builder.Append(v10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Console.WriteLine("---");
|
builder.Append("---");
|
||||||
|
|
||||||
|
if (queryRows <= 10)
|
||||||
|
{
|
||||||
|
Console.WriteLine(builder.ToString());
|
||||||
|
}
|
||||||
|
builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TDengine.ErrorNo(res) != 0)
|
if (TDengine.ErrorNo(res) != 0)
|
||||||
|
@ -431,9 +438,9 @@ namespace TDengineDriver
|
||||||
|
|
||||||
public void CloseConnection()
|
public void CloseConnection()
|
||||||
{
|
{
|
||||||
if (conn != 0)
|
if (this.conn != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
TDengine.Close(conn);
|
TDengine.Close(this.conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue