Giter VIP home page Giter VIP logo

ruby-odbc's Introduction

ODBC binding for Ruby

DESCRIPTION:

This is an ODBC binding for Ruby. So far it has been tested with

- Ruby 1.[6-9], MySQL 3.22/MyODBC (local), unixODBC 2.1.0
  on Linux 2.2-x86 and 2.6-x86_64

- Ruby 1.6.4, MySQL 3.22/MyODBC (local), libiodbc 2.50
  on Linux 2.2-x86

- Ruby 1.[6-8], MySQL 3.22/MyODBC (remote), MS Jet Engine, MSVC++ 6.0
  on Windows NT4SP6

- Ruby 1.6.[3-5], MySQL 3.22/MyODBC (remote), MS Jet Engine, cygwin,
  on Windows NT4SP6 and 2000

- Ruby 1.8.*, SQLite/ODBC >= 0.67, libiodbc 3.52.4 on Fedora Core 3 x86

Michael Neumann <[email protected]> and
Will Merrell <[email protected]> reported successful compilation
with Cygwin on Win32.

Requirements:

- Ruby 1.6.[3-8] or Ruby >= 1.7
- unixODBC 2.x or libiodbc 3.52 on UN*X

Installation:

$ ruby -Cext extconf.rb [--enable-dlopen|--disable-dlopen]
$ make -C ext
# make -C ext install

--enable/disble-dlopen turns on/off special initialization
code to make ruby-odbc agnostic to unixODBC/iODBC driver
manager shared library names when GCC is used for compile.
In cases where unixODBC or iODBC is installed in non-standard
locations, use the option --with-odbc-dir=<non-standard-location>
when running extconf.rb

Installation of utf8 version:

$ ruby -Cext/utf8 extconf.rb [--enable-dlopen|--disable-dlopen]
$ make -C ext/utf8
# make -C ext/utf8 install

Installation MSVC:

C:..>ruby -Cext extconf.rb
C:..>cd ext
C:..>nmake
C:..>nmake install
C:..>ruby -Cutf8 extconf.rb
C:..>cd utf8
C:..>nmake
C:..>nmake install

Testing:

   $ ruby -Ctest test.rb DSN [uid] [pwd]
or
   $ ruby -KU -Ctest/utf8 test.rb DSN [uid] [pwd]

Usage:

Refer to doc/odbc.html

The difference between utf8 and non-utf8 versions are:

  - non-utf8 version uses normal SQL.* ANSI functions
  - utf8 version uses SQL.*W UNICODE functions and
    requires/returns all strings in UTF8 format

Thus, depending on the -K option of ruby one could use
that code snippet:

  ...
  if $KCODE == "UTF8" then
    require 'odbc_utf8'
  else
    require 'odbc'
  fi

It is also possible to load both non-utf8 and utf8 version
into ruby:

  ...
  # non-utf8 version
  require 'odbc'
  # utf8 version
  require 'odbc_utf8'

Whichever is loaded first, gets the module name 'ODBC'.
The second loaded module will be named 'ODBC_UTF8' (for
'odbc_utf8') or 'ODBC_NONE' (for 'odbc'). That should
allow to use both versions simultaneously in special
situations.

TODO:

- heavier testing
- improve documentation

Author:

Christian Werner
mailto:[email protected]
http://www.ch-werner.de/rubyodbc

ruby-odbc's People

Contributors

larskanis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ruby-odbc's Issues

512 bytes longer text data drops in query on Windows enviroment

Hi, I use ruby-odbc library in Windows11 envrioment (windows native).

But it seems 512 bytes longer text in Query.
Maybe it looks memory break.

require "odbc"

def connect()
	driver = ODBC::Driver.new
	driver.name = 'odbc'
	driver.attrs = {}
	driver.attrs["DRIVER"] = "FileMaker ODBC"
	driver.attrs["HOST"] = "localhost"
	driver.attrs["DATABASE"] = "fmtest"
	driver.attrs["UID"] = "user"
	driver.attrs["PWD"] = "user"

	return ODBC::Database.new.drvconnect(driver)
end

db = connect()
res = db.run("SELECT docs FROM yomi WHERE id=1")
p res.first
PS D:\tmp> ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x64-mingw32]

PS D:\tmp> gem list ruby-odbc
*** LOCAL GEMS ***
ruby-odbc (0.999991)

