Skip to content

添加数据库配置项 - SetDbConfigEx

函数简介

保存用户自定义数据到数据库,默认使用 SetConfig 接口配置的数据库,如果未配置则返回失败。

接口名称

SetDbConfigEx

DLL调用

cpp
int SetDbConfigEx(long ola, string key, string value);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
key字符串配置项名,如"width"、"height"。
value字符串配置项值,如"100"。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
string val = ola.GetDbConfigEx("username");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
string val = ola.GetDbConfigEx("username");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ola.SetDbConfigEx("username", "admin")
ola.SetDbConfigEx("width", "1920")
val = ola.GetDbConfigEx("username")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
String val = ola.GetDbConfigEx("username");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ola.SetDbConfigEx("username", "admin")
ola.SetDbConfigEx("width", "1920")
val := ola.GetDbConfigEx("username")
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
ola.set_db_config_ex("username", "admin");
ola.set_db_config_ex("width", "1920");
let val = ola.get_db_config_ex("username");
cpp
var ola = com("OlaPlug.OlaSoft")
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
var val = ola.GetDbConfigEx("username")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
val = ola.GetDbConfigEx("username")
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.SetDbConfigEx("username", "admin")
ola.SetDbConfigEx("width", "1920")
val = ola.GetDbConfigEx(“username“)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
var val = ola.GetDbConfigEx("username");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
文本型 val = ola.GetDbConfigEx("username")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.SetDbConfigEx("username", "admin");
ola.SetDbConfigEx("width", "1920");
string val = ola.GetDbConfigEx("username");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
SetDbConfigEx(instance, "username", "admin");
long valPtr = GetDbConfigEx(instance, "username");
if (valPtr != 0) {
    char val[512] = {0};
    GetStringFromPtr(valPtr, val, sizeof(val));
    FreeStringPtr(valPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
SetDbConfigEx(instance, "username", "admin");
long valPtr = GetDbConfigEx(instance, "username");
if (valPtr != 0) {
    StringBuilder val = new StringBuilder(GetStringSize(valPtr) + 1);
    GetStringFromPtr(valPtr, val, val.Capacity);
    FreeStringPtr(valPtr);
    string valStr = val.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
SetDbConfigEx(instance, "username", "admin")
valPtr = GetDbConfigEx(instance, "username")
if valPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(valPtr, buf, 512)
    ola.FreeStringPtr(valPtr)
    val = buf.value.decode("utf-8")

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
该函数用于设置用户自定义数据该函数用于设置用户自定义数据,如账号密码、软件默认配置等信息。