V: sqlite c error (windows)

Created on 1 Feb 2020  Â·  12Comments  Â·  Source: vlang/v

V version: 0.1.25 2fbfbf4
OS: Windows 10

What did you do?

import sqlite

fn main() {
    db := sqlite.connect(':memory:')
    db.exec("create table users (id integer primary key, name text default '');")

    db.exec("insert into users (name) values ('Sam')")
    db.exec("insert into users (name) values ('Peter')")
    db.exec("insert into users (name) values ('Kate')")

    nr_users := db.q_int('select count(*) from users')
    println('nr users = $nr_users')

    name := db.q_string('select name from users where id = 1')
    assert name == 'Sam'

    users := db.exec('select * from users')
    for row in users {
        println(row.vals)
    }   
}

What did you expect to see?
running sqlite.v is success

What did you see instead?

PS C:\> v run sqlite.v
3.h"
          ^~~~~~~~~~~
compilation terminated.V error: C error. This should never happen. 
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
Bug Windows Has Workaround vlib

Most helpful comment

@didik78 @shawnye You'll need to download the zip file in the SQLite download page (the first link), create a new folder named sqlite inside the thirdparty folder where the V compiler lives, extract the contents of the zip into that folder, and edit the following on the sqlite.v:

module sqlite

#flag -lsqlite3
#flag freebsd -I/usr/local/include
#flag freebsd -Wl -L/usr/local/lib -lsqlite3
+ #flag windows -I @VROOT/thirdparty/sqlite
+ #flag windows -L @VROOT/thirdparty/sqlite

I can't test it right now since I'm encountering unicode redefinition errors but it should work as expected.

All 12 comments

Hi @didik78, can you run it with v -show_c_cmd run sqlite.v? and have you installed the sqlite3 library?

@dhonx I did as readme.md required: # to use modulesqlite, installsqlite-develfirst.

D:\v\examples>v install sqlite-devel
Skipping module "sqlite-devel", since it is missing name or url information.

It seems no sqlite-devel module for windows.

@nedpals Can you troubleshooting this ??

@didik78 @shawnye You'll need to download the zip file in the SQLite download page (the first link), create a new folder named sqlite inside the thirdparty folder where the V compiler lives, extract the contents of the zip into that folder, and edit the following on the sqlite.v:

module sqlite

#flag -lsqlite3
#flag freebsd -I/usr/local/include
#flag freebsd -Wl -L/usr/local/lib -lsqlite3
+ #flag windows -I @VROOT/thirdparty/sqlite
+ #flag windows -L @VROOT/thirdparty/sqlite

I can't test it right now since I'm encountering unicode redefinition errors but it should work as expected.

windows2008 server 64bit
V 0.1.25 7165327

@nedpals I downloaded the latest sqlite3 source code ,and put down into thirdparty ,changed the sqlite.v file as you suggested, but it failed me :(

Administrator@DD1815W1 MINGW64 /d/yexy6/v/examples (master)
$ ll ../thirdparty/sqlite
total 9068
-rw-r--r-- 1 Administrator 197121  591565 一月 28 03:25 shell.c
-rw-r--r-- 1 Administrator 197121 8074669 一月 28 03:25 sqlite3.c
-rw-r--r-- 1 Administrator 197121  576161 一月 28 03:25 sqlite3.h
-rw-r--r-- 1 Administrator 197121   34802 一月 28 03:25 sqlite3ext.h

Administrator@DD1815W1 MINGW64 /d/yexy6/v/examples (master)
$ head ../vlib/sqlite/sqlite.v
module sqlite

#flag -lsqlite3
#flag freebsd -I/usr/local/include
#flag freebsd -Wl -L/usr/local/lib -lsqlite3

#flag windows -I @VROOT/thirdparty/sqlite
#flag windows -L @VROOT/thirdparty/sqlite

#include "sqlite3.h"

Administrator@DD1815W1 MINGW64 /d/yexy6/v/examples (master)
$ v -cg sqlite.v
C compiler=gcc
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:145: warning: "UNICODE" redefined
 #define UNICODE

: note: this is the location of the previous definition
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c: In function 'print':
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:1160:58: warning: passing argument 4 of 'Wri                                                                                                                                                                             teConsoleW' from incompatible pointer type [-Wincompatible-pointer-types]
  WriteConsole ( output_handle ,  wide_str ,  wide_len ,  & bytes_written ,  0 ) ;
                                                          ^~~~~~~~~~~~~~~
In file included from D:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-                                                                                                                                                                             w64-mingw32/include/windows.h:74,
                 from C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:146:
D:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wi                                                                                                                                                                             ncon.h:260:122: note: expected 'LPDWORD' {aka 'long unsigned int *'} but argument is of type 'int                                                                                                                                                                              *'
   WINBASEAPI WINBOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput,CONST VOID *lpBuffer,DWORD nNumbe                                                                                                                                                                             rOfCharsToWrite,LPDWORD lpNumberOfCharsWritten,LPVOID lpReserved);
                                                                                                                                                                                                                                                                                               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:1163:58: warning: passing argument 4 of 'Wri                                                                                                                                                                             teFile' from incompatible pointer type [-Wincompatible-pointer-types]
  WriteFile ( output_handle , (char*) s .str ,  s .len ,  & bytes_written ,  0 ) ;
                                                          ^~~~~~~~~~~~~~~
