go-sqlite3
go-sqlite3 copied to clipboard
It is not possible to change driver name from sqlite3 to some another
It is not possible to change driver name from sqlite3 to some another. It's critical if another lib also use sqlite3 but another version with the same driver name
This is ultimately a flaw in the original design of Go's database/sql package.
What we can do is move the call to sql.Register
to a separate file that can be excluded via some build tag. Will that suffice?
This is ultimately a flaw in the original design of Go's database/sql package. What we can do is move the call to
sql.Register
to a separate file that can be excluded via some build tag. Will that suffice?
I tired that. Unfortunately it is not help to me, problem is not in driver name =( May be do you have any ideas about that? tdlib/td#1815
It looks like that td library you are trying to use compiles in its own version of SQLite, which has the sqlcipher extension built in. My guess is this conflicts with the version of SQLite that gets compiled in by this library, resulting in the issue you are seeing.
The only way I can think of to fix this issue is to tell this library not to compile in its own copy of SQLite, or to use the system-provided version, but rather use one that will be statically compiled in elsewhere. That is, you basically want the same thing as what the libsqlite3 build tag does, except for these lines: https://github.com/mattn/go-sqlite3/blob/98c52198ca55ae44ef9bb3107ff71af4c9d6e9eb/sqlite3_libsqlite3.go#L12-L17
You will also need to set CFLAGS appropriately at the command line so that it uses the sqlite3.h header file from td.
It looks like that td library you are trying to use compiles in its own version of SQLite, which has the sqlcipher extension built in. My guess is this conflicts with the version of SQLite that gets compiled in by this library, resulting in the issue you are seeing.
The only way I can think of to fix this issue is to tell this library not to compile in its own copy of SQLite, or to use the system-provided version, but rather use one that will be statically compiled in elsewhere. That is, you basically want the same thing as what the libsqlite3 build tag does, except for these lines:
https://github.com/mattn/go-sqlite3/blob/98c52198ca55ae44ef9bb3107ff71af4c9d6e9eb/sqlite3_libsqlite3.go#L12-L17
You will also need to set CFLAGS appropriately at the command line so that it uses the sqlite3.h header file from td.
Thank you so much for diving into my problem!!! But I'm afraid my immature brain of a beginner in the golang world is not able to understand exactly what I need to do and where =(
Did I understand correctly what I need in my fork of go-sqlite3 remove next lines
#cgo linux LDFLAGS: -lsqlite3 #cgo darwin LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3 #cgo darwin CFLAGS: -I/usr/local/opt/sqlite/include #cgo openbsd LDFLAGS: -lsqlite3 #cgo solaris LDFLAGS: -lsqlite3 #cgo windows LDFLAGS: -lsqlite3
And then when I compile my golang application specify CFLAGS:
CFLAGS=[path to tdlib sqlite3.h] go build
I apologize in advance that I'm so stupid, I've been studying golang for only a week
Something like that. I haven't dealt with this level of cgo that often, so it may take a few tries to get right. Please note you want CFLAGS to be -I/path/to/tdlib/sqlite3/dir
. That is, the path to the folder, not the path of the file itself. You will also want to compile with the libsqlite3 build tag.
I apologize in advance that I'm so stupid, I've been studying golang for only a week
No need to apologize. You are not stupid, you just happened to hit upon what seems to be a fairly uncommon use case. :)
Something like that. I haven't dealt with this level of cgo that often, so it may take a few tries to get right. Please note you want CFLAGS to be
-I/path/to/tdlib/sqlite3/dir
. That is, the path to the folder, not the path of the file itself. You will also want to compile with the libsqlite3 build tag.I apologize in advance that I'm so stupid, I've been studying golang for only a week
No need to apologize. You are not stupid, you just happened to hit upon what seems to be a fairly uncommon use case. :)
thanks)) my tires (files sqlite3.h and other *.h are in /td/sqlite/sqlite) I run:
CGO_CFLAGS="-I/td/sqlite/sqlite" go build --tags "libsqlite3"
And I got alot of errors:
github.com/borzovplus/go-sqlite3 Undefined symbols for architecture x86_64: "_sqlite3_aggregate_context", referenced from: __cgo_8cada9c70ee3_Cfunc_sqlite3_aggregate_context in _x005.o (maybe you meant: __cgo_8cada9c70ee3_Cfunc_sqlite3_aggregate_context) "_sqlite3_backup_finish", referenced from: __cgo_8cada9c70ee3_Cfunc_sqlite3_backup_finish in _x002.o (maybe you meant: __cgo_8cada9c70ee3_Cfunc_sqlite3_backup_finish) "_sqlite3_backup_init", referenced from: __cgo_8cada9c70ee3_Cfunc_sqlite3_backup_init in _x002.o (maybe you meant: __cgo_8cada9c70ee3_Cfunc_sqlite3_backup_init) ....
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Hmm, that is unfortunate. One other thing you could try is compiling td as a library first, and then linking with it in both places.
Hmm, that is unfortunate. One other thing you could try is compiling td as a library first, and then linking with it in both places.
tdlib is already compiled in /usr/local/lib, what should I do? I have libtdjson.dylib
If we provide variable driverName, you may be possible to replace the name. How about this?
go build -ldflags="-X 'github.com/mattn/go-sqlite3.driverName=my-sqlite3'"
Ah, sorry. I misunderstood the purpose of this issue.