diff --git a/.gitignore b/.gitignore index 1530978..1478632 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*.o \ No newline at end of file +build +.vscode +example diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index de7e3a3..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -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" - } -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..de46055 --- /dev/null +++ b/CMakeLists.txt @@ -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 + $ + $ +) + +# 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) diff --git a/README.md b/README.md index 5ed7350..c745e65 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,11 @@ And compile your code ```bash g++ test.cpp ../src/* -o test.o -l sqlite3 + + +add_subdirectory(external/sqlitecpp) +target_link_libraries(my_project PRIVATE sqlitecpp) + ``` ## License diff --git a/cmake/sqlitecppConfig.cmake.in b/cmake/sqlitecppConfig.cmake.in new file mode 100644 index 0000000..a8a8ac5 --- /dev/null +++ b/cmake/sqlitecppConfig.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/sqlitecppTargets.cmake") diff --git a/example/example.db b/example/example.db deleted file mode 100644 index d674c75..0000000 Binary files a/example/example.db and /dev/null differ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..a95c5bb --- /dev/null +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/compile.sh b/test/compile.sh deleted file mode 100644 index d78b604..0000000 --- a/test/compile.sh +++ /dev/null @@ -1 +0,0 @@ -g++ test.cpp ../src/* -o test.o -l sqlite3 \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..0bddfa0 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,35 @@ +#include "sqlite3.hpp" +#include + +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 \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp deleted file mode 100644 index 9e059bd..0000000 --- a/test/test.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -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; -} \ No newline at end of file