PS D:\tmp> ruby .\test_odbc.rb
["Prince of Denmarke. The bird of dawning singeth all night long,\rAnd then they say, no spirite dare walke abroade,\rThe nights are wholesome, then no planet frikes,\rNo Fairie takes, nor Witch hath powre to charme,\rSo gratious, and so hallowed is that time.\r\x00    str1\x91*\x9D\xD5h\x05\x00\x88\xBE\xD5\x93r\xFE\x7F\x00\x00\x9D\xC3\x93r\xFE\x7F\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\xA0\xABHz\b\x02\x00\x00B\xAA\x93r\xFE\x7F\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00s\xAB\x93r\xFE\x7F\x00\x00\e7\x00\x00\x00\x00\x00\x00/\xC4\x93r\xFE\x7F\x00\x00\xA0\xABHz\b\x02\x00\x00\xBB\xB1\x93r\xFE\x7F\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00<\xB6\x93r\xFE\x7F\x00\x00 \xA1Hz\b\x02\x00\x00\b\xC3\x93r\xFE\x7F\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00B\xAA\x93r\xFE\x7F\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\xE7\xB0\x93r\xFE\x7F\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x9D\xC3\x93r\xFE\x7F\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\xB0\xABHz\b\x02\x00\x00B\xAA\x93r\xFE\x7F\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00s\xAB\x93r\xFE\x7F\x00\x00\e7\x00\x00\x00\x00\x00\x00/\xC4\x93r\xFE\x7F\x00\x00\xB0\xABHz\b\x02\x00\x00\xBB\xB1\x93r\xFE\x7F\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x86\x9C\x93r\xFE\x7F\x00\x000\xA1Hz\b\x02\x00\x00\xBE\xD5\x93r\xFE\x7F\x00\x00H\xBE\x93r\xFE\x7F\x00\x00\xA3*\xB3\xD5\n\x06\x00\x80     d[j] = e\n        e = x\n      end\n\n      d[m] = x\n    end\n\n    return x\n  end\nend\n\x00\x00\xD8\x00\x00\x00\x02\x00\x00\x00\xDC\x00\x00\x00\x05\x00\x00\x00*\x01\x00\x00\b\x02\x00\x00\eF\x00\x00\x00\x00\x00\x00Q\r\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF+\x01\x00\x00\b\x02\x00\x00\e\xB0l\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"]
WARNING: #<ODBC::Statement:0x7a640bc0> was not dropped before garbage collection.
PS D:\tmp>

Does anyone see some probrem?

Can't get it installed in Ubuntu 18.04 or Mac 10.15.1

running Ruby 2.5.5 on Mac and 2.6.3 on Ubuntu 18.04 when I try to install ruby-odbc I get this error

 `checking for version.h... no
  checking for sql.h... no
   *** extconf.rb failed ***
  Could not create Makefile due to some reason, probably lack of necessary
  libraries and/or headers.  Check the mkmf.log file for more details.`

and in the mkmf.log

   conftest.c:3:10: fatal error: sql.h: No such file or directory
   #include <sql.h>
      ^~~~~~~
   compilation terminated.
   checked program was:
   /* begin */
  1: #include "ruby.h"
  2: 
  3: #include <sql.h>
  /* end */

Where do I get sql.h from?

gem install fails on windows 8.1 with ruby 2.1 and devkit

when I gem install ruby-odbc, I get the error:

make failed, uncaught signal 11

-- gem install output --

C:\APPS\RUBY21-X64\devkit\mingw\bin>gem install ruby-odbc
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing ruby-odbc:
ERROR: Failed to build gem native extension.

current directory: C:/APPS/RUBY21-X64/lib/ruby/gems/2.1.0/gems/ruby-odbc-0.99997/ext

C:/APPS/RUBY21-X64/bin/ruby.exe -r ./siteconf20160322-42016-1v2yhn8.rb extconf.rb
checking for version.h... no
checking for sql.h... yes
checking for sqlext.h... yes
checking for SQLTCHAR in windows.h,sqltypes.h... yes
checking for SQLLEN in windows.h,sqltypes.h... yes
checking for SQLULEN in windows.h,sqltypes.h... yes
checking for odbcinst.h... yes
checking for SQLROWOFFSET in windows.h,sqltypes.h... yes
checking for odbcinst.h... yes
checking for SQLROWSETSIZE in windows.h,sqltypes.h... yes
checking for odbcinst.h... yes
checking for main() in -lodbc32... yes
checking for main() in -lodbccp32... yes
checking for main() in -luser32... yes
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

C:/APPS/RUBY21-X64/lib/ruby/gems/2.1.0/extensions/x64-mingw32/2.1.0/ruby-odbc-0.99997/mkmf.log

current directory: C:/APPS/RUBY21-X64/lib/ruby/gems/2.1.0/gems/ruby-odbc-0.99997/ext
make "DESTDIR=" clean

current directory: C:/APPS/RUBY21-X64/lib/ruby/gems/2.1.0/gems/ruby-odbc-0.99997/ext
make "DESTDIR="

make failed, uncaught signal 11

Gem files will remain installed in C:/APPS/RUBY21-X64/lib/ruby/gems/2.1.0/gems/ruby-odbc-0.99997 for inspection.
Results logged to C:/APPS/RUBY21-X64/lib/ruby/gems/2.1.0/extensions/x64-mingw32/2.1.0/ruby-odbc-0.99997/gem_make.out

