Skip to content

Low level api#1

Closed
Conni2461 wants to merge 4 commits intomasterfrom
api
Closed

Low level api#1
Conni2461 wants to merge 4 commits intomasterfrom
api

Conversation

@Conni2461
Copy link
Copy Markdown
Collaborator

@Conni2461 Conni2461 commented Dec 29, 2020

Right now testing with :luafile %.
How should we name that file?

Edit: I am going to copy everything and then we can get rid of everything we don't really need like sqlite3_int64 sqlite3_memory_used(void) or do we need *sqlite3_malloc(int). We will see :) I am at 25% right now

int sqlite3_libversion_number(void);
]]

print(ffi.string(clib.sqlite3_libversion()))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do ffi.string wrapped. We also need to check if NULL i think

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is nil then it should skip sending nil i think

Copy link
Copy Markdown
Collaborator Author

@Conni2461 Conni2461 Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just a comment to myself because i noticed that weird output of clib.sqlite3_libversion() without it

Comment on lines +503 to +1155
int sqlite3_prepare(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare_v2(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare_v3(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare16(
sqlite3 *db, /* Database handle */
const void *zSql, /* SQL statement, UTF-16 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const void **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare16_v2(
sqlite3 *db, /* Database handle */
const void *zSql, /* SQL statement, UTF-16 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const void **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare16_v3(
sqlite3 *db, /* Database handle */
const void *zSql, /* SQL statement, UTF-16 encoded */
int nByte, /* Maximum length of zSql in bytes. */
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const void **pzTail /* OUT: Pointer to unused portion of zSql */
);
]]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need that many prepare statements. Just prepare and prepare16. So which version do we keep 😆

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Conni2461 If there is no difference between then any would be fine. Also what does the additional 16 means?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTF-8 vs UTF-16 encoded statement can be found in the comment 😆

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣🤣 oh then I believe as user we need both, no?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need definitely both 8 and 16 but i have no idea whats the difference between v1, v2, v3

- sqlite3rtree
- sqlite3session
- fts5
@kkharji
Copy link
Copy Markdown
Owner

kkharji commented Dec 29, 2020

Right now testing with :luafile %.

How should we name that file?

I guess defs.lua, inside sql dir if it's only purpose is to have the low level ffi stuff

> Edit: I am going to copy everything and then we can get rid of everything we don't really need like sqlite3_int64 sqlite3_memory_used(void) or do we need *sqlite3_malloc(int). We will see :) I am at 25% right now

I saw we are using sqlite3, can we abbreviate it or would result in problems😝😝

@kkharji kkharji closed this Dec 29, 2020
@Conni2461 Conni2461 deleted the api branch December 29, 2020 20:37
kkharji added a commit that referenced this pull request Aug 19, 2021
kkharji added a commit that referenced this pull request Aug 19, 2021
kkharji added a commit that referenced this pull request Sep 21, 2021
Before lazy was default and there was no way of changing that. I've
decided to make it optional because it seems that:

1. People expects sqlite {} or sqlite:extend {} to create all the
   defined table in advance.
2. Performance impact of initializing db object is only 1.0 slower in
   microseconds, so it seems to not be as important as I thought it
   would:

   ```lua
   -- test/lazy.lua
    Benchmark #1: 'Logical Component'
      Time(mean ± σ):     23.7 μs ±  18.7 μs
      Range(min … max):   17.4 μs … 102.3 μs  20 runs
    Benchmark #2: 'Full Initialization'
      Time(mean ± σ):     28.7 μs ±  12.9 μs
      Range(min … max):   24.1 μs …  83.1 μs  20 runs
    Summary
      'Logical Component' ran
      1.2 ± 1.1 times faster than 'Full Initialization'
   ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants