From 89838f2e2192d3fdec2d038cc032cdc3f68e63e8 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 6 Apr 2021 22:15:14 +0300 Subject: [PATCH] tutorials: blog: use db.create_table() --- .../code/blog/blog.v | 7 +++++-- vlib/sqlite/sqlite.v | 12 ++++++------ vlib/v/tests/valgrind/1.strings_and_arrays.v | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.v b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.v index 9f83d35768..15e17ad586 100644 --- a/tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.v +++ b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.v @@ -33,8 +33,11 @@ pub fn (app &App) index() vweb.Result { pub fn (mut app App) init_once() { app.db = sqlite.connect('blog.db') or { panic(err) } - app.db.exec('create table if not exists article (' + 'id integer primary key, ' + - "title text default ''," + "text text default ''" + ');') + app.db.create_table('article', [ + 'id integer primary key', + "title text default ''", + "text text default ''", + ]) } pub fn (mut app App) init() { diff --git a/vlib/sqlite/sqlite.v b/vlib/sqlite/sqlite.v index ccc9638b54..f30b3c994a 100644 --- a/vlib/sqlite/sqlite.v +++ b/vlib/sqlite/sqlite.v @@ -36,21 +36,21 @@ pub mut: } // -fn C.sqlite3_open(charptr, &&C.sqlite3) int +fn C.sqlite3_open(&char, &&C.sqlite3) int fn C.sqlite3_close(&C.sqlite3) int // -fn C.sqlite3_prepare_v2(&C.sqlite3, charptr, int, &&C.sqlite3_stmt, &charptr) int +fn C.sqlite3_prepare_v2(&C.sqlite3, &char, int, &&C.sqlite3_stmt, &&char) int fn C.sqlite3_step(&C.sqlite3_stmt) int fn C.sqlite3_finalize(&C.sqlite3_stmt) int // -fn C.sqlite3_column_name(&C.sqlite3_stmt, int) charptr +fn C.sqlite3_column_name(&C.sqlite3_stmt, int) &char -fn C.sqlite3_column_text(&C.sqlite3_stmt, int) byteptr +fn C.sqlite3_column_text(&C.sqlite3_stmt, int) &byte fn C.sqlite3_column_int(&C.sqlite3_stmt, int) int @@ -61,7 +61,7 @@ fn C.sqlite3_column_double(&C.sqlite3_stmt, int) f64 fn C.sqlite3_column_count(&C.sqlite3_stmt) int // -fn C.sqlite3_errstr(int) charptr +fn C.sqlite3_errstr(int) &char fn C.sqlite3_free(voidptr) @@ -180,5 +180,5 @@ pub fn (db DB) insert(x T) { } pub fn (db DB) create_table(table_name string, columns []string) { - db.exec('create table $table_name (' + columns.join(',\n') + ')') + db.exec('create table if not exists $table_name (' + columns.join(',\n') + ')') } diff --git a/vlib/v/tests/valgrind/1.strings_and_arrays.v b/vlib/v/tests/valgrind/1.strings_and_arrays.v index 16a5461745..47c5a910e1 100644 --- a/vlib/v/tests/valgrind/1.strings_and_arrays.v +++ b/vlib/v/tests/valgrind/1.strings_and_arrays.v @@ -380,7 +380,7 @@ fn main() { str_tmp_expr_advanced_var_decl() str_inter() match_expr() - // optional_str() + optional_str() // optional_return() str_replace() str_replace2()