From: Salim Q
Subject: cl-sql refuses to work
Date: 
Message-ID: <877j8dwr01.fsf@localhost.localdomain>
Hi,
I know this is supposed to only have lisp language related questiosns,
but I havent gotten a response from the maintainer.

I had cl-sql working with cl-sql-mysql, but I had to reinstall my system
due to a system crash when moving. Now it refuses to work with
libmysqlclient14(or 15)-dev. 

This is the error I get.

Undefined foreign symbol: "mysql_connect"
   [Condition of type KERNEL:SIMPLE-PROGRAM-ERROR]


I had worked through the sample guide here on my previous install.
http://bc.tech.coop/blog/040608.html

Any help would be appreciated.
cheers,
salim

NOTE :

I have the following packages installed

ii  cl-sql         3.5.3-1        SQL Interface for Common Lisp
un  cl-sql-backend <none>         (no description available)
ii  cl-sql-mysql   3.5.3-1        CLSQL database backend, MySQL
ii  cl-sql-uffi    3.5.3-1        Common UFFI functions for CLSQL

mysql 4.1.15, libmysqlclient14 and libmysqlclient14-dev

From: Wade Humeniuk
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <yQsEf.161958$6K2.20232@edtnps90>
CLSQL probably cannot find the library, see

http://clsql.b9.com/manual/mysql.html#id2599601

and check *mysql-so-load-path* to see if it correct.  Your mysql library
may be in /usr/local/lib/ instead.

Wade

Salim Q wrote:
> Hi,
> I know this is supposed to only have lisp language related questiosns,
> but I havent gotten a response from the maintainer.
> 
> I had cl-sql working with cl-sql-mysql, but I had to reinstall my system
> due to a system crash when moving. Now it refuses to work with
> libmysqlclient14(or 15)-dev. 
> 
> This is the error I get.
> 
> Undefined foreign symbol: "mysql_connect"
>    [Condition of type KERNEL:SIMPLE-PROGRAM-ERROR]
> 
> 
> I had worked through the sample guide here on my previous install.
> http://bc.tech.coop/blog/040608.html
> 
> Any help would be appreciated.
> cheers,
> salim
> 
> NOTE :
> 
> I have the following packages installed
> 
> ii  cl-sql         3.5.3-1        SQL Interface for Common Lisp
> un  cl-sql-backend <none>         (no description available)
> ii  cl-sql-mysql   3.5.3-1        CLSQL database backend, MySQL
> ii  cl-sql-uffi    3.5.3-1        Common UFFI functions for CLSQL
> 
> mysql 4.1.15, libmysqlclient14 and libmysqlclient14-dev
> 
> 
> 
From: Salim Q
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <87d5i5tmw8.fsf@diaphanous.homeunix.net>
Thanks for the reply. I checked libmysqlclient.so and it is in /usr/lib
as a symlink like this : libmysqlclient.so -> libmysqlclient.so.14

I am wondering if cl-sql works with an obsoleted version (such as
libmysqlclient.so.10 which is the LGLPL version) or if i
need libmysqlclient.so.15. 

I am hesitant to try v10 of the libmysqlclient because I need higher
versions for PHP and some GUI tools. 

cheers,
salim
From: Wade Humeniuk
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <oFwEf.178445$km.20740@edtnps89>
Salim Q wrote:
> Thanks for the reply. I checked libmysqlclient.so and it is in /usr/lib
> as a symlink like this : libmysqlclient.so -> libmysqlclient.so.14
> 
> I am wondering if cl-sql works with an obsoleted version (such as
> libmysqlclient.so.10 which is the LGLPL version) or if i
> need libmysqlclient.so.15. 
> 
> I am hesitant to try v10 of the libmysqlclient because I need higher
> versions for PHP and some GUI tools. 
> 
> cheers,
> salim

Try to see what the symbols are in libmysqlclient.so are...

You can use nm (do a man nm to see the args)

I am pretty confused with your problem.  Can you post a
backtrace of the error?  If you look at the cl-sql mysql
code it seems to use mysql_real_connect to do its work.
I do not even know what CL you are using or the
version of CLSQL (I have the source for 3.5.2)

I really do not think the problem is the version of mysql.
Other potential problems are improper file permissions for
the mysql so.

See

http://dev.mysql.com/doc/refman/5.1/en/mysql-connect.html

Also in the ../dm-mysql/mysql-api.lisp there is

#-mysql-client-v4
(declaim (inline mysql-connect))
#-mysql-client-v4
(uffi:def-function "mysql_connect"
     ((mysql (* mysql-mysql))
      (host :cstring)
      (user :cstring)
      (passwd :cstring))
   :module "mysql"
   :returning (* mysql-mysql))

