5 Commits
0.0.1 ... 0.0.3

Author SHA1 Message Date
262aacc0a9 ownership bugfix and vbump 2020-01-27 09:05:11 +01:00
2386599913 examples: remove fsanitize 2020-01-26 22:23:16 +01:00
21e74f82e3 docs: update for 0.0.2 2020-01-26 22:15:22 +01:00
9743ac15d9 memory bugfix, vbump 2020-01-26 22:14:25 +01:00
e239ac2b7f docs: better example 2020-01-26 16:06:06 +01:00
4 changed files with 17 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ everything, but it tries to be useful.
## Installation
```clojure
(load "https://veitheller.de/git/carpentry/sqlite3@0.0.1")
(load "https://veitheller.de/git/carpentry/sqlite3@0.0.3")
```
## Usage

View File

@@ -32,7 +32,7 @@
<p>is a simple high-level wrapper around SQLite3. It doesnt intend
to wrap everything, but it tries to be useful.</p>
<h2>Installation</h2>
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/sqlite3@0.0.1&quot;)
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/sqlite3@0.0.3&quot;)
</code></pre>
<h2>Usage</h2>
<p>The module <code>SQLite3</code> provides facilities for opening, closing, and querying
@@ -43,8 +43,9 @@ databases.</p>
; ignore that
(let-do [db (Result.unsafe-from-success (SQLite3.open &quot;db&quot;))]
; we can prepare statements
(println* &amp;(SQLite3.query &amp;db &quot;INSERT INTO mytable VALUES (?1, ?2);&quot;
&amp;[(to-sqlite3 @&quot;hello&quot;) (to-sqlite3 100)]))
(ignore
(SQLite3.query &amp;db &quot;INSERT INTO mytable VALUES (?1, ?2);&quot;
&amp;[(to-sqlite3 @&quot;hello&quot;) (to-sqlite3 100)]))
; and query things
(println* &amp;(SQLite3.query &amp;db &quot;SELECT * from mytable;&quot; &amp;[]))
(SQLite3.close db)

View File

@@ -7,7 +7,7 @@ to wrap everything, but it tries to be useful.
## Installation
```clojure
(load \"https://veitheller.de/git/carpentry/sqlite3@0.0.1\")
(load \"https://veitheller.de/git/carpentry/sqlite3@0.0.3\")
```
## Usage
@@ -22,8 +22,9 @@ databases.
; ignore that
(let-do [db (Result.unsafe-from-success (SQLite3.open \"db\"))]
; we can prepare statements
(println* &(SQLite3.query &db \"INSERT INTO mytable VALUES (?1, ?2);\"
&[(to-sqlite3 @\"hello\") (to-sqlite3 100)]))
(ignore
(SQLite3.query &db \"INSERT INTO mytable VALUES (?1, ?2);\"
&[(to-sqlite3 @\"hello\") (to-sqlite3 100)]))
; and query things
(println* &(SQLite3.query &db \"SELECT * from mytable;\" &[]))
(SQLite3.close db)
@@ -144,7 +145,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
(register open- (Fn [&SQLite (Ptr Char)] Int) "SQLite3_open_c")
(private exec-)
(hidden exec-)
(register exec- (Fn [&SQLite (Ptr Char) (Array SQLiteColumn)] SQLiteRes) "SQLite3_exec_c")
(register exec- (Fn [&SQLite (Ptr Char) &(Array SQLiteColumn)] SQLiteRes) "SQLite3_exec_c")
(private error-)
(hidden error-)
(register error- (Fn [SQLite] (Ptr Char)) "SQLite3_error")
@@ -164,7 +165,7 @@ If it fails, we return an error message using `Result.Error`.")
If it fails, we return an error message using `Result.Error`.")
(defn query [db s p]
(let [r (exec- db (cstr s) (Array.copy-map &(fn [x] (Type.to-sqlite3-internal @x)) p))]
(let [r (exec- db (cstr s) &(Array.copy-map &(fn [x] (Type.to-sqlite3-internal @x)) p))]
(if (SQLiteRes.ok? &r)
(Result.Success (SQLiteRes.to-array r))
(Result.Error (from-cstr (SQLiteRes.error r))))))

View File

@@ -176,14 +176,14 @@ const char* SQLite3_exec_internal(sqlite3_stmt* s, SQLiteRows* rows) {
break;
case SQLITE_TEXT: {
len = sqlite3_column_bytes(s, i);
c->s = CARP_MALLOC(len);
c->s = CARP_MALLOC(len+1);
memcpy(c->s, sqlite3_column_text(s, i), len);
c->s[len] = '\0';
break;
}
case SQLITE_BLOB: {
len = sqlite3_column_bytes(s, i);
c->s = CARP_MALLOC(len);
c->s = CARP_MALLOC(len+1);
memcpy(c->s, sqlite3_column_blob(s, i), len);
c->s[len] = '\0';
break;
@@ -218,12 +218,12 @@ static const char* SQLite3_exec_ignore(sqlite3_stmt* s) {
return ret;
}
const char* SQLite3_bind(sqlite3_stmt* s, Array p) {
const char* SQLite3_bind(sqlite3_stmt* s, Array* p) {
int res;
const char* err = NULL;
for (int i = 0; i < p.len; i++) {
SQLiteColumn val = ((SQLiteColumn*)p.data)[i];
for (int i = 0; i < p->len; i++) {
SQLiteColumn val = ((SQLiteColumn*)p->data)[i];
switch (val.tag) {
case SQLITE_NULL:
@@ -252,7 +252,7 @@ const char* SQLite3_bind(sqlite3_stmt* s, Array p) {
return err;
}
SQLiteRes SQLite3_exec_c(SQLite* db, const char* stmt, Array p) {
SQLiteRes SQLite3_exec_c(SQLite* db, const char* stmt, Array* p) {
sqlite3_stmt* s = NULL;
sqlite3_stmt* n = NULL;
const char* err;