[DO-982] add sqlite package (!13)
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/13
This commit is contained in:
14
recipes/sqlite3/all/test_package/CMakeLists.txt
Normal file
14
recipes/sqlite3/all/test_package/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(test_package LANGUAGES C)
|
||||
|
||||
option(USE_EMPTY_VFS "Using empty SQLite OS interface")
|
||||
|
||||
find_package(SQLite3 REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.c)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE SQLite::SQLite3)
|
||||
|
||||
if(USE_EMPTY_VFS)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_EMPTY_VFS)
|
||||
target_sources(${PROJECT_NAME} PRIVATE empty_vfs.c)
|
||||
endif()
|
||||
26
recipes/sqlite3/all/test_package/conanfile.py
Normal file
26
recipes/sqlite3/all/test_package/conanfile.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
|
||||
test_type = "explicit"
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if can_run(self):
|
||||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
self.run(bin_path, env="conanrun")
|
||||
90
recipes/sqlite3/all/test_package/empty_vfs.c
Normal file
90
recipes/sqlite3/all/test_package/empty_vfs.c
Normal file
@@ -0,0 +1,90 @@
|
||||
#include <sqlite3.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int empty_xOpen(sqlite3_vfs *vfs, const char *zName, sqlite3_file *f, int flags, int *pOutFlags)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int empty_xDelete(sqlite3_vfs *vfs, const char *zName, int syncDir)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int empty_xAccess(sqlite3_vfs *vfs, const char *zName, int flags, int *pResOut)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int empty_xFullPathname(sqlite3_vfs *vfs, const char *zName, int nOut, char *zOut)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int empty_xRandomness(sqlite3_vfs *vfs, int nByte, char *zOut)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int empty_xSleep(sqlite3_vfs *vfs, int microseconds)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int empty_xCurrentTime(sqlite3_vfs *vfs, double *t)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int empty_xGetLastError(sqlite3_vfs *vfs, int code, char *name)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int empty_xCurrentTimeInt64(sqlite3_vfs *vfs, sqlite3_int64 *t)
|
||||
{
|
||||
// TODO: implement
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
// empty VFS will be provided
|
||||
int sqlite3_os_init(void)
|
||||
{
|
||||
static sqlite3_vfs emptyVFS =
|
||||
{
|
||||
2, /* iVersion */
|
||||
0, /* szOsFile */
|
||||
100, /* mxPathname */
|
||||
NULL, /* pNext */
|
||||
"empty", /* zName */
|
||||
NULL, /* pAppData */
|
||||
empty_xOpen, /* xOpen */
|
||||
empty_xDelete, /* xDelete */
|
||||
empty_xAccess, /* xAccess */
|
||||
empty_xFullPathname, /* xFullPathname */
|
||||
NULL, /* xDlOpen */
|
||||
NULL, /* xDlError */
|
||||
NULL, /* xDlSym */
|
||||
NULL, /* xDlClose */
|
||||
empty_xRandomness, /* xRandomness */
|
||||
empty_xSleep, /* xSleep */
|
||||
empty_xCurrentTime, /* xCurrentTime */
|
||||
empty_xGetLastError, /* xGetLastError */
|
||||
empty_xCurrentTimeInt64, /* xCurrentTimeInt64 */
|
||||
NULL, /* xSetSystemCall */
|
||||
NULL, /* xGetSystemCall */
|
||||
NULL, /* xNextSystemCall */
|
||||
};
|
||||
|
||||
sqlite3_vfs_register(&emptyVFS, 1);
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int sqlite3_os_end(void)
|
||||
{
|
||||
return SQLITE_OK;
|
||||
}
|
||||
46
recipes/sqlite3/all/test_package/test_package.c
Normal file
46
recipes/sqlite3/all/test_package/test_package.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#ifdef USE_EMPTY_VFS
|
||||
#define DB_NAME ":memory:"
|
||||
#else
|
||||
#define DB_NAME "bincrafters.db"
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
sqlite3* db_instance = NULL;
|
||||
char* errmsg = NULL;
|
||||
int result = 0;
|
||||
|
||||
printf("SQLite Version: %s\n", sqlite3_libversion());
|
||||
|
||||
printf("Creating new data base ...\n");
|
||||
result = sqlite3_open(DB_NAME, &db_instance);
|
||||
if (result != SQLITE_OK) {
|
||||
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db_instance));
|
||||
sqlite3_close(db_instance);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Done!\n");
|
||||
|
||||
printf("Creating new table...\n");
|
||||
result = sqlite3_exec(db_instance, "CREATE TABLE IF NOT EXISTS package(ID INT PRIMARY KEY NOT NULL);", NULL, 0, &errmsg);
|
||||
if(result != SQLITE_OK) {
|
||||
fprintf(stderr, "SQL error: %s\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Done!\n");
|
||||
|
||||
printf("Closing connection ...\n");
|
||||
sqlite3_close(db_instance);
|
||||
if(result != SQLITE_OK) {
|
||||
fprintf(stderr, "Connection error: %s\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Done!\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user