;; Need to comment this out for LW 4.2.6
;; ? bug in LW version
#-lispworks (declaim (inline mysql-real-connect))
(uffi:def-function "mysql_real_connect"
     ((mysql (* mysql-mysql))
      (host :cstring)
      (user :cstring)
      (passwd :cstring)
      (db :cstring)
      (port :unsigned-int)
      (unix-socket :cstring)
      (clientflag :unsigned-long))
   :module "mysql"
   :returning (* mysql-mysql))

Wade
From: Salim Q
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <873bj1t0b5.fsf@diaphanous.homeunix.net>
Hi, 

Thanks for helping me out so far, I have tried to give you as much info
as I can. I am not competent enough to read the source and figure out
what is wrong.


Wade Humeniuk <··················@telus.net> writes:

> Try to see what the symbols are in libmysqlclient.so are...
> You can use nm (do a man nm to see the args)

$ nm -D -g libmysqlclient.so | grep conn
         U connect
000337d0 T my_connect
00012c30 T mysql_manager_connect
00035900 T mysql_real_connect
000369a0 T mysql_reconnect

This seems to be missing a mysql_connect which cl-sql-mysql is looking
for, but has the mysql_real_connect. I used the -D flag (for dynamic
libraries) because otherwise nothing got displayed.


> I am pretty confused with your problem.  Can you post a
> backtrace of the error?  If you look at the cl-sql mysql
> code it seems to use mysql_real_connect to do its work.
> I do not even know what CL you are using or the
> version of CLSQL (I have the source for 3.5.2)

I am using cl-sql-mysql and cl-sql 3.5.3-1 from Debian
testing. Downgrading is only possible to 3.2.x if i use ancient
libs. Here is the backtrace, but there is much more to follow. Note how
the load asdf.lisp does not work but it may be nothing.

; SLIME 2005-12-27
CL-USER> (load "asdf.lisp")
; Evaluation aborted
CL-USER> (clc:clc-build-all-packages)
; loading system definition from /usr/share/common-lisp/systems/clsql-mysql.asd
; into #<The ASDF1861 package>
; Loading #P"/usr/share/common-lisp/source/clsql-mysql/clsql-mysql.asd".
; loading system definition from /usr/share/common-lisp/systems/uffi.asd into
; #<The ASDF1862 package>
;; Loading #P"/usr/share/common-lisp/source/uffi/uffi.asd".
; registering #<SYSTEM UFFI {58A99195}> as UFFI
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/package.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/primitives.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/objects.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/aggregates.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/functions.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/strings.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/libraries.x86f".
;; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/uffi/src/os.x86f".
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; registering #<SYSTEM :CLSQL-MYSQL {5859C1BD}> as CLSQL-MYSQL
; loading system definition from /usr/share/common-lisp/systems/clsql-uffi.asd
; into #<The ASDF1947 package>
; Loading #P"/usr/share/common-lisp/source/clsql-uffi/clsql-uffi.asd".
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; registering #<SYSTEM CLSQL-UFFI {589CC6CD}> as CLSQL-UFFI
; loading system definition from /usr/share/common-lisp/systems/clsql.asd into
; #<The ASDF1972 package>
; Loading #P"/usr/share/common-lisp/source/clsql/clsql.asd".
; registering #<SYSTEM CLSQL {589E883D}> as CLSQL
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. O C): 
; Compiling Top-Level Form: 
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/cmucl-compat.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/package.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/kmr-mop.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/base-classes.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/conditions.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/db-interface.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/time.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/utils.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/generics.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/initialize.x86f".

