diff --git a/doc/docs.md b/doc/docs.md index 8cf8808766..1a2c208e58 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2720,7 +2720,7 @@ fn C.sqlite3_close(&C.sqlite3) int fn C.sqlite3_column_int(stmt &C.sqlite3_stmt, n int) int -// ... you can also just define the type of parameter & leave out the C. prefix +// ... you can also just define the type of parameter and leave out the C. prefix fn C.sqlite3_prepare_v2(&sqlite3, charptr, int, &&sqlite3_stmt, &charptr) int fn C.sqlite3_step(&sqlite3_stmt) @@ -2732,8 +2732,10 @@ fn C.sqlite3_exec(db &sqlite3, sql charptr, FnSqlite3Callback voidptr, cb_arg vo fn C.sqlite3_free(voidptr) fn my_callback(arg voidptr, howmany int, cvalues &charptr, cnames &charptr) int { - for i in 0 .. howmany { - print('| ${cstring_to_vstring(cnames[i])}: ${cstring_to_vstring(cvalues[i]):20} ') + unsafe { + for i in 0 .. howmany { + print('| ${cstring_to_vstring(cnames[i])}: ${cstring_to_vstring(cvalues[i]):20} ') + } } println('|') return 0 @@ -2744,9 +2746,10 @@ fn main() { // passing a string literal to a C function call results in a C string, not a V string C.sqlite3_open('users.db', &db) // C.sqlite3_open(db_path.str, &db) - // you can also use `.str byteptr` field to convert a V string to a C char pointer query := 'select count(*) from users' stmt := &C.sqlite3_stmt(0) + // NB: you can also use the `.str` field of a V string, + // to get its C style zero terminated representation C.sqlite3_prepare_v2(db, query.str, -1, &stmt, 0) C.sqlite3_step(stmt) nr_users := C.sqlite3_column_int(stmt, 0)