* [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring @ 2018-10-02 20:50 AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin ` (3 more replies) 0 siblings, 4 replies; 9+ messages in thread From: AlexeyIvushkin @ 2018-10-02 20:50 UTC (permalink / raw) To: tarantool-patches; +Cc: Morgan-iv From: Morgan-iv <ivushkinalex@gmail.com> These 2 patches are the beginning of SQLite error codes refactoring. Both of them change implementation of affected error codes from define macro to enum statement, and remove codes that aren't returned anywhere, but first also remove related function that aren't called anywhere too. First patch affects SQLITE_IOERR_ codes, second - SQLITE_CONSTRAINT_ codes. Final rename of all error codes affected in these 2 patches and the next several patches in this branch will be applied after removing all unused error codes and removing all found unused functions related to affected SQLite error codes Issue: https://github.com/tarantool/tarantool/issues/3315 Branch: https://github.com/tarantool/tarantool/tree/Morgan-iv/gh-3315 Morgan-iv (2): sql: refactor SQLITE_IOERR_ error codes sql: remove unused SQLITE_CONSTRAINT_ error codes src/box/sql/main.c | 51 ---------------------------- src/box/sql/os_unix.c | 88 ------------------------------------------------- src/box/sql/sqliteInt.h | 56 ++++++++++++------------------- 3 files changed, 21 insertions(+), 174 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] [PATCH] box: add tuple:size function 2018-10-02 20:50 [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring AlexeyIvushkin @ 2018-10-02 20:50 ` AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes AlexeyIvushkin ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: AlexeyIvushkin @ 2018-10-02 20:50 UTC (permalink / raw) To: tarantool-patches; +Cc: Morgan-iv From: Morgan-iv <ivushkinalex@gmail.com> When operating with tuples, we only have tuple:bsize function to get size of tuple. tuple:bsize returns only size of MessagePack part of struct tuple, without tuple_meta. New function tuple:size returns size of all tuple, with MessagePack and tuple_meta Closes #2256 --- https://github.com/tarantool/tarantool/issues/2256 https://github.com/tarantool/tarantool/tree/Morgan-iv/gh-2256 src/box/lua/tuple.c | 10 ++++++++++ src/box/lua/tuple.lua | 1 + test/box/tuple.result | 12 ++++++++++++ test/box/tuple.test.lua | 6 ++++++ 4 files changed, 29 insertions(+) diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c index 65660ce..1ae49d6 100644 --- a/src/box/lua/tuple.c +++ b/src/box/lua/tuple.c @@ -489,6 +489,15 @@ lbox_tuple_to_string(struct lua_State *L) return 1; } +static int +lbox_tuple_size(struct lua_State *L) +{ + struct tuple *tuple = lua_checktuple(L, 1); + size_t size = tuple_size(tuple); + lua_pushinteger(L, size); + return 1; +} + void luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple) { @@ -506,6 +515,7 @@ static const struct luaL_Reg lbox_tuple_meta[] = { {"__gc", lbox_tuple_gc}, {"tostring", lbox_tuple_to_string}, {"slice", lbox_tuple_slice}, + {"size", lbox_tuple_size}, {"transform", lbox_tuple_transform}, {"tuple_to_map", lbox_tuple_to_map}, {"tuple_field_by_path", lbox_tuple_field_by_path}, diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index 63ea73e..801ee3c 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -286,6 +286,7 @@ local methods = { ["update"] = tuple_update; ["upsert"] = tuple_upsert; ["bsize"] = tuple_bsize; + ["size"] = internal.tuple.size; ["tomap"] = internal.tuple.tuple_to_map; } diff --git a/test/box/tuple.result b/test/box/tuple.result index e035cb9..418f5f8 100644 --- a/test/box/tuple.result +++ b/test/box/tuple.result @@ -186,6 +186,18 @@ t:bsize() --- - 5 ... +-- tuple:size() +t = box.tuple.new('abc') +--- +... +t +--- +- ['abc'] +... +t:size() +--- +- 15 +... -- -- Test cases for #106 box.tuple.new fails on multiple items -- diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua index 9df978d..7f4e2b3 100644 --- a/test/box/tuple.test.lua +++ b/test/box/tuple.test.lua @@ -49,6 +49,12 @@ t = box.tuple.new('abc') t t:bsize() +-- tuple:size() + +t = box.tuple.new('abc') +t +t:size() + -- -- Test cases for #106 box.tuple.new fails on multiple items -- -- 2.7.4 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes 2018-10-02 20:50 [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin @ 2018-10-02 20:50 ` AlexeyIvushkin 2018-10-03 20:06 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-02 20:50 ` [tarantool-patches] [PATCH 2/2] sql: remove unused SQLITE_CONSTRAINT_ " AlexeyIvushkin 2018-10-03 20:04 ` [tarantool-patches] Re: [PATCH 0/2] First part of SQLite error codes refactoring Vladislav Shpilevoy 3 siblings, 1 reply; 9+ messages in thread From: AlexeyIvushkin @ 2018-10-02 20:50 UTC (permalink / raw) To: tarantool-patches; +Cc: Morgan-iv From: Morgan-iv <ivushkinalex@gmail.com> Remove error codes with prefix SQLITE_IOERR_ that only defined, but don't used anywhere. Replace '#define' macro with enum statement in implementation of SQLITE_IOERR_ error codes Remove unused function xDelete from sqlite3_vfs interface and its implementation, unixDelete. Also remove function openDirectory, used only in unixDelete Part of #3315 --- src/box/sql/main.c | 42 ----------------------- src/box/sql/os_unix.c | 88 ------------------------------------------------- src/box/sql/sqliteInt.h | 43 +++++++++--------------- 3 files changed, 15 insertions(+), 158 deletions(-) diff --git a/src/box/sql/main.c b/src/box/sql/main.c index 782f994..532d324 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -784,12 +784,6 @@ sqlite3ErrName(int rc) case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break; - case SQLITE_IOERR_FSYNC: - zName = "SQLITE_IOERR_FSYNC"; - break; - case SQLITE_IOERR_DIR_FSYNC: - zName = "SQLITE_IOERR_DIR_FSYNC"; - break; case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break; @@ -802,54 +796,18 @@ sqlite3ErrName(int rc) case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break; - case SQLITE_IOERR_DELETE: - zName = "SQLITE_IOERR_DELETE"; - break; case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break; case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break; - case SQLITE_IOERR_CHECKRESERVEDLOCK: - zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; - break; - case SQLITE_IOERR_LOCK: - zName = "SQLITE_IOERR_LOCK"; - break; case SQLITE_IOERR_CLOSE: zName = "SQLITE_IOERR_CLOSE"; break; - case SQLITE_IOERR_DIR_CLOSE: - zName = "SQLITE_IOERR_DIR_CLOSE"; - break; - case SQLITE_IOERR_SHMOPEN: - zName = "SQLITE_IOERR_SHMOPEN"; - break; - case SQLITE_IOERR_SHMSIZE: - zName = "SQLITE_IOERR_SHMSIZE"; - break; - case SQLITE_IOERR_SHMLOCK: - zName = "SQLITE_IOERR_SHMLOCK"; - break; - case SQLITE_IOERR_SHMMAP: - zName = "SQLITE_IOERR_SHMMAP"; - break; - case SQLITE_IOERR_SEEK: - zName = "SQLITE_IOERR_SEEK"; - break; - case SQLITE_IOERR_DELETE_NOENT: - zName = "SQLITE_IOERR_DELETE_NOENT"; - break; - case SQLITE_IOERR_MMAP: - zName = "SQLITE_IOERR_MMAP"; - break; case SQLITE_IOERR_GETTEMPPATH: zName = "SQLITE_IOERR_GETTEMPPATH"; break; - case SQLITE_IOERR_CONVPATH: - zName = "SQLITE_IOERR_CONVPATH"; - break; case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break; diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c index b8816e0..5de722d 100644 --- a/src/box/sql/os_unix.c +++ b/src/box/sql/os_unix.c @@ -990,53 +990,6 @@ unixWrite(sqlite3_file * id, const void *pBuf, int amt, sqlite3_int64 offset) } /* - * Open a file descriptor to the directory containing file zFilename. - * If successful, *pFd is set to the opened file descriptor and - * SQLITE_OK is returned. If an error occurs, either SQLITE_NOMEM - * or SQLITE_CANTOPEN is returned and *pFd is set to an undefined - * value. - * - * The directory file descriptor is used for only one thing - to - * fsync() a directory to make sure file creation and deletion events - * are flushed to disk. Such fsyncs are not needed on newer - * journaling filesystems, but are required on older filesystems. - * - * This routine can be overridden using the xSetSysCall interface. - * The ability to override this routine was added in support of the - * chromium sandbox. Opening a directory is a security risk (we are - * told) so making it overrideable allows the chromium sandbox to - * replace this routine with a harmless no-op. To make this routine - * a no-op, replace it with a stub that returns SQLITE_OK but leaves - * *pFd set to a negative number. - * - * If SQLITE_OK is returned, the caller is responsible for closing - * the file descriptor *pFd using close(). - */ -static int -openDirectory(const char *zFilename, int *pFd) -{ - int ii; - int fd; - char zDirname[MAX_PATHNAME + 1]; - - sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename); - for (ii = (int)strlen(zDirname); ii > 0 && zDirname[ii] != '/'; ii--) ; - if (ii > 0) { - zDirname[ii] = '\0'; - } else { - if (zDirname[0] != '/') - zDirname[0] = '.'; - zDirname[1] = 0; - } - fd = robust_open(zDirname, O_RDONLY | O_BINARY, 0); - - *pFd = fd; - if (fd >= 0) - return SQLITE_OK; - return unixLogError(SQLITE_CANTOPEN_BKPT, "openDirectory", zDirname); -} - -/* * This function is called to handle the SQLITE_FCNTL_SIZE_HINT * file-control operation. Enlarge the database to nBytes in size * (rounded up to the next chunk-size). If the database is already @@ -1923,46 +1876,6 @@ unixOpen(sqlite3_vfs * pVfs, /* The VFS for which this is the xOpen method */ } /* - * Delete the file at zPath. If the dirSync argument is true, fsync() - * the directory after deleting the file. - */ -static int -unixDelete(sqlite3_vfs * NotUsed, /* VFS containing this as the xDelete method */ - const char *zPath, /* Name of file to be deleted */ - int dirSync /* If true, fsync() directory after deleting file */ - ) -{ - int rc = SQLITE_OK; - UNUSED_PARAMETER(NotUsed); - if (unlink(zPath) == (-1)) { - if (errno == ENOENT) { - rc = SQLITE_IOERR_DELETE_NOENT; - } else { - rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); - } - return rc; - } -#ifndef SQLITE_DISABLE_DIRSYNC - if ((dirSync & 1) != 0) { - int fd; - rc = openDirectory(zPath, &fd); - if (rc == SQLITE_OK) { - struct stat buf; - if (fstat(fd, &buf)) { - rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, - "fsync", zPath); - } - robust_close(0, fd, __LINE__); - } else { - assert(rc == SQLITE_CANTOPEN); - rc = SQLITE_OK; - } - } -#endif - return rc; -} - -/* * Write nBuf bytes of random data to the supplied buffer zBuf. */ static int @@ -2076,7 +1989,6 @@ unixGetLastError(sqlite3_vfs * NotUsed, int NotUsed2, char *NotUsed3) VFSNAME, /* zName */ \ (void*)&FINDER, /* pAppData */ \ unixOpen, /* xOpen */ \ - unixDelete, /* xDelete */ \ unixRandomness, /* xRandomness */ \ unixSleep, /* xSleep */ \ NULL, /* xCurrentTime */ \ diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 53188e7..00c0309 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -336,7 +336,6 @@ struct sqlite3_vfs { void *pAppData; /* Pointer to application-specific data */ int (*xOpen) (sqlite3_vfs *, const char *zName, sqlite3_file *, int flags, int *pOutFlags); - int (*xDelete) (sqlite3_vfs *, const char *zName, int syncDir); int (*xRandomness) (sqlite3_vfs *, int nByte, char *zOut); int (*xSleep) (sqlite3_vfs *, int microseconds); int (*xCurrentTime) (sqlite3_vfs *, double *); @@ -605,33 +604,21 @@ sqlite3_exec(sqlite3 *, /* An open database */ void *, /* 1st argument to callback */ char **errmsg /* Error msg written here */ ); -#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) -#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) -#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) -#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) -#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) -#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) -#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) -#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) -#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) -#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) -#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) -#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) -#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) -#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) -#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) -#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) -#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) -#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) -#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) -#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) -#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) -#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) -#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) -#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) -#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) -#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) -#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) + +enum sql_ioerr_code { + SQLITE_IOERR_READ = (SQLITE_IOERR | (1<<8)), + SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2<<8)), + SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3<<8)), + SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (4<<8)), + SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (5<<8)), + SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (6<<8)), + SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (7<<8)), + SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (8<<8)), + SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (9<<8)), + SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (10<<8)), + SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (11<<8)) +}; + #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) -- 2.7.4 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes 2018-10-02 20:50 ` [tarantool-patches] [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes AlexeyIvushkin @ 2018-10-03 20:06 ` Vladislav Shpilevoy 0 siblings, 0 replies; 9+ messages in thread From: Vladislav Shpilevoy @ 2018-10-03 20:06 UTC (permalink / raw) To: tarantool-patches, AlexeyIvushkin Thanks for the patch! See 2 comments below. On 02/10/2018 23:50, AlexeyIvushkin wrote: > From: Morgan-iv <ivushkinalex@gmail.com> > > Remove error codes with prefix SQLITE_IOERR_ that only defined, > but don't used anywhere. > Replace '#define' macro with enum statement in implementation of > SQLITE_IOERR_ error codes > Remove unused function xDelete from sqlite3_vfs interface and its > implementation, unixDelete. Also remove function openDirectory, used > only in unixDelete > > Part of #3315 > --- > src/box/sql/main.c | 42 ----------------------- > src/box/sql/os_unix.c | 88 ------------------------------------------------- > src/box/sql/sqliteInt.h | 43 +++++++++--------------- > 3 files changed, 15 insertions(+), 158 deletions(-) > > diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h > index 53188e7..00c0309 100644 > --- a/src/box/sql/sqliteInt.h > +++ b/src/box/sql/sqliteInt.h > @@ -605,33 +604,21 @@ sqlite3_exec(sqlite3 *, /* An open database */ > void *, /* 1st argument to callback */ > char **errmsg /* Error msg written here */ > ); > -#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) > -#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) > -#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) > -#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) > -#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) > -#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) > -#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) > -#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) > -#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) > -#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) > -#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) > -#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) > -#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) > -#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) > -#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) > -#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) > -#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) > -#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) > -#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) > -#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) > -#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) > -#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) > -#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) > -#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) > -#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) > -#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) > -#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) > + > +enum sql_ioerr_code {> + SQLITE_IOERR_READ = (SQLITE_IOERR | (1<<8)), 1. Please, read the issue title more attentive: "sql: remove SQLITE_ prefix from error codes". But after your patch they still are SQLITE_. > + SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2<<8)), > + SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3<<8)), > + SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (4<<8)), > + SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (5<<8)), > + SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (6<<8)), > + SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (7<<8)), > + SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (8<<8)), > + SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (9<<8)), > + SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (10<<8)), > + SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (11<<8)) > +}; 2. You removed not all unused error codes. I found unused SQLITE_IOERR_CLOSE. Please, find others if they exist. > + > #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) > #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) > #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] [PATCH 2/2] sql: remove unused SQLITE_CONSTRAINT_ error codes 2018-10-02 20:50 [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes AlexeyIvushkin @ 2018-10-02 20:50 ` AlexeyIvushkin 2018-10-03 20:07 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-03 20:04 ` [tarantool-patches] Re: [PATCH 0/2] First part of SQLite error codes refactoring Vladislav Shpilevoy 3 siblings, 1 reply; 9+ messages in thread From: AlexeyIvushkin @ 2018-10-02 20:50 UTC (permalink / raw) To: tarantool-patches; +Cc: Morgan-iv From: Morgan-iv <ivushkinalex@gmail.com> Remove SQLITE_CONSTRAINT_ error codes that only defined, but don't used anywhere. Change its implementation from define macro to enum statement. Part of #3315 --- src/box/sql/main.c | 9 --------- src/box/sql/sqliteInt.h | 13 ++++++------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/box/sql/main.c b/src/box/sql/main.c index 532d324..885cdcc 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -826,9 +826,6 @@ sqlite3ErrName(int rc) case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break; - case SQLITE_CONSTRAINT_UNIQUE: - zName = "SQLITE_CONSTRAINT_UNIQUE"; - break; case SQLITE_CONSTRAINT_TRIGGER: zName = "SQLITE_CONSTRAINT_TRIGGER"; break; @@ -838,15 +835,9 @@ sqlite3ErrName(int rc) case SQLITE_CONSTRAINT_CHECK: zName = "SQLITE_CONSTRAINT_CHECK"; break; - case SQLITE_CONSTRAINT_PRIMARYKEY: - zName = "SQLITE_CONSTRAINT_PRIMARYKEY"; - break; case SQLITE_CONSTRAINT_NOTNULL: zName = "SQLITE_CONSTRAINT_NOTNULL"; break; - case SQLITE_CONSTRAINT_FUNCTION: - zName = "SQLITE_CONSTRAINT_FUNCTION"; - break; case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break; diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 00c0309..5c031e1 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -619,13 +619,12 @@ enum sql_ioerr_code { SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (11<<8)) }; -#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) -#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) -#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) -#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) -#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) -#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) -#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) +enum sql_constrant_code { + SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1<<8)), + SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (2<<8)), + SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (3<<8)), + SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (4<<8)) +}; enum sql_type { SQLITE_INTEGER = 1, -- 2.7.4 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH 2/2] sql: remove unused SQLITE_CONSTRAINT_ error codes 2018-10-02 20:50 ` [tarantool-patches] [PATCH 2/2] sql: remove unused SQLITE_CONSTRAINT_ " AlexeyIvushkin @ 2018-10-03 20:07 ` Vladislav Shpilevoy 0 siblings, 0 replies; 9+ messages in thread From: Vladislav Shpilevoy @ 2018-10-03 20:07 UTC (permalink / raw) To: tarantool-patches, AlexeyIvushkin Thanks for the patch! On 02/10/2018 23:50, AlexeyIvushkin wrote: > From: Morgan-iv <ivushkinalex@gmail.com> > > Remove SQLITE_CONSTRAINT_ error codes that only defined, but don't used > anywhere. Change its implementation from define macro to enum statement. > > Part of #3315 > --- > src/box/sql/main.c | 9 --------- > src/box/sql/sqliteInt.h | 13 ++++++------- > 2 files changed, 6 insertions(+), 16 deletions(-) > > diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h > index 00c0309..5c031e1 100644 > --- a/src/box/sql/sqliteInt.h > +++ b/src/box/sql/sqliteInt.h > @@ -619,13 +619,12 @@ enum sql_ioerr_code { > SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (11<<8)) > }; > > -#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) > -#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) > -#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) > -#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) > -#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) 1. Still visible here: tarantool/test/sql-tap/unique.test.lua: 75 }) 76 77: -- verify_ex_errcode unique-1.3b SQLITE_CONSTRAINT_PRIMARYKEY 78 test:do_execsql_test( 79 "unique-1.4", > -#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) > -#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) 2. The same. > +enum sql_constrant_code { > + SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1<<8)), > + SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (2<<8)), > + SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (3<<8)), > + SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (4<<8)) > +}; > > enum sql_type { > SQLITE_INTEGER = 1, > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] Re: [PATCH 0/2] First part of SQLite error codes refactoring 2018-10-02 20:50 [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring AlexeyIvushkin ` (2 preceding siblings ...) 2018-10-02 20:50 ` [tarantool-patches] [PATCH 2/2] sql: remove unused SQLITE_CONSTRAINT_ " AlexeyIvushkin @ 2018-10-03 20:04 ` Vladislav Shpilevoy 3 siblings, 0 replies; 9+ messages in thread From: Vladislav Shpilevoy @ 2018-10-03 20:04 UTC (permalink / raw) To: tarantool-patches, AlexeyIvushkin Hi! Thanks for the patchset! Unfortunately, SQLITE_IOERR and CONSTRAINT are not the only error codes. Please, look at enum sql_ret_code in sqliteInt.h All of these codes are errors too and should be refactored alongside with this patch - I mean SQLITE_OK, SQLITE_ERROR, SQLITE_PERM etc. Strictly speaking, I think SQLITE_OK should be removed and be replaced with inlined 0 as it is done in other parts of Tarantool. On 02/10/2018 23:50, AlexeyIvushkin wrote: > From: Morgan-iv <ivushkinalex@gmail.com> > > These 2 patches are the beginning of SQLite error codes refactoring. > Both of them change implementation of affected error codes from > define macro to enum statement, and remove codes that aren't returned > anywhere, but first also remove related function that aren't called > anywhere too. First patch affects SQLITE_IOERR_ codes, second - > SQLITE_CONSTRAINT_ codes. > Final rename of all error codes affected in these 2 patches and > the next several patches in this branch will be applied after removing > all unused error codes and removing all found unused functions related > to affected SQLite error codes > > Issue: https://github.com/tarantool/tarantool/issues/3315 > Branch: https://github.com/tarantool/tarantool/tree/Morgan-iv/gh-3315 > > Morgan-iv (2): > sql: refactor SQLITE_IOERR_ error codes > sql: remove unused SQLITE_CONSTRAINT_ error codes > > src/box/sql/main.c | 51 ---------------------------- > src/box/sql/os_unix.c | 88 ------------------------------------------------- > src/box/sql/sqliteInt.h | 56 ++++++++++++------------------- > 3 files changed, 21 insertions(+), 174 deletions(-) > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tarantool-patches] [PATCH] box: add tuple:size function @ 2018-09-27 17:55 AlexeyIvushkin 2018-10-05 10:23 ` Vladimir Davydov 0 siblings, 1 reply; 9+ messages in thread From: AlexeyIvushkin @ 2018-09-27 17:55 UTC (permalink / raw) To: tarantool-patches; +Cc: Morgan-iv From: Morgan-iv <ivushkinalex@gmail.com> When operating with tuples, we only have tuple:bsize function to get size of tuple. tuple:bsize returns only size of MessagePack part of struct tuple, without tuple_meta. New function tuple:size returns size of all tuple, with MessagePack and tuple_meta Closes #2256 --- https://github.com/tarantool/tarantool/issues/2256 https://github.com/tarantool/tarantool/tree/Morgan-iv/gh-2256 src/box/lua/tuple.c | 10 ++++++++++ src/box/lua/tuple.lua | 1 + test/box/tuple.result | 12 ++++++++++++ test/box/tuple.test.lua | 6 ++++++ 4 files changed, 29 insertions(+) diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c index 65660ce..1ae49d6 100644 --- a/src/box/lua/tuple.c +++ b/src/box/lua/tuple.c @@ -489,6 +489,15 @@ lbox_tuple_to_string(struct lua_State *L) return 1; } +static int +lbox_tuple_size(struct lua_State *L) +{ + struct tuple *tuple = lua_checktuple(L, 1); + size_t size = tuple_size(tuple); + lua_pushinteger(L, size); + return 1; +} + void luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple) { @@ -506,6 +515,7 @@ static const struct luaL_Reg lbox_tuple_meta[] = { {"__gc", lbox_tuple_gc}, {"tostring", lbox_tuple_to_string}, {"slice", lbox_tuple_slice}, + {"size", lbox_tuple_size}, {"transform", lbox_tuple_transform}, {"tuple_to_map", lbox_tuple_to_map}, {"tuple_field_by_path", lbox_tuple_field_by_path}, diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index 63ea73e..801ee3c 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -286,6 +286,7 @@ local methods = { ["update"] = tuple_update; ["upsert"] = tuple_upsert; ["bsize"] = tuple_bsize; + ["size"] = internal.tuple.size; ["tomap"] = internal.tuple.tuple_to_map; } diff --git a/test/box/tuple.result b/test/box/tuple.result index e035cb9..418f5f8 100644 --- a/test/box/tuple.result +++ b/test/box/tuple.result @@ -186,6 +186,18 @@ t:bsize() --- - 5 ... +-- tuple:size() +t = box.tuple.new('abc') +--- +... +t +--- +- ['abc'] +... +t:size() +--- +- 15 +... -- -- Test cases for #106 box.tuple.new fails on multiple items -- diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua index 9df978d..7f4e2b3 100644 --- a/test/box/tuple.test.lua +++ b/test/box/tuple.test.lua @@ -49,6 +49,12 @@ t = box.tuple.new('abc') t t:bsize() +-- tuple:size() + +t = box.tuple.new('abc') +t +t:size() + -- -- Test cases for #106 box.tuple.new fails on multiple items -- -- 2.7.4 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [tarantool-patches] [PATCH] box: add tuple:size function 2018-09-27 17:55 [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin @ 2018-10-05 10:23 ` Vladimir Davydov 0 siblings, 0 replies; 9+ messages in thread From: Vladimir Davydov @ 2018-10-05 10:23 UTC (permalink / raw) To: AlexeyIvushkin; +Cc: tarantool-patches On Thu, Sep 27, 2018 at 08:55:23PM +0300, AlexeyIvushkin wrote: > diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua > index 63ea73e..801ee3c 100644 > --- a/src/box/lua/tuple.lua > +++ b/src/box/lua/tuple.lua > @@ -286,6 +286,7 @@ local methods = { > ["update"] = tuple_update; > ["upsert"] = tuple_upsert; > ["bsize"] = tuple_bsize; > + ["size"] = internal.tuple.size; > ["tomap"] = internal.tuple.tuple_to_map; Why did you decide to introduce a new function rather than fixing tuple.bsize, as it was explicitly requested in the ticket? ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-10-05 10:23 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-10-02 20:50 [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin 2018-10-02 20:50 ` [tarantool-patches] [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes AlexeyIvushkin 2018-10-03 20:06 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-02 20:50 ` [tarantool-patches] [PATCH 2/2] sql: remove unused SQLITE_CONSTRAINT_ " AlexeyIvushkin 2018-10-03 20:07 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-03 20:04 ` [tarantool-patches] Re: [PATCH 0/2] First part of SQLite error codes refactoring Vladislav Shpilevoy -- strict thread matches above, loose matches on Subject: below -- 2018-09-27 17:55 [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin 2018-10-05 10:23 ` Vladimir Davydov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox