init
This commit is contained in:
commit
70d467d052
97 files changed
+10386
No files matched your search
@@ -0,0 +1,69 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Linker files
|
||||
*.ilk
|
||||
|
||||
# Debugger Files
|
||||
*.pdb
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
*.so.*
|
||||
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# Build directories
|
||||
build/
|
||||
Build/
|
||||
build-*/
|
||||
|
||||
# CMake generated files
|
||||
CMakeFiles/
|
||||
CMakeCache.txt
|
||||
cmake_install.cmake
|
||||
#Makefile
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.log
|
||||
*.bak
|
||||
*.swp
|
||||
|
||||
# vcpkg
|
||||
vcpkg_installed/
|
||||
|
||||
# debug information files
|
||||
*.dwo
|
||||
|
||||
# test output & cache
|
||||
Testing/
|
||||
.cache/
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 建昌风物大顺脚本
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,37 @@
|
||||
VERSION := 0.0.1
|
||||
FRAMEWORK_NAME := us
|
||||
LIB_NAME := libus_sqlite3
|
||||
INSTL_TDIR := /lib
|
||||
INCLU_TDIR := /usr/include
|
||||
INCLU_SDIR := inc
|
||||
CPP := g++
|
||||
INCS := -I inc
|
||||
CPPFLAGS := --std=c++20 -O3 -pipe -Wall -Werror
|
||||
LIBS :=
|
||||
BUILD_TDIR := build
|
||||
$(shell mkdir -p $(BUILD_TDIR))
|
||||
|
||||
#--------
|
||||
#all: $(BUILD_TDIR)/$(LIB_NAME).so
|
||||
|
||||
#$(BUILD_TDIR)/$(LIB_NAME).so: $(BUILD_TDIR)/Thread.o
|
||||
# $(CPP) -shared $^ $(LIBS) -o $@
|
||||
|
||||
#$(BUILD_TDIR)/Thread.o: src/Thread.cpp
|
||||
# $(CPP) $(CPPFLAGS) -fPIC -c $^ $(INCS) -o $@
|
||||
|
||||
#clear:
|
||||
# @rm -rvf $(BUILD_TDIR)
|
||||
|
||||
install:
|
||||
@echo "install UniServe_libth..."
|
||||
@mkdir -vp $(INCLU_TDIR)/$(FRAMEWORK_NAME)
|
||||
@cp -vf $(INCLU_SDIR)/$(FRAMEWORK_NAME)/Sqlite3.hpp $(INCLU_TDIR)/$(FRAMEWORK_NAME)/
|
||||
# @cp -vf $(BUILD_TDIR)/$(LIB_NAME).so $(INSTL_TDIR)/
|
||||
@echo "done."
|
||||
|
||||
uninstall:
|
||||
@echo "uninstall UniServe_libth..."
|
||||
@rm -vf $(INCLU_TDIR)/$(FRAMEWORK_NAME)/Sqlite3.hpp
|
||||
# @rm -vf $(INSTL_TDIR)/$(LIB_NAME).so
|
||||
@echo "done."
|
||||
@@ -0,0 +1,5 @@
|
||||
# UniServe_libsqlite3
|
||||
UniServe Framework sqlite3 Library
|
||||
|
||||
# Dependancy
|
||||
libsqlite3-dev
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")" || exit
|
||||
#make clear
|
||||
#make
|
||||
make install
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sqlite3.h>
|
||||
namespace qing {
|
||||
|
||||
|
||||
class Sqlite3_stmt {
|
||||
public:
|
||||
Sqlite3_stmt(sqlite3 *db, const char *sql) {
|
||||
int rc = sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Failed to prepare sql stmt: " << sqlite3_errmsg(db) << std::endl;
|
||||
throw std::runtime_error("Failed to prepare sql stmt");
|
||||
}
|
||||
}
|
||||
|
||||
~Sqlite3_stmt() {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
void bind_int(int idx, int data) {
|
||||
int rc = sqlite3_bind_int(stmt, idx, data);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Failed to bind an integer to sql stmt." << std::endl;
|
||||
throw std::runtime_error("Failed to bind an integer to sql stmt");
|
||||
}
|
||||
}
|
||||
|
||||
void bind_text(int idx, const std::string &data) {
|
||||
int rc = sqlite3_bind_text(stmt, idx, data.c_str(), -1, SQLITE_TRANSIENT);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Failed to bind a text to sql stmt." << std::endl;
|
||||
throw std::runtime_error("Failed to bind a text to sql stmt");
|
||||
}
|
||||
}
|
||||
|
||||
bool step() {
|
||||
int rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
|
||||
throw std::runtime_error("Failed to query");
|
||||
}
|
||||
return rc == SQLITE_ROW && rc != SQLITE_DONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* int len = sqlite3_column_bytes(stmt, 1); // 获取字节长度(不含结束符)
|
||||
* std::string name(reinterpret_cast<const char*>(rawName), len);
|
||||
*/
|
||||
int read_int(int idx) {
|
||||
return sqlite3_column_int(stmt, idx);
|
||||
}
|
||||
|
||||
|
||||
const unsigned char *read_text(int idx) {
|
||||
return sqlite3_column_text(stmt, idx);
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3_stmt* stmt;
|
||||
};
|
||||
|
||||
class Sqlite3 {
|
||||
|
||||
public:
|
||||
Sqlite3(const std::string& filename) {
|
||||
int rc = sqlite3_open(filename.c_str(), &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Failed to open database: " << sqlite3_errmsg(db) << std::endl;
|
||||
sqlite3_close(db);
|
||||
throw std::runtime_error("Failed to open sqlite3 database.");
|
||||
}
|
||||
}
|
||||
|
||||
~Sqlite3() {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
bool exec(const std::string& sql) {
|
||||
char *errMsg;
|
||||
int rc = sqlite3_exec(db, sql.c_str(), 0, 0, &errMsg);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Failed to execute at sqlite3: " << errMsg << std::endl;
|
||||
sqlite3_free(errMsg);
|
||||
//sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Sqlite3_stmt stmt(std::string& sql) {
|
||||
return Sqlite3_stmt(db, sql.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3* db;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user