Changeset 15015 in project


Ignore:
Timestamp:
06/18/09 10:49:13 (10 years ago)
Author:
daishi
Message:

mysql: added new procedure mysql-is-closed? and check the connection in most mysql procedures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/mysql/trunk/mysql.scm

    r15014 r15015  
    331331                mysql-field-charsetnr
    332332                mysql-field-type
     333               
     334                ; check if connection is closed
     335                mysql-is-closed?
    333336
    334337                ;; connection client flags
     
    474477;; my_bool
    475478
    476 (define-foreign-type my-bool "my_bool" (lambda (x) (if x 1 0)) (lambda (x) (not (fx= 0 x))))
     479;(define-foreign-type my-bool "my_bool" (lambda (x) (if x 1 0)) (lambda (x) (not (fx= 0 x))))
     480;the above raises an error in csc, and the below is a workaround.
     481(define-foreign-type my-bool char (lambda (x) (if x 1 0)) (lambda (x) (not (fx= 0 x))))
    477482
    478483;; MYSQL_FIELD_OFFSET
     
    13801385         host user passwd db port unix-socket client-flag options ssl options) ) ) )
    13811386
     1387; MySQL Connection verification functions
     1388
     1389(define (mysql-is-closed? conn)
     1390  (not (mysql-connection-ptr conn)))
     1391 
     1392(define (mysql-check-connection conn)
     1393  (if (mysql-is-closed? conn)
     1394      (signal-mysql-condition 'mysql-check-connection "connection is closed")))
     1395
    13821396;; Specialized connection record printers
    13831397
    13841398 ;DEBUG
    13851399(define-record-printer (mysql-connection conn out)
     1400  (mysql-check-connection conn)
    13861401        (let ([host (mysql-connection-host conn)]
    13871402                                [user (mysql-connection-user conn)]
     
    14211436#; ;RELEASE
    14221437(define-record-printer (mysql-connection conn out)
     1438  (mysql-check-connection conn)
    14231439        (let ([host (mysql-connection-host conn)]
    14241440                                [user (mysql-connection-user conn)]
     
    14511467
    14521468(define (mysql-affected-rows conn)
     1469  (mysql-check-connection conn)
    14531470        (let ([cnt (foreign-mysql-affected-rows (mysql-connection-ptr conn))])
    14541471                (and (not (= -1 cnt))
     
    14581475
    14591476(define (mysql-change-user conn #!key (user #f) (passwd #f) (db #f))
     1477  (mysql-check-connection conn)
    14601478        (foreign-mysql-change-user (mysql-connection-ptr conn) user passwd db) )
    14611479
     
    14631481
    14641482(define (mysql-character-set-name conn)
     1483  (mysql-check-connection conn)
    14651484        (foreign-mysql-character-set-name (mysql-connection-ptr conn)))
    14661485
     
    14951514
    14961515(define (mysql-dump-debug-info conn)
     1516  (mysql-check-connection conn)
    14971517        (foreign-mysql-dump-debug-info (mysql-connection-ptr conn)) )
    14981518
     
    15001520
    15011521(define (mysql-errno conn)
     1522  (mysql-check-connection conn)
    15021523        (foreign-mysql-errno (mysql-connection-ptr conn)))
    15031524
     
    15061527
    15071528(define (mysql-error conn)
     1529  (mysql-check-connection conn)
    15081530        (let ([errstr (foreign-mysql-error (mysql-connection-ptr conn))])
    15091531                (and (not (string=? "" errstr))
     
    15851607
    15861608(define (mysql-field-count conn)
     1609  (mysql-check-connection conn)
    15871610        (foreign-mysql-field-count (mysql-connection-ptr conn)) )
    15881611
     
    15991622
    16001623(define (mysql-get-character-set-info conn)
     1624  (mysql-check-connection conn)
    16011625        (let ([chrsetinfo (allocate-my-charset-info)])
    16021626                (foreign-mysql-get-character-set-info (mysql-connection-ptr conn) chrsetinfo)
     
    16171641
    16181642(define (mysql-get-host-info conn)
     1643  (mysql-check-connection conn)
    16191644        (foreign-mysql-get-host-info (mysql-connection-ptr conn)) )
    16201645
     
    16221647
    16231648(define (mysql-get-proto-info conn)
     1649  (mysql-check-connection conn)
    16241650        (foreign-mysql-get-proto-info (mysql-connection-ptr conn)) )
    16251651
     
    16271653
    16281654(define (mysql-get-server-info conn)
     1655  (mysql-check-connection conn)
    16291656        (foreign-mysql-get-server-info (mysql-connection-ptr conn)) )
    16301657
     
    16321659
    16331660(define (mysql-get-server-version conn)
     1661  (mysql-check-connection conn)
    16341662        (foreign-mysql-get-server-version (mysql-connection-ptr conn)) )
    16351663
     
    16371665
    16381666(define (mysql-info conn)
     1667  (mysql-check-connection conn)
    16391668        (foreign-mysql-info (mysql-connection-ptr conn)) )
    16401669
     
    16421671
    16431672(define (mysql-insert-id conn)
     1673  (mysql-check-connection conn)
    16441674        (foreign-mysql-insert-id (mysql-connection-ptr conn)) )
    16451675
     
    16471677
    16481678(define (mysql-kill conn pid)
     1679  (mysql-check-connection conn)
    16491680        (foreign-mysql-kill (mysql-connection-ptr conn) pid) )
    16501681
     
    16521683
    16531684(define (mysql-list-dbs conn like)
     1685  (mysql-check-connection conn)
    16541686        (mysql-free-result conn)
    16551687        (mysql-connection-result-set! conn
     
    16591691
    16601692(define (mysql-list-fields conn table wild)
     1693  (mysql-check-connection conn)
    16611694        (mysql-free-result conn)
    16621695        (mysql-connection-result-set! conn
     
    16661699
    16671700(define (mysql-list-processes conn)
     1701  (mysql-check-connection conn)
    16681702        (mysql-free-result conn)
    16691703        (mysql-connection-result-set! conn
     
    16731707
    16741708(define (mysql-list-tables conn wild)
     1709  (mysql-check-connection conn)
    16751710        (mysql-free-result conn)
    16761711        (mysql-connection-result-set! conn
     
    16911726
    16921727(define (mysql-ping conn)
     1728  (mysql-check-connection conn)
    16931729        (foreign-mysql-ping (mysql-connection-ptr conn)) )
    16941730
     
    16961732
    16971733(define (mysql-query conn query)
     1734  (mysql-check-connection conn)
    16981735        (let ([mysql-ptr (mysql-connection-ptr conn)])
    16991736                ; zero indicates success
     
    17051742
    17061743(define (mysql-select-db conn db)
     1744  (mysql-check-connection conn)
    17071745        (or (fx= 0 (foreign-mysql-select-db (mysql-connection-ptr conn) db))
    17081746                        (signal-mysql-error 'mysql-select-db conn db) ) )
     
    17111749
    17121750(define (mysql-set-character-set conn csname)
     1751  (mysql-check-connection conn)
    17131752        (or (fx= 0 (foreign-mysql-set-character-set (mysql-connection-ptr conn) csname))
    17141753                        (signal-mysql-condition 'mysql-set-character-set "bad character set name" csname) ) )
     
    17171756
    17181757(define (mysql-stat conn)
     1758  (mysql-check-connection conn)
    17191759        (foreign-mysql-stat (mysql-connection-ptr conn)) )
    17201760
     
    17221762
    17231763(define (mysql-store-result conn)
     1764  (mysql-check-connection conn)
    17241765        (mysql-connection-result-set! conn
    17251766         (foreign-mysql-store-result (mysql-connection-ptr conn)))
     
    17311772
    17321773(define (mysql-thread-id conn)
     1774  (mysql-check-connection conn)
    17331775        (foreign-mysql-thread-id (mysql-connection-ptr conn)) )
    17341776
Note: See TracChangeset for help on using the changeset viewer.