Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
|
90c86e72bd | 1 month ago |
@ -1 +1,3 @@ |
||||
*.o |
||||
build |
||||
.vscode |
||||
example |
||||
|
@ -1,61 +0,0 @@ |
||||
{ |
||||
"files.associations": { |
||||
"string": "cpp", |
||||
"vector": "cpp", |
||||
"*.tcc": "cpp", |
||||
"deque": "cpp", |
||||
"unordered_map": "cpp", |
||||
"system_error": "cpp", |
||||
"iostream": "cpp", |
||||
"type_traits": "cpp", |
||||
"tuple": "cpp", |
||||
"array": "cpp", |
||||
"utility": "cpp", |
||||
"cctype": "cpp", |
||||
"clocale": "cpp", |
||||
"cmath": "cpp", |
||||
"cstdarg": "cpp", |
||||
"cstddef": "cpp", |
||||
"cstdio": "cpp", |
||||
"cstdlib": "cpp", |
||||
"ctime": "cpp", |
||||
"cwchar": "cpp", |
||||
"cwctype": "cpp", |
||||
"atomic": "cpp", |
||||
"bit": "cpp", |
||||
"chrono": "cpp", |
||||
"compare": "cpp", |
||||
"concepts": "cpp", |
||||
"condition_variable": "cpp", |
||||
"cstdint": "cpp", |
||||
"map": "cpp", |
||||
"exception": "cpp", |
||||
"algorithm": "cpp", |
||||
"functional": "cpp", |
||||
"iterator": "cpp", |
||||
"memory": "cpp", |
||||
"memory_resource": "cpp", |
||||
"numeric": "cpp", |
||||
"optional": "cpp", |
||||
"random": "cpp", |
||||
"ratio": "cpp", |
||||
"string_view": "cpp", |
||||
"fstream": "cpp", |
||||
"initializer_list": "cpp", |
||||
"iosfwd": "cpp", |
||||
"istream": "cpp", |
||||
"limits": "cpp", |
||||
"mutex": "cpp", |
||||
"new": "cpp", |
||||
"numbers": "cpp", |
||||
"ostream": "cpp", |
||||
"semaphore": "cpp", |
||||
"sstream": "cpp", |
||||
"stdexcept": "cpp", |
||||
"stop_token": "cpp", |
||||
"streambuf": "cpp", |
||||
"thread": "cpp", |
||||
"cinttypes": "cpp", |
||||
"typeinfo": "cpp" |
||||
} |
||||
} |
@ -0,0 +1,69 @@ |
||||
cmake_minimum_required(VERSION 3.15) |
||||
project(SqliteCppWrapper LANGUAGES CXX) |
||||
|
||||
# Postavi standard za C++ |
||||
set(CMAKE_CXX_STANDARD 17) |
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
||||
|
||||
# Dodaj glavnu biblioteku |
||||
add_library(sqlitecpp STATIC |
||||
src/sqlite3.cpp |
||||
) |
||||
|
||||
# Uključi zaglavlja |
||||
target_include_directories(sqlitecpp |
||||
PUBLIC |
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib> |
||||
$<INSTALL_INTERFACE:include> |
||||
) |
||||
|
||||
# Poveži sa SQLite3 |
||||
find_package(SQLite3 REQUIRED) |
||||
target_link_libraries(sqlitecpp PRIVATE SQLite::SQLite3) |
||||
|
||||
# Generiši export fajl za lokalnu upotrebu |
||||
export(TARGETS sqlitecpp |
||||
FILE ${CMAKE_CURRENT_BINARY_DIR}/sqlitecppTargets.cmake |
||||
NAMESPACE sqlitecpp:: |
||||
) |
||||
|
||||
# Generiši sqlitecppConfig.cmake |
||||
include(CMakePackageConfigHelpers) |
||||
|
||||
configure_package_config_file( |
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlitecppConfig.cmake.in |
||||
${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfig.cmake |
||||
INSTALL_DESTINATION lib/cmake/sqlitecpp |
||||
) |
||||
|
||||
write_basic_package_version_file( |
||||
${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfigVersion.cmake |
||||
VERSION 1.0.0 |
||||
COMPATIBILITY SameMajorVersion |
||||
) |
||||
|
||||
# Instalacija za lokalnu upotrebu |
||||
install(TARGETS sqlitecpp |
||||
EXPORT sqlitecppTargets |
||||
ARCHIVE DESTINATION lib |
||||
LIBRARY DESTINATION lib |
||||
RUNTIME DESTINATION bin |
||||
) |
||||
|
||||
install(EXPORT sqlitecppTargets |
||||
FILE sqlitecppTargets.cmake |
||||
NAMESPACE sqlitecpp:: |
||||
DESTINATION lib/cmake/sqlitecpp |
||||
) |
||||
|
||||
install(FILES |
||||
${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfig.cmake |
||||
${CMAKE_CURRENT_BINARY_DIR}/sqlitecppConfigVersion.cmake |
||||
DESTINATION lib/cmake/sqlitecpp |
||||
) |
||||
|
||||
# Opcionalno dodaj testove |
||||
# enable_testing() |
||||
# add_subdirectory(test) |
||||
|
||||
add_subdirectory(test) |
@ -0,0 +1,3 @@ |
||||
@PACKAGE_INIT@ |
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/sqlitecppTargets.cmake") |
Binary file not shown.
@ -0,0 +1,6 @@ |
||||
add_executable(sqlitecpp_test main.cpp) |
||||
|
||||
target_link_libraries(sqlitecpp_test PRIVATE sqlitecpp SQLite::SQLite3) |
||||
|
||||
# Dodaj direktorijum za zaglavlja |
||||
target_include_directories(sqlitecpp_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib) |
@ -1 +0,0 @@ |
||||
g++ test.cpp ../src/* -o test.o -l sqlite3 |
@ -0,0 +1,35 @@ |
||||
#include "sqlite3.hpp" |
||||
#include <iostream> |
||||
|
||||
int main() { |
||||
try { |
||||
// Kreiraj instancu SQLite wrapper klase
|
||||
marcelb::SQlite3::SQLite3 db("test.db"); // test.db je naziv baze podataka
|
||||
|
||||
// Izvrši SQL upit za kreiranje tabele
|
||||
db.query("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT);"); |
||||
|
||||
// Ubaci podatke u tabelu
|
||||
db.query("INSERT INTO test (name) VALUES ('John Doe');"); |
||||
|
||||
// Izvrši SELECT upit i pročitaj podatke
|
||||
auto results = db.query("SELECT id, name FROM test;"); |
||||
|
||||
// Prikaži rezultate
|
||||
for (const auto& row : results) { |
||||
std::string id = row.first; |
||||
std::string name = row.second[0]; |
||||
std::cout << "ID: " << id << ", Name: " << name << std::endl; |
||||
} |
||||
} catch (const std::exception& e) { |
||||
std::cerr << "Error: " << e.what() << std::endl; |
||||
return 1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
// cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
// cmake --build . --target sqlitecpp_test
|
||||
// ./test/sqlitecpp_test
|
@ -1,28 +0,0 @@ |
||||
#include <iostream> |
||||
using namespace std; |
||||
|
||||
#include "../lib/sqlite3.hpp" |
||||
using namespace marcelb::SQlite3; |
||||
|
||||
int main() { |
||||
try { |
||||
|
||||
SQLite3 mydb("../example/example.db", false); |
||||
|
||||
auto res = mydb.query("Select * from Tab1"); |
||||
// cout << endl << res["NAME"][1];
|
||||
|
||||
// cout << endl << res["MAIL"][1];
|
||||
|
||||
for (auto i : res) { |
||||
for (auto j: i.second) { |
||||
cout << i.first << " : " << j << endl;
|
||||
} |
||||
} |
||||
|
||||
} catch (const string err) { |
||||
cout << err << endl; |
||||
} |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue