Skip to content

Commit

Permalink
database: add sqlite support
Browse files Browse the repository at this point in the history
enable UTILS_SQLITE configuration, use the sqlite3 command line tool

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
  • Loading branch information
Gary-Hobson authored and acassis committed Mar 4, 2024
1 parent 110fa82 commit c8e0d7a
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 0 deletions.
21 changes: 21 additions & 0 deletions database/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
############################################################################
# apps/database/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(wildcard $(APPDIR)/database/*/Make.defs)
23 changes: 23 additions & 0 deletions database/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/database/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

MENUDESC = "Database"

include $(APPDIR)/Directory.mk
3 changes: 3 additions & 0 deletions database/sqlite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build
/sqlite
*.zip
26 changes: 26 additions & 0 deletions database/sqlite/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config LIB_SQLITE
bool "SQLITE library"
depends on CONFIG_FS_LOCK_BUCKET_SIZE > 0
default n

if LIB_SQLITE

config LIB_SQLITE_VERSION
string "SQLITE version"
default "3.45.1"

config UTILS_SQLITE
tristate "SQLite cmd line tool"
default n

config UTILS_SQLITE_STACKSIZE
int "SQLite3 cmd line tool stack size"
default 8192
depends on UTILS_SQLITE

endif
23 changes: 23 additions & 0 deletions database/sqlite/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/database/sqlite/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_LIB_SQLITE),)
CONFIGURED_APPS += $(APPDIR)/database/sqlite
endif
68 changes: 68 additions & 0 deletions database/sqlite/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
############################################################################
# apps/database/sqlite/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

SQLITEDIR=$(APPDIR)/database/sqlite
BUILDDIR=$(SQLITEDIR)/build

CSRCS += ${BUILDDIR}/sqlite3.c

CFLAGS += ${INCDIR_PREFIX}$(SQLITEDIR)
CFLAGS += ${DEFINE_PREFIX}_HAVE_SQLITE_CONFIG_H
CFLAGS += ${DEFINE_PREFIX}NDEBUG
CFLAGS += -Wno-unused-variable -Wno-undef -Wno-unused-function -Wno-shadow

ifneq ($(CONFIG_UTILS_SQLITE),)
PROGNAME = sqlite3
PRIORITY = 100
STACKSIZE = ${CONFIG_UTILS_SQLITE_STACKSIZE}
MAINSRC = ${BUILDDIR}/shell.c
endif


# Download and unpack tarball if no git repo found

sqlite.zip:
ifeq ($(wildcard sqlite/.git),)
$(Q) curl -L https://codeload.github.com/sqlite/sqlite/zip/refs/tags/vesion-${CONFIG_LIB_SQLITE_VERSION} -o sqlite.zip
$(Q) unzip -q -o sqlite.zip
$(Q) mv sqlite-vesion-* sqlite
$(call DELFILE, sqlite.zip)
endif

context:: sqlite.zip
$(Q) mkdir -p ${BUILDDIR} && \
cd ${BUILDDIR} && \
echo "Generate SQLite amalgamation version" && \
${SQLITEDIR}/sqlite/configure 1> /dev/null && \
make sqlite3.c -j 1> /dev/null

clean::
$(call DELFILE, ${BUILDDIR}/*.o)

distclean::
$(call DELDIR, ${BUILDDIR})
ifeq ($(wildcard sqlite/.git),)
$(call DELDIR, sqlite)
endif

include $(APPDIR)/Application.mk

145 changes: 145 additions & 0 deletions database/sqlite/sqlite_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* sqlite_cfg.h. Generated from sqlite_cfg.h.in by configure. */
/* sqlite_cfg.h.in. Generated from configure.ac by autoheader. */

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Define to 1 if you have the `fdatasync' function. */
#define HAVE_FDATASYNC 1

/* Define to 1 if you have the `gmtime_r' function. */
#define HAVE_GMTIME_R 1

/* Define to 1 if the system has the type `int16_t'. */
#define HAVE_INT16_T 1

/* Define to 1 if the system has the type `int32_t'. */
#define HAVE_INT32_T 1

/* Define to 1 if the system has the type `int64_t'. */
#define HAVE_INT64_T 1

/* Define to 1 if the system has the type `int8_t'. */
#define HAVE_INT8_T 1

/* Define to 1 if the system has the type `intptr_t'. */
#define HAVE_INTPTR_T 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the `isnan' function. */
#define HAVE_ISNAN 1

/* Define to 1 if you have the `localtime_r' function. */
#define HAVE_LOCALTIME_R 1

/* Define to 1 if you have the `localtime_s' function. */
/* #undef HAVE_LOCALTIME_S */

/* Define to 1 if you have the <malloc.h> header file. */
#define HAVE_MALLOC_H 1

/* Define to 1 if you have the `malloc_usable_size' function. */
#define HAVE_MALLOC_USABLE_SIZE 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the `pread' function. */
#define HAVE_PREAD 1

/* Define to 1 if you have the `pread64' function. */
#define HAVE_PREAD64 1

/* Define to 1 if you have the `pwrite' function. */
#define HAVE_PWRITE 1

/* Define to 1 if you have the `pwrite64' function. */
#define HAVE_PWRITE64 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the `strchrnul' function. */
#define HAVE_STRCHRNUL 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if the system has the type `uint16_t'. */
#define HAVE_UINT16_T 1

/* Define to 1 if the system has the type `uint32_t'. */
#define HAVE_UINT32_T 1

/* Define to 1 if the system has the type `uint64_t'. */
#define HAVE_UINT64_T 1

/* Define to 1 if the system has the type `uint8_t'. */
#define HAVE_UINT8_T 1

/* Define to 1 if the system has the type `uintptr_t'. */
#define HAVE_UINTPTR_T 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to 1 if you have the `usleep' function. */
#define HAVE_USLEEP 1

/* Define to 1 if you have the `utime' function. */
#define HAVE_UTIME 1

/* Define to 1 if you have the <zlib.h> header file. */
#ifdef CONFIG_LIB_ZLIB
# define HAVE_ZLIB_H 1
#endif

/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""

/* Define to the full name of this package. */
#define PACKAGE_NAME "sqlite"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "sqlite 3.45.1"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "sqlite"

/* Define to the home page for this package. */
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "3.45.1"

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif

/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */

/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */

0 comments on commit c8e0d7a

Please sign in to comment.