1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2026-06-20 09:19:27 +02:00

Пересборка SQLite для многопоточности

This commit is contained in:
Anton Titovets
2025-05-20 16:02:06 +03:00
parent 0269572175
commit d7b597037f
3 changed files with 47 additions and 28 deletions
+6 -6
View File
@@ -1,10 +1,10 @@
"MAIN ---"
linux-vdso.so.1 (0x00007ffcd9bf6000)
libm.so.6 => /lib64/libm.so.6 (0x00007f92c5ace000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f92c58ae000)
libc.so.6 => /lib64/libc.so.6 (0x00007f92c54d7000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f92c52d3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f92c5e50000)
linux-vdso.so.1 (0x00007fff2f736000)
libm.so.6 => /lib64/libm.so.6 (0x00007febb79bc000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007febb779c000)
libc.so.6 => /lib64/libc.so.6 (0x00007febb73c5000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007febb71c1000)
/lib64/ld-linux-x86-64.so.2 (0x00007febb7d3e000)
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.3.4
+20 -14
View File
@@ -12,11 +12,16 @@ pub fn execute_query(
force_result: bool
) -> String {
let conn = match client.get_connection() {
let conn_arc = match client.get_connection() {
Some(c) => c,
None => return format_json_error("No connection initialized"),
};
let conn = match conn_arc.lock() {
Ok(conn) => conn,
Err(_) => return format_json_error("Failed to acquire connection lock"),
};
// Парсинг JSON параметров
let mut parsed_params: Value = match serde_json::from_str(&params_json) {
Ok(params) => params,
@@ -62,31 +67,32 @@ pub fn execute_query(
}
pub fn load_extension(client: &mut component::AddIn, path: String, point: String) -> String {
let conn = match client.get_connection() {
let conn_arc = match client.get_connection() {
Some(c) => c,
None => return format_json_error("No connection initialized"),
};
let conn = match conn_arc.lock() {
Ok(conn) => conn,
Err(_) => return format_json_error("Failed to acquire connection lock"),
};
let entry_point = match point.is_empty() {
true => None,
false => Some(point.as_str())
};
unsafe {
// Здесь мы берем ссылку на Connection из MutexGuard
let _guard = match LoadExtensionGuard::new(&*conn) {
Ok(g) => g,
Err(e) => return format_json_error(e),
};
let guard = LoadExtensionGuard::new(conn);
match guard {
Err(e) => format_json_error(e),
Ok(_) => {
match conn.load_extension(path, entry_point){
Ok(_) => r#"{"result": true}"#.to_string(),
Err(e) => format_json_error(e)
}
}
match conn.load_extension(path, entry_point) {
Ok(_) => r#"{"result": true}"#.to_string(),
Err(e) => format_json_error(e)
}
}
}
+21 -8
View File
@@ -1,6 +1,7 @@
mod methods;
use addin1c::{name, Variant};
use std::sync::{Mutex, Arc};
use crate::core::getset;
use rusqlite::{Connection, OpenFlags};
use serde_json::json;
@@ -66,7 +67,7 @@ pub const PROPS: &[&[u16]] = &[
pub struct AddIn {
connection_string: String,
connection: Option<Connection>,
connection: Option<Arc<Mutex<Connection>>>,
}
impl AddIn {
@@ -91,7 +92,7 @@ impl AddIn {
match conn_result {
Ok(conn) => {
self.connection = Some(conn);
self.connection = Some(Arc::new(Mutex::new(conn)));
r#"{"result": true}"#.to_string()
}
Err(e) => {
@@ -116,17 +117,29 @@ impl AddIn {
}
}
pub fn get_connection(&self) -> Option<&Connection> {
self.connection.as_ref()
pub fn get_connection(&self) -> Option<Arc<Mutex<Connection>>> {
self.connection.clone()
}
pub fn close_connection(&mut self) -> String {
if let Some(conn) = self.connection.take() {
match conn.close() {
Ok(_) => json!({"result": true}).to_string(),
Err((_conn, err)) => json!({
match Arc::try_unwrap(conn) {
Ok(conn_mutex) => match conn_mutex.into_inner() {
Ok(conn) => match conn.close() {
Ok(_) => json!({"result": true}).to_string(),
Err((_conn, err)) => json!({
"result": false,
"error": err.to_string()
}).to_string(),
},
Err(_) => json!({
"result": false,
"error": "Failed to acquire connection lock"
}).to_string(),
},
Err(_) => json!({
"result": false,
"error": err.to_string()
"error": "Connection is still in use by other threads"
}).to_string(),
}
} else {