; In: LAMBDA (#:G2184 #:G2185 #:G2186)

;   (LET (#)
;     (DECLARE #)
;     (LET #
;       #))
; Note: Deleting unreachable code.
; 
;   (FUNCALL (THE FUNCTION #'#)
;            (PCL::FAST-METHOD-CALL-PV-CELL PCL::.CALL.)
;            (PCL::FAST-METHOD-CALL-NEXT-METHOD-CALL PCL::.CALL.)
;            PCL::.ARG0.)
; Note: Deleting unreachable code.
; 
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/database.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/recording.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/pool.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/expressions.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/operations.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/syntax.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/fdml.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/transaction.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/loop-extension.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/fddl.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/metaclasses.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/ooddl.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/oodml.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/generic-postgresql.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/generic-odbc.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql/sql/sequences.x86f".
; Loading #P"/etc/clsql-init.lisp".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-uffi/uffi/clsql-uffi-package.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-uffi/uffi/clsql-uffi-loader.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-uffi/uffi/clsql-uffi.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-mysql/db-mysql/mysql-package.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-mysql/db-mysql/mysql-loader.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-mysql/db-mysql/mysql-client-info.x86f".
; Loading #P"/var/cache/common-lisp-controller/tay/cmucl/clsql-mysql/db-mysql/mysql-api.x86f".

; Compilation unit aborted.
;   2 notes

Backtrace:
  0: (COMMON-LISP-CONTROLLER:CLC-BUILD-ALL-PACKAGES NIL)
  1: (SWANK::EVAL-REGION "(clc:clc-build-all-packages)
" T)
  2: ("DEFSLIMEFUN LISTENER-EVAL")
  3: (SWANK::CALL-WITH-BUFFER-SYNTAX #<Closure Over Function "DEFSLIMEFUN LISTENER-EVAL" {58A7BE31}>)
  4: ("DEFUN EVAL-FOR-EMACS")
  5: ((METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK NIL (T T)) #<#1=unused-arg> #<#1#> #<Function SWANK:SWANK-DEBUGGER-HOOK {58703FD1}> #<Closure Over Function "DEFUN EVAL-FOR-EMACS" {58A7BD59}>)
  6: ("DEFUN HANDLE-REQUEST")
  7: ("DEFUN CALL-WITH-CONNECTION")
  8: (SWANK::CALL-WITH-REDIRECTED-IO #<SWANK::CONNECTION {588E5FA5}> #<Closure Over Function "DEFUN CALL-WITH-CONNECTION" {58A7AE49}>)
  9: (SWANK::CALL-WITH-CONNECTION #<SWANK::CONNECTION {588E5FA5}> #<Function "DEFUN HANDLE-REQUEST" {585971C9}>)
 10: (SWANK::HANDLE-REQUEST #<SWANK::CONNECTION {588E5FA5}>)
 11: (SWANK::PROCESS-AVAILABLE-INPUT #<Stream for descriptor 6> #<Closure Over Function "DEFUN INSTALL-SIGIO-HANDLER" {58A7AE39}>)
 12: ((FLET SWANK::HANDLER SWANK::INSTALL-SIGIO-HANDLER))
 13: (SWANK-BACKEND::SIGIO-HANDLER #<#1=unused-arg> #<#1#> #<#1#>)
 14: ("call_into_lisp+#x8C [#x80548DC] /usr/bin/lisp")
 15: ("funcall3+#x29 [#x80546E4] /usr/bin/lisp")
 16: ("interrupt_handle_now+#xEF [#x80503A3] /usr/bin/lisp")
 17: ("NIL+#x80507C4 [#x80507C4] /usr/bin/lisp")
 18: ("NIL+#x40071658 [#x40071658] /lib/libc.so.6")
 19: (SYSTEM:WAIT-UNTIL-FD-USABLE 0 :INPUT NIL)
 20: (LISP::DO-INPUT #<Stream for Standard Input>)
 21: (LISP::INPUT-CHARACTER #<Stream for Standard Input> NIL (LISP::*EOF*))
 22: (LISP::SYNONYM-IN #<Synonym Stream to SYSTEM:*STDIN*> NIL (LISP::*EOF*))
 23: (LISP::TWO-WAY-IN #<Two-Way Stream, Input = #<Synonym Stream to SYSTEM:*STDIN*>, Output = #<Synonym Stream to SYSTEM:*STDOUT*>> NIL (LISP::*EOF*))
 24: (LISP::SYNONYM-IN #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (LISP::*EOF*))
 25: (READ-CHAR #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (LISP::*EOF*) NIL)
 26: (LISP::READ-PRESERVING-WHITESPACE-INTERNAL #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (:EOF) T)
 27: (LISP::READ-PRESERVING-WHITESPACE-INTERNAL #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (:EOF) NIL)
 28: (LISP::READ-PRESERVING-WHITESPACE-INTERNAL 4 #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (:EOF) ...)[:EXTERNAL]
 29: (LISP::READ-INTERNAL #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (:EOF) NIL)
 30: (READ #<Synonym Stream to SWANK::*CURRENT-STANDARD-INPUT*> NIL (:EOF) NIL)
 31: (LISP::%TOP-LEVEL)
 32: ((LABELS LISP::RESTART-LISP SAVE-LISP))



> I really do not think the problem is the version of mysql.
> Other potential problems are improper file permissions for
> the mysql so.

I have a mysql.so in my php dir. There is only a clsql_mysql.so in the
clsql dir.

$ find /usr -type f -name *mysql.so
/usr/lib/perl5/auto/DBD/mysql/mysql.so
/usr/lib/php5.0/20041030/mysql.so
/usr/lib/clsql/clsql_mysql.so

Permissions are generall rw-r-r for all these files and are default
debian permissions. apt-file lists that there should a mysql.so in the
clsql dir, but I am not sure.

> See
>
> http://dev.mysql.com/doc/refman/5.1/en/mysql-connect.html
>
> Also in the ../dm-mysql/mysql-api.lisp there is

I am not sure what declaim does exactly, and I havent downloaded the
source as I didnt fancy trying to find my problem that way.

Thanks a bunch again, I hope I have given you enough information.

Cheers,
salim


>
> #-mysql-client-v4
> (declaim (inline mysql-connect))
> #-mysql-client-v4
> (uffi:def-function "mysql_connect"
>     ((mysql (* mysql-mysql))
>      (host :cstring)
>      (user :cstring)
>      (passwd :cstring))
>   :module "mysql"
>   :returning (* mysql-mysql))
>
> ;; Need to comment this out for LW 4.2.6
> ;; ? bug in LW version
> #-lispworks (declaim (inline mysql-real-connect))
> (uffi:def-function "mysql_real_connect"
>     ((mysql (* mysql-mysql))
>      (host :cstring)
>      (user :cstring)
>      (passwd :cstring)
>      (db :cstring)
>      (port :unsigned-int)
>      (unix-socket :cstring)
>      (clientflag :unsigned-long))
>   :module "mysql"
>   :returning (* mysql-mysql))
>
> Wade
From: Christian Lynbech
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <87fyn0y2cb.fsf@chateau.defun.dk>
The problem could be related to MySQL versions. Debian recently
migrated from mysql 4 to mysql 5 (in unstable at least).

I have seen the same problem, including even problems with finding
"libmysqlclient.so" as it appears the link is not (any longer?)
maintained by the mysql packages. I have however not gotten round to
investigate and report the problem.


------------------------+-----------------------------------------------------
Christian Lynbech       | christian ··@ defun #\. dk
------------------------+-----------------------------------------------------
Hit the philistines three times over the head with the Elisp reference manual.
                                        - ·······@hal.com (Michael A. Petonic)
From: Wade Humeniuk
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <4nLEf.247071$OU5.21794@clgrps13>
Salim,

I think the easiest solution is to comment out the
mysql_connect definition, like this

Change

#-mysql-client-v4
(uffi:def-function "mysql_connect"
     ((mysql (* mysql-mysql))
      (host :cstring)
      (user :cstring)
      (passwd :cstring))
   :module "mysql"
   :returning (* mysql-mysql))

to

#+ignore
(uffi:def-function "mysql_connect"
     ((mysql (* mysql-mysql))
      (host :cstring)
      (user :cstring)
      (passwd :cstring))
   :module "mysql"
   :returning (* mysql-mysql))

I think the reason for this is that the UFFI tries to
resolve all symbols, even though they may not be used
by CLSQL.  It is obvious the symbol is not in
libmysqlclient.so.  Looking at the CLSQL source, mysql_connect
is not used anywhere so just delete it.

Wade
From: Salim Q
Subject: Re: cl-sql refuses to work
Date: 
Message-ID: <87y80rfvuz.fsf@diaphanous.homeunix.net>
Wade Humeniuk <··················@telus.net> writes:

> Salim,
>
> I think the easiest solution is to comment out the
> mysql_connect definition, like this
>
> Change
>
> #-mysql-client-v4
> (uffi:def-function "mysql_connect"
>     ((mysql (* mysql-mysql))
>      (host :cstring)
>      (user :cstring)
>      (passwd :cstring))
>   :module "mysql"
>   :returning (* mysql-mysql))
>
> to
>
> #+ignore
> (uffi:def-function "mysql_connect"
>     ((mysql (* mysql-mysql))
>      (host :cstring)
>      (user :cstring)
>      (passwd :cstring))
>   :module "mysql"
>   :returning (* mysql-mysql))
>
> I think the reason for this is that the UFFI tries to
> resolve all symbols, even though they may not be used
> by CLSQL.  It is obvious the symbol is not in
> libmysqlclient.so.  Looking at the CLSQL source, mysql_connect
> is not used anywhere so just delete it.
>
> Wade


Hi Wade,

Thanks a lot for your help. In addition to comment out the mysql_connect
definition as you suggested, I had to comment out mysql_create_db and
mysql_drop_db as well. These seem to be missing from the source
elsewhere as well.

Now the package compiles cleanly, and it seems to be working
fine. Thanks a lot for your help, I will bring this to the attention of
the debian maintainer for cl-sql-mysql by pointing him to this thread.

Cheers,
salim

PS. I modified the file
/usr/share/common-lisp/source/clsql-mysql/db-mysql/mysql-api.lisp
exactly as you said above.