读取string数据 - GetString
函数简介
读取string类型的数据
函数原型
long GetString(long ola, long stmt, int columnIndex);
参数定义
ola
(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。stmt
(长整型数): 数据库语句对象指针,由 ExecuteReader 接口返回。columnIndex
(整型数): 列索引,从0开始。
返回值
- 返回值:数据的值。
示例
SDK
C#
using System;
using OLA.ServiceCenter.PlugFactory;
namespace OLADemo
{
internal class Program
{
static OLAPlugServer OLAServer;
static void Main(string[] args)
{
OLAServer = new OLAPlugServer();
var regResult = OLAServer.Reg(
OLAServer.UserCode,
OLAServer.SoftCode,
OLAServer.FeatureList
);
OLAServer.CreateCOLAPlugInterFace();
long db = OLAServer.OpenDatabase("OLAPlugDemo.db", "olaplug");
Console.WriteLine($"OpenDatabase 返回:{db}");
// 执行SQL语句(插入操作)
string tableName = "user";
result = OLAServer.ExecuteSql(db, $"DROP TABLE IF EXISTS {tableName}");
result = OLAServer.ExecuteSql(db, $"CREATE TABLE {tableName} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, balance REAL)");
result = OLAServer.ExecuteSql(db, $"DELETE FROM {tableName} WHERE 1=1");
for (int i = 1; i <= 5; i++)
{
result = OLAServer.ExecuteSql(db, $"INSERT INTO {tableName}(name, balance) VALUES ('用户{i}', {100 + i / 100})");
Console.WriteLine($"ExecuteSql 插入数据 返回:{result}");
}
//读取数据
long stmt = OLAServer.ExecuteReader(db, $"SELECT * FROM {tableName}");
while (OLAServer.Read(stmt))
{
var id = OLAServer.GetInt32(stmt, 0);
var name = OLAServer.GetString(stmt, 1);
var balance = OLAServer.GetDouble(stmt, 2);
Console.WriteLine($"Read 数据:id={id},name={name},balance={balance}");
};
}
}
}
Python
# 待补充
原生方式
Python
# 待补充