--ruby version--
C:\APPS\RUBY21-X64\devkit\mingw\bin>ruby -v
ruby 2.1.7p400 (2015-08-18 revision 51632) [x64-mingw32]

--windows version--
C:\APPS\RUBY21-X64\devkit\mingw\bin>ver

Microsoft Windows [Version 6.3.9600]

--- devkit ---
C:\APPS\RUBY21-X64\devkit\mingw\bin>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/apps/ruby21-x64/devkit/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: /home/ruben/mingw-w64/src/gcc/configure --host=x86_64-w64-mingw32 --build=x86_64-linux-gnu --target=x86_64-w64-mingw32 --with-sysroot=/home/ruben/mi
ngw-w64/mingw64mingw64/mingw64 --prefix=/home/ruben/mingw-w64/mingw64mingw64/mingw64 --with-gmp=/home/ruben/mingw-w64/prereq/x86_64-w64-mingw32/install --with-mpfr=/
home/ruben/mingw-w64/prereq/x86_64-w64-mingw32/install --with-mpc=/home/ruben/mingw-w64/prereq/x86_64-w64-mingw32/install --with-ppl=/home/ruben/mingw-w64/prereq/x86
_64-w64-mingw32/install --with-cloog=/home/ruben/mingw-w64/prereq/x86_64-w64-mingw32/install --disable-ppl-version-check --disable-cloog-version-check --enable-cloog
-backend=isl --with-host-libstdcxx='-static -lstdc++ -lm' --enable-shared --enable-static --enable-threads=win32 --enable-plugins --disable-multilib --enable-languag
es=c,lto,c++,objc,obj-c++,fortran,java --enable-libgomp --enable-fully-dynamic-string --enable-libstdcxx-time --disable-nls --disable-werror --enable-checking=releas
e --with-gnu-as --with-gnu-ld --disable-win32-registry --disable-rpath --disable-werror --with-libiconv-prefix=/home/ruben/mingw-w64/prereq/x86_64-w64-mingw32/instal
l --with-pkgversion=rubenvb-4.7.2-release --with-bugurl=[email protected] CC= CFLAGS='-O2 -march=nocona -mtune=core2 -fomit-frame-pointer -momit
-leaf-frame-pointer' LDFLAGS=
Thread model: win32
gcc version 4.7.2 (rubenvb-4.7.2-release)

Database.get_info returns malformed ASCII in UTF8 mode

To reproduce:

require 'odbc_utf8'
attrs = 'DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=odbc_test;UID=postgres;ENCODING=utf8'.split(';').map { |option| option.split('=', 2) }.to_h
driver = ODBC::Driver.new
driver.name = 'odbc'
driver.attrs = attrs
conn = ODBC::Database.new.drvconnect(driver)
i = conn.get_info(ODBC::SQL_DBMS_NAME)
puts i.encoding

Regardless of LOCALE, LC_CODE, LC_ALL the value returned is always ASCII-8BIT and the string appears to be UTF-16 Little endian coded, a la P\x00o\x00s\x00t\x00g\x00r\x00e\x00S\x00Q\x00L\x00

Fails to make with Ruby 3.2.0

Fails to make it with Ruby 3.2.0

odbc.c:1873:20: error: implicit declaration of function 'rb_obj_taint' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    rb_ary_push(a, rb_obj_taint(v));
                   ^
odbc.c:1952:21: error: implicit declaration of function 'rb_obj_taint' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            rb_ary_push(a, rb_obj_taint(v));
                           ^
odbc.c:2048:21: error: implicit declaration of function 'rb_obj_taint' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            rb_ary_push(a, rb_obj_taint(v));
                           ^
odbc.c:2302:20: error: implicit declaration of function 'rb_obj_taint' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    rb_ary_push(a, rb_obj_taint(v));
                   ^
odbc.c:2392:27: error: implicit declaration of function 'rb_tainted_str_new' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        rb_iv_set(odsn, "@name", rb_tainted_str_new(dsn, dsnLen));
                                 ^
odbc.c:2457:27: error: implicit declaration of function 'rb_tainted_str_new' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        rb_iv_set(odrv, "@name", rb_tainted_str_new(driver, driverLen));
                                 ^
odbc.c:2463:9: error: implicit declaration of function 'rb_tainted_str_new2' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                             rb_tainted_str_new2(p + 1));
                             ^
odbc.c:2463:9: note: did you mean 'rb_tainted_str_new'?
odbc.c:2392:27: note: 'rb_tainted_str_new' declared here
        rb_iv_set(odsn, "@name", rb_tainted_str_new(dsn, dsnLen));
                                 ^
odbc.c:2782:9: error: implicit declaration of function 'rb_tainted_str_new2' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        return rb_tainted_str_new2(valbuf);
               ^
odbc.c:4589:29: error: implicit declaration of function 'rb_tainted_str_new2' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    rb_iv_set(obj, "@name", rb_tainted_str_new2(upcase_if(name, upc)));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.