In file included from D:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-                                                                                                                                                                             w64-mingw32/include/winbase.h:18,
                 from D:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-                                                                                                                                                                             w64-mingw32/include/windows.h:70,
                 from C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:146:
D:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/fi                                                                                                                                                                             leapi.h:175:109: note: expected 'LPDWORD' {aka 'long unsigned int *'} but argument is of type 'int                                                                                                                                                                              *'
   WINBASEAPI WINBOOL WINAPI WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrit                                                                                                                                                                             e, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
                                                                                                                                                                                                                                                                                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c: In function 'u64_hex':
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:1543:15: warning: comparison of unsigned exp                                                                                                                                                                             ression >= 0 is always true [-Wtype-limits]
 int len= (( n >= ((u64)( 0 ) ) ) ? ( u64_str ( n ) .len + 3 ) : ( 19 )) ;
               ^~
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c: In function 'sqlite__DB_q_string':
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:4315:25: warning: passing argument 1 of 'tos                                                                                                                                                                             _clone' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 string res= tos_clone ( sqlite3_column_text ( stmt ,  0 ) ) ;
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:2098:26: note: expected 'byte *' {aka 'unsig                                                                                                                                                                             ned char *'} but argument is of type 'const unsigned char *'
  string tos_clone (byte* s) {
                    ~~~~~~^
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c: In function 'sqlite__DB_exec':
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:4340:25: warning: passing argument 1 of 'tos                                                                                                                                                                             _clone' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 string val= tos_clone ( sqlite3_column_text ( stmt ,  i ) ) ;
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\ADMINI~1\AppData\Local\Temp\2\v\sqlite.tmp.c:2098:26: note: expected 'byte *' {aka 'unsig                                                                                                                                                                             ned char *'} but argument is of type 'const unsigned char *'
  string tos_clone (byte* s) {
                    ~~~~~~^
D:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-min                                                                                                                                                                             gw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsqlite3
collect2.exe: error: ld returned 1 exit status
V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

Full error is truncated :)

@shawnye Like I said, It definitely points out to the redefinition of UNICODE thats why I was not able to test sqlite3 on Windows properly (using MingW GCC)

No, the most important error is last error which is truncated, not warnings

I have the same issue & followed the same suggestion (put amalgamation source into thirdparty sqlite folder). Here's the result https://pastebin.com/RFJPp9NC

V searches for libsqlite3.(lib|a) to link with, make sure amalgamation source build produces that file, or remove "-l sqlite3" flag from module flags

@vitalyster thanks for the tip. I could eventually get it to work. Not sure if it's the ideal solution. Basically

  • do the sqlite.v update as suggested above by @nedpals
  • copy the .h file (from amalgamated SQLite source) into thirdpartysqlite
  • download the Precompiled Binaries for Windows zip containing (def & dll files) assuming 64-bit env
  • create a lib file from the def (using lib /DEF:sqlite3.def /OUT:sqlite3.lib) assuming using MSVC
  • copy the resultant sqlite.lib file to thirdpartysqlite
  • compile the examplesqlite.v using v
  • copy the sqlite.dll from the Precompiled Binaries zip to the example folder
  • run examplesqlite.exe and it should work

any other/better suggestions welcome.

@didik78 @shawnye You'll need to download the zip file in the SQLite download page (the first link), create a new folder named sqlite inside the thirdparty folder where the V compiler lives, extract the contents of the zip into that folder, and edit the following on the sqlite.v:

module sqlite

#flag -lsqlite3
#flag freebsd -I/usr/local/include
#flag freebsd -Wl -L/usr/local/lib -lsqlite3
+ #flag windows -I @VROOT/thirdparty/sqlite
+ #flag windows -L @VROOT/thirdparty/sqlite

I can't test it right now since I'm encountering unicode redefinition errors but it should work as expected.

Thanks, it worked,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ArcDrake picture ArcDrake  Â·  3Comments

shouji-kazuo picture shouji-kazuo  Â·  3Comments

oleg-kachan picture oleg-kachan  Â·  3Comments

medvednikov picture medvednikov  Â·  3Comments

cjmxp picture cjmxp  Â·  3Comments