tiny_tds 2.1.7-x64-mingw32 → 3.1.0-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +477 -0
  3. data/CHANGELOG.md +14 -0
  4. data/ISSUE_TEMPLATE.md +1 -1
  5. data/README.md +25 -45
  6. data/Rakefile +2 -6
  7. data/VERSION +1 -1
  8. data/docker-compose.yml +2 -2
  9. data/ext/tiny_tds/client.c +8 -15
  10. data/ext/tiny_tds/extconf.rb +1 -2
  11. data/ext/tiny_tds/extconsts.rb +4 -10
  12. data/ext/tiny_tds/result.c +27 -35
  13. data/ext/tiny_tds/tiny_tds_ext.c +4 -1
  14. data/lib/tiny_tds/2.7/tiny_tds.so +0 -0
  15. data/lib/tiny_tds/3.0/tiny_tds.so +0 -0
  16. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/bin/bsqldb.exe +0 -0
  17. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/bin/datacopy.exe +0 -0
  18. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/bin/defncopy.exe +0 -0
  19. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/bin/freebcp.exe +0 -0
  20. data/ports/x64-mingw32/freetds/1.4.23/bin/libct-4.dll +0 -0
  21. data/ports/x64-mingw32/freetds/1.4.23/bin/libsybdb-5.dll +0 -0
  22. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/bin/osql +84 -79
  23. data/ports/x64-mingw32/freetds/1.4.23/bin/tdspool.exe +0 -0
  24. data/ports/x64-mingw32/freetds/1.4.23/bin/tsql.exe +0 -0
  25. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/lib/libct.la +3 -3
  26. data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/lib/libsybdb.la +3 -3
  27. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/bin/iconv.exe +0 -0
  28. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/bin/libcharset-1.dll +0 -0
  29. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/bin/libiconv-2.dll +0 -0
  30. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/lib/libcharset.dll.a +0 -0
  31. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/lib/libcharset.la +3 -3
  32. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/lib/libiconv.dll.a +0 -0
  33. data/ports/x64-mingw32/libiconv/{1.15 → 1.17}/lib/libiconv.la +4 -4
  34. data/ports/x64-mingw32/openssl/{1.1.1s → 3.4.0}/bin/c_rehash +46 -45
  35. data/ports/x64-mingw32/openssl/3.4.0/bin/libcrypto-3-x64.dll +0 -0
  36. data/ports/x64-mingw32/openssl/3.4.0/bin/libssl-3-x64.dll +0 -0
  37. data/ports/x64-mingw32/openssl/3.4.0/bin/openssl.exe +0 -0
  38. data/tasks/ports/freetds.rb +1 -6
  39. data/tasks/ports.rake +2 -2
  40. data/test/bin/install-mssql.ps1 +22 -11
  41. data/test/client_test.rb +2 -5
  42. data/test/gem_test.rb +1 -2
  43. data/test/result_test.rb +99 -192
  44. data/test/schema_test.rb +366 -388
  45. data/test/test_helper.rb +7 -38
  46. data/tiny_tds.gemspec +5 -4
  47. metadata +50 -49
  48. data/.circleci/config.yml +0 -409
  49. data/lib/tiny_tds/2.4/tiny_tds.so +0 -0
  50. data/lib/tiny_tds/2.5/tiny_tds.so +0 -0
  51. data/lib/tiny_tds/2.6/tiny_tds.so +0 -0
  52. data/ports/x64-mingw32/freetds/1.1.24/bin/libct-4.dll +0 -0
  53. data/ports/x64-mingw32/freetds/1.1.24/bin/libsybdb-5.dll +0 -0
  54. data/ports/x64-mingw32/freetds/1.1.24/bin/tdspool.exe +0 -0
  55. data/ports/x64-mingw32/freetds/1.1.24/bin/tsql.exe +0 -0
  56. data/ports/x64-mingw32/libiconv/1.15/lib/charset.alias +0 -4
  57. data/ports/x64-mingw32/openssl/1.1.1s/bin/libcrypto-1_1-x64.dll +0 -0
  58. data/ports/x64-mingw32/openssl/1.1.1s/bin/libssl-1_1-x64.dll +0 -0
  59. data/ports/x64-mingw32/openssl/1.1.1s/bin/openssl.exe +0 -0
  60. data/ports/x64-mingw32/openssl/1.1.1s/lib/libcrypto.a +0 -0
  61. data/ports/x64-mingw32/openssl/1.1.1s/lib/libcrypto.dll.a +0 -0
  62. data/ports/x64-mingw32/openssl/1.1.1s/lib/libssl.a +0 -0
  63. data/ports/x64-mingw32/openssl/1.1.1s/lib/libssl.dll.a +0 -0
  64. data/test/schema/sqlserver_2000.sql +0 -140
  65. data/test/schema/sqlserver_2005.sql +0 -140
  66. data/test/schema/sqlserver_2014.sql +0 -140
  67. data/test/schema/sqlserver_2016.sql +0 -140
  68. data/test/schema/sybase_ase.sql +0 -138
  69. /data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/lib/libct.dll.a +0 -0
  70. /data/ports/x64-mingw32/freetds/{1.1.24 → 1.4.23}/lib/libsybdb.dll.a +0 -0
  71. /data/test/schema/{sqlserver_2008.sql → sqlserver_2017.sql} +0 -0
data/Rakefile CHANGED
@@ -7,14 +7,10 @@ require_relative './ext/tiny_tds/extconsts'
7
7
 
8
8
  SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
9
9
 
10
- ruby_cc_ucrt_versions = "3.3.0:3.2.0:3.1.0".freeze
11
- ruby_cc_mingw32_versions = "3.0.0:2.7.0:2.6.0:2.5.0:2.4.0".freeze
10
+ ruby_cc_ucrt_versions = "3.4.0:3.3.5:3.2.0:3.1.0".freeze
11
+ ruby_cc_mingw32_versions = "3.0.0:2.7.0".freeze
12
12
 
13
13
  GEM_PLATFORM_HOSTS = {
14
- 'x86-mingw32' => {
15
- host: 'i686-w64-mingw32',
16
- ruby_versions: ruby_cc_mingw32_versions
17
- },
18
14
  'x64-mingw32' => {
19
15
  host: 'x86_64-w64-mingw32',
20
16
  ruby_versions: ruby_cc_mingw32_versions
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.7
1
+ 3.1.0
data/docker-compose.yml CHANGED
@@ -5,11 +5,11 @@ networks:
5
5
 
6
6
  services:
7
7
  mssql:
8
- image: metaskills/mssql-server-linux-tinytds:2017-GA
8
+ image: mcr.microsoft.com/mssql/server:${MSSQL_VERSION:-2017}-latest
9
9
  container_name: sqlserver
10
10
  environment:
11
11
  ACCEPT_EULA: Y
12
- SA_PASSWORD: super01S3cUr3
12
+ MSSQL_SA_PASSWORD: super01S3cUr3
13
13
  ports:
14
14
  - "1433:1433"
15
15
  network_mode: "host"
@@ -299,8 +299,7 @@ static VALUE rb_tinytds_execute(VALUE self, VALUE sql) {
299
299
  REQUIRE_OPEN_CLIENT(cwrap);
300
300
  dbcmd(cwrap->client, StringValueCStr(sql));
301
301
  if (dbsqlsend(cwrap->client) == FAIL) {
302
- rb_warn("TinyTds: dbsqlsend() returned FAIL.\n");
303
- return Qfalse;
302
+ rb_raise(cTinyTdsError, "failed dbsqlsend() function");
304
303
  }
305
304
  cwrap->userdata->dbsql_sent = 1;
306
305
  result = rb_tinytds_new_result_obj(cwrap);
@@ -404,17 +403,15 @@ static VALUE rb_tinytds_connect(VALUE self, VALUE opts) {
404
403
  #endif
405
404
  }
406
405
  }
407
- #ifdef DBSETUTF16
408
- if (use_utf16 == Qtrue) { DBSETLUTF16(cwrap->login, 1); }
409
- if (use_utf16 == Qfalse) { DBSETLUTF16(cwrap->login, 0); }
410
- #else
411
- if (use_utf16 == Qtrue || use_utf16 == Qfalse) {
412
- rb_warning("TinyTds: Please consider upgrading to FreeTDS 0.99 or higher for better unicode support.\n");
413
- }
414
- #endif
406
+ if (use_utf16 == Qtrue) { DBSETLUTF16(cwrap->login, 1); }
407
+ if (use_utf16 == Qfalse) { DBSETLUTF16(cwrap->login, 0); }
415
408
 
416
409
  cwrap->client = dbopen(cwrap->login, StringValueCStr(dataserver));
417
410
  if (cwrap->client) {
411
+ if (dbtds(cwrap->client) < 11) {
412
+ rb_raise(cTinyTdsError, "connecting with a TDS version older than 7.3!");
413
+ }
414
+
418
415
  VALUE transposed_encoding, timeout_string;
419
416
 
420
417
  cwrap->closed = 0;
@@ -435,11 +432,7 @@ static VALUE rb_tinytds_connect(VALUE self, VALUE opts) {
435
432
  }
436
433
  transposed_encoding = rb_funcall(cTinyTdsClient, intern_transpose_iconv_encoding, 1, charset);
437
434
  cwrap->encoding = rb_enc_find(StringValueCStr(transposed_encoding));
438
- if (dbtds(cwrap->client) <= 7) {
439
- cwrap->identity_insert_sql = "SELECT CAST(@@IDENTITY AS bigint) AS Ident";
440
- } else {
441
- cwrap->identity_insert_sql = "SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident";
442
- }
435
+ cwrap->identity_insert_sql = "SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident";
443
436
  }
444
437
  return self;
445
438
  }
@@ -22,7 +22,6 @@ do_help if arg_config('--help')
22
22
 
23
23
  # Make sure to check the ports path for the configured host
24
24
  architecture = RbConfig::CONFIG['arch']
25
- architecture = "x86-mingw32" if architecture == "i386-mingw32"
26
25
 
27
26
  project_dir = File.expand_path("../../..", __FILE__)
28
27
  freetds_ports_dir = File.join(project_dir, 'ports', architecture, 'freetds', FREETDS_VERSION)
@@ -84,7 +83,7 @@ have_dependencies = [
84
83
  end
85
84
 
86
85
  unless have_dependencies
87
- abort 'Failed! Do you have FreeTDS 0.95.80 or higher installed?'
86
+ abort 'Failed! Do you have FreeTDS 1.0.0 or higher installed?'
88
87
  end
89
88
 
90
89
  create_makefile('tiny_tds/tiny_tds')
@@ -1,15 +1,9 @@
1
1
 
2
- ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.15"
2
+ ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.17"
3
3
  ICONV_SOURCE_URI = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"
4
4
 
5
- OPENSSL_VERSION = ENV['TINYTDS_OPENSSL_VERSION'] || '1.1.1s'
5
+ OPENSSL_VERSION = ENV['TINYTDS_OPENSSL_VERSION'] || '3.4.0'
6
6
  OPENSSL_SOURCE_URI = "https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
7
7
 
8
- FREETDS_VERSION = ENV['TINYTDS_FREETDS_VERSION'] || "1.1.24"
9
- FREETDS_VERSION_INFO = Hash.new { |h,k|
10
- h[k] = {files: "http://www.freetds.org/files/stable/freetds-#{k}.tar.bz2"}
11
- }
12
- FREETDS_VERSION_INFO['1.00'] = {files: 'http://www.freetds.org/files/stable/freetds-1.00.tar.bz2'}
13
- FREETDS_VERSION_INFO['0.99'] = {files: 'http://www.freetds.org/files/current/freetds-dev.0.99.678.tar.gz'}
14
- FREETDS_VERSION_INFO['0.95'] = {files: 'http://www.freetds.org/files/stable/freetds-0.95.92.tar.gz'}
15
- FREETDS_SOURCE_URI = FREETDS_VERSION_INFO[FREETDS_VERSION][:files]
8
+ FREETDS_VERSION = ENV['TINYTDS_FREETDS_VERSION'] || '1.4.23'
9
+ FREETDS_SOURCE_URI = "http://www.freetds.org/files/stable/freetds-#{FREETDS_VERSION}.tar.bz2"
@@ -298,42 +298,34 @@ static VALUE rb_tinytds_result_fetch_row(VALUE self, ID timezone, int symbolize_
298
298
  }
299
299
  break;
300
300
  }
301
- case 40: // SYBMSDATE
302
- case 41: // SYBMSTIME
303
- case 42: // SYBMSDATETIME2
304
- case 43: { // SYBMSDATETIMEOFFSET
305
- #ifdef DBVERSION_73
306
- if (dbtds(rwrap->client) >= DBTDS_7_3) {
307
- DBDATEREC2 dr2;
308
- dbanydatecrack(rwrap->client, &dr2, coltype, data);
309
- switch(coltype) {
310
- case 40: { // SYBMSDATE
311
- val = rb_funcall(cDate, intern_new, 3, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day));
312
- break;
313
- }
314
- case 41: { // SYBMSTIME
315
- VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek);
316
- val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(1900), INT2NUM(1), INT2NUM(1), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec);
317
- break;
318
- }
319
- case 42: { // SYBMSDATETIME2
320
- VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek);
321
- val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec);
322
- break;
323
- }
324
- case 43: { // SYBMSDATETIMEOFFSET
325
- long long numerator = ((long)dr2.second * (long long)1000000000) + (long long)dr2.nanosecond;
326
- VALUE rational_sec = rb_Rational(LL2NUM(numerator), opt_onebil);
327
- val = rb_funcall(rb_cTime, intern_new, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), rational_sec, INT2NUM(dr2.tzone*60));
328
- break;
329
- }
330
- }
331
- } else {
332
- val = ENCODED_STR_NEW(data, data_len);
301
+ case SYBMSDATE:
302
+ case SYBMSTIME:
303
+ case SYBMSDATETIME2:
304
+ case SYBMSDATETIMEOFFSET: {
305
+ DBDATEREC2 dr2;
306
+ dbanydatecrack(rwrap->client, &dr2, coltype, data);
307
+ switch(coltype) {
308
+ case SYBMSDATE: {
309
+ val = rb_funcall(cDate, intern_new, 3, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day));
310
+ break;
333
311
  }
334
- #else
335
- val = ENCODED_STR_NEW(data, data_len);
336
- #endif
312
+ case SYBMSTIME: {
313
+ VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek);
314
+ val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(1900), INT2NUM(1), INT2NUM(1), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec);
315
+ break;
316
+ }
317
+ case SYBMSDATETIME2: {
318
+ VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek);
319
+ val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec);
320
+ break;
321
+ }
322
+ case SYBMSDATETIMEOFFSET: {
323
+ long long numerator = ((long)dr2.second * (long long)1000000000) + (long long)dr2.nanosecond;
324
+ VALUE rational_sec = rb_Rational(LL2NUM(numerator), opt_onebil);
325
+ val = rb_funcall(rb_cTime, intern_new, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), rational_sec, INT2NUM(dr2.tzone*60));
326
+ break;
327
+ }
328
+ }
337
329
  break;
338
330
  }
339
331
  case SYBCHAR:
@@ -1,6 +1,9 @@
1
-
2
1
  #include <tiny_tds_ext.h>
3
2
 
3
+ #ifndef DBVERSION_73
4
+ #error "DBVERSION_73 is not defined. Aborting compilation."
5
+ #endif
6
+
4
7
  VALUE mTinyTds, cTinyTdsError;
5
8
 
6
9
  void Init_tiny_tds() {
Binary file
Binary file
@@ -5,7 +5,7 @@
5
5
  # then execute isql (assume it's unixODBC's isql).
6
6
  #
7
7
 
8
- USAGE="Syntax: $(basename $0) -S server -U user -P password"
8
+ USAGE="Syntax: $(basename "$0") -S server -U user -P password"
9
9
 
10
10
  while getopts I:S:U:P: OPTION
11
11
  do
@@ -18,68 +18,73 @@ do
18
18
  ;;
19
19
  P) PASSWORD=${OPTARG}
20
20
  ;;
21
- \?) echo $USAGE
21
+ \?) echo "$USAGE"
22
22
  exit 1
23
23
  ;;
24
24
  esac
25
25
  done
26
26
 
27
27
  #cho ${DSN} ${USERNAME} ${PASSWORD}
28
- if [ -z "${DSN}" -o -z "${USERNAME}" -o -z "${PASSWORD}" ]
28
+ if [ -z "${DSN}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]
29
29
  then
30
-
31
- echo $USAGE
30
+ echo "$USAGE"
32
31
  exit 1
33
32
  fi
34
33
 
35
34
  ISQL=$(command -v isql)
36
35
  if [ -z "${ISQL}" ]
37
36
  then
38
- echo "$(basename $0): error: no \"isql\" command found. Is unixODBC installed?"
37
+ echo "$(basename "$0"): error: no \"isql\" command found. Is unixODBC installed?"
39
38
  exit 1
40
39
  fi
41
40
 
42
41
  # Establish ODBC prefix directory
43
42
 
44
- ISQL_DIR=$(strings ${ISQL} | grep ^/ | grep -v elf | grep -v '\.so\.' | head -1 | sed 's/lib$/etc/' )
43
+ ISQL_DIR=$(strings "${ISQL}" | grep ^/ | grep -v elf | grep -v '\.so\.' | head -1 | sed 's/lib$/etc/' )
45
44
 
46
- INI_DIRNAME="/tmp/$(basename $0).$$"
47
- exec 3> ${INI_DIRNAME}
45
+ INI_DIRNAME="/tmp/$(basename "$0").$$"
46
+ exec 3> "${INI_DIRNAME}"
48
47
 
49
48
  # Check the libraries, too.
50
49
  if [ -z "${OVER_DIR}" ]
51
50
  then
51
+ libcmd='ldd "${ISQL}" | awk "/libodbc\./ {print \$3}"'
52
+ if ! command -V ldd >/dev/null 2>&1 && command -V otool >/dev/null 2>&1
53
+ then
54
+ libcmd='otool -L "${ISQL}" | awk "/libodbc\./ {print \$1}"'
55
+ fi
52
56
  echo "checking shared odbc libraries linked to isql for default directories..."
53
- (echo ${ISQL_DIR}; ldd "${ISQL}" | awk '/libodbc\./ {print $3}') \
57
+ (echo ${ISQL_DIR}; eval "$libcmd") \
54
58
  | while read L
55
59
  do
56
- strings "$L" | grep '^/' | grep -v '/lib' \
60
+ strings "$L" | grep '^/' | grep -v '/lib' \
57
61
  | while read D
58
62
  do
59
- if [ ! -s "${INI_DIRNAME}" ]
63
+ if [ ! -s "${INI_DIRNAME}" ]
60
64
  then
61
- printf " trying $D ... "
62
- if [ -d "$D" -a -r "${D}/odbc.ini" ]
65
+ printf " trying %s ... " "$D"
66
+ if [ -d "$D" ] && [ -r "${D}/odbc.ini" ]
63
67
  then
64
- printf $D >&3
68
+ echo "$D" >&3
65
69
  printf "OK"
66
70
  else
67
71
  printf "no"
68
72
  fi
69
73
  printf "\n"
70
74
  fi
71
- done
72
- done
75
+ done
76
+ done
73
77
  fi
78
+ exec 3>&-
74
79
 
75
- ODBC_DIR=$(cat ${INI_DIRNAME}) && rm ${INI_DIRNAME}
80
+ ODBC_DIR=$(cat "${INI_DIRNAME}") && rm "${INI_DIRNAME}"
76
81
 
77
- if [ -z "${ODBC_DIR}" -a -z "${OVER_DIR}" ]
82
+ if [ -z "${ODBC_DIR}" ] && [ -z "${OVER_DIR}" ]
78
83
  then
79
- echo "$(basename $0): problem: no potential directory strings in \"$(command -v isql)\""
80
- echo "$(basename $0): advice: use \"osql -I DIR\" where DIR unixODBC\'s install prefix e.g. /usr/local"
84
+ echo "$(basename "$0"): problem: no potential directory strings in \"$(command -v isql)\""
85
+ echo "$(basename "$0"): advice: use \"osql -I DIR\" where DIR unixODBC\'s install prefix e.g. /usr/local"
81
86
  echo "isql strings are:"
82
- strings ${ISQL} | grep ^/ | sed 's/^/+ /'
87
+ strings "${ISQL}" | grep ^/ | sed 's/^/+ /'
83
88
  #xit 1
84
89
  fi
85
90
 
@@ -97,7 +102,7 @@ then
97
102
  then
98
103
  ODBC_DIR=${OVER_DIR}
99
104
  else
100
- echo "$(basename $0): error: \"${OVER_DIR}\" is not a directory"
105
+ echo "$(basename "$0"): error: \"${OVER_DIR}\" is not a directory"
101
106
  exit 1
102
107
  fi
103
108
  fi
@@ -106,9 +111,9 @@ fi
106
111
  echo 'checking odbc.ini files'
107
112
  for F in "${HOME}/.odbc.ini" "${ODBC_DIR}/odbc.ini"
108
113
  do
109
- if [ ! -d "$(dirname $F)" ]
114
+ if [ ! -d "$(dirname "$F")" ]
110
115
  then
111
- echo "warning: $(dirname $F) is not a directory"
116
+ echo "warning: $(dirname "$F") is not a directory"
112
117
  continue
113
118
  fi
114
119
 
@@ -120,7 +125,7 @@ do
120
125
  continue
121
126
  fi
122
127
 
123
- grep -F "[${DSN}]" $F > /dev/null
128
+ grep -F "[${DSN}]" "$F" > /dev/null
124
129
 
125
130
  if [ $? -eq 0 ]
126
131
  then
@@ -134,14 +139,14 @@ done
134
139
 
135
140
  if [ -z "${ODBC_INI}" ]
136
141
  then
137
- echo "$(basename $0): error: unable to locate ${DSN} in any odbc.ini"
142
+ echo "$(basename "$0"): error: unable to locate ${DSN} in any odbc.ini"
138
143
  exit 1
139
144
  fi
140
145
 
141
146
  # Report finding of server entry
142
147
  echo found this section:
143
148
  SED_CMD="/^\[${DSN}\]/,/^[[:space:]]*$/ { s/^/ /; p; }"
144
- sed -ne "${SED_CMD}" ${ODBC_INI}
149
+ sed -ne "${SED_CMD}" "${ODBC_INI}"
145
150
 
146
151
  #
147
152
  # Examine server entry in odbc.ini
@@ -151,28 +156,28 @@ sed -ne "${SED_CMD}" ${ODBC_INI}
151
156
  for D in "${DSN}" 'default'
152
157
  do
153
158
  echo "looking for driver for DSN [$D] in ${ODBC_INI}"
154
- grep "$D" ${ODBC_INI} > /dev/null
159
+ grep "$D" "${ODBC_INI}" > /dev/null
155
160
  if [ $? -eq 0 ]
156
161
  then
157
162
  CMD="/^\[$D\]/,/^[[:space:]]*$/ { s/^/ /; p; }"
158
- DRIVER_LINE=$(sed -ne "${CMD}" ${ODBC_INI} \
163
+ DRIVER_LINE=$(sed -ne "${CMD}" "${ODBC_INI}" \
159
164
  | grep -Ei '^[[:space:]]*driver[[:space:]]*=')
160
165
  if [ -z "${DRIVER_LINE}" ]
161
166
  then
162
- echo " no driver mentioned for [$D] in $(basename ${ODBC_INI})"
167
+ echo " no driver mentioned for [$D] in $(basename "${ODBC_INI}")"
163
168
  continue
164
169
  fi
165
170
 
166
171
  echo " found driver line: \"${DRIVER_LINE}\""
167
- DRIVER=$(echo ${DRIVER_LINE} \
172
+ DRIVER=$(echo "${DRIVER_LINE}" \
168
173
  | awk -F ' *= *' '{print $2}' \
169
174
  | sed 's/[[:space:]][[:space:]]*//g')
170
175
  if [ "${DRIVER}" ]
171
176
  then
172
- echo " driver \"${DRIVER}\" found for [$D] in $(basename ${ODBC_INI})"
177
+ echo " driver \"${DRIVER}\" found for [$D] in $(basename "${ODBC_INI}")"
173
178
  break
174
179
  else
175
- echo " driver line for [$D] incomplete in $(basename ${ODBC_INI})"
180
+ echo " driver line for [$D] incomplete in $(basename "${ODBC_INI}")"
176
181
  continue
177
182
  fi
178
183
  fi
@@ -180,13 +185,13 @@ done
180
185
 
181
186
  if [ -z "${DRIVER}" ]
182
187
  then
183
- echo "$(basename $0): error: no driver found for [${DSN}] in $(basename ${ODBC_INI})"
188
+ echo "$(basename "$0"): error: no driver found for [${DSN}] in $(basename "${ODBC_INI}")"
184
189
  exit 1
185
190
  fi
186
191
 
187
192
  # get filename of driver
188
- echo found driver named \"${DRIVER}\"
189
- if [ -d "${DRIVER}" -o ! -x "${DRIVER}" ]
193
+ echo "found driver named \"${DRIVER}\""
194
+ if [ -d "${DRIVER}" ] || [ ! -x "${DRIVER}" ]
190
195
  then
191
196
  # not a filename, look it up
192
197
  DRIVERNAME=${DRIVER}
@@ -194,39 +199,39 @@ then
194
199
  echo "\"${DRIVERNAME}\" is not an executable file"
195
200
  echo "looking for entry named [${DRIVERNAME}] in ${ODBC_INST}"
196
201
 
197
- grep "${DRIVERNAME}" ${ODBC_INST} > /dev/null
202
+ grep "${DRIVERNAME}" "${ODBC_INST}" > /dev/null
198
203
  if [ $? -ne 0 ]
199
204
  then
200
205
  if [ $? -eq 1 ]
201
206
  then
202
- echo "$(basename $0): error: no driver entry [${DRIVERNAME}] in ${ODBC_INST}"
207
+ echo "$(basename "$0"): error: no driver entry [${DRIVERNAME}] in ${ODBC_INST}"
203
208
  fi
204
209
  exit 1;
205
210
  fi
206
211
 
207
212
  CMD="/^\[${DRIVERNAME}\]/,/^[[:space:]]*$/ { s/^/ /; p; }"
208
- DRIVER_LINE=$(sed -ne "${CMD}" ${ODBC_INST} \
213
+ DRIVER_LINE=$(sed -ne "${CMD}" "${ODBC_INST}" \
209
214
  | grep -Ei '^[[:space:]]*driver[[:space:]]*=')
210
215
  if [ -z "${DRIVER_LINE}" ]
211
216
  then
212
- echo "$(basename $0): no driver mentioned for [${DRIVERNAME}] in $(basename ${ODBC_INST})"
217
+ echo "$(basename "$0"): no driver mentioned for [${DRIVERNAME}] in $(basename "${ODBC_INST}")"
213
218
  exit 1
214
219
  fi
215
220
 
216
221
  echo " found driver line: \"${DRIVER_LINE}\""
217
- DRIVER=$(echo ${DRIVER_LINE} | awk -F ' *= *' '{print $2}')
222
+ DRIVER=$(echo "${DRIVER_LINE}" | awk -F ' *= *' '{print $2}')
218
223
  if [ -z "${DRIVER}" ]
219
224
  then
220
- echo "$(basename $0): driver line incomplete for [${DRIVERNAME}] in $(basename ${ODBC_INST})"
225
+ echo "$(basename "$0"): driver line incomplete for [${DRIVERNAME}] in $(basename "${ODBC_INST}")"
221
226
  exit 1
222
227
  fi
223
228
 
224
- echo " found driver ${DRIVER} for [${DRIVERNAME}] in $(basename ${ODBC_INST})"
229
+ echo " found driver ${DRIVER} for [${DRIVERNAME}] in $(basename "${ODBC_INST}")"
225
230
  fi
226
231
 
227
232
  if [ -z "${DRIVER}" ]
228
233
  then
229
- echo $(basename $0): 'error: sorry, failed sanity check: ${DRIVER} is null'
234
+ echo "$(basename "$0"): error: sorry, failed sanity check: \${DRIVER} is null"
230
235
  exit 1
231
236
  fi
232
237
 
@@ -235,30 +240,30 @@ then
235
240
  echo "${DRIVER} is an executable file"
236
241
  else
237
242
  echo "${DRIVER} is not an executable file"
238
- echo "$(basename $0): error: no driver found for ${DSN}"
243
+ echo "$(basename "$0"): error: no driver found for ${DSN}"
239
244
  exit 1
240
245
  fi
241
246
 
242
247
  # find the server/servername
243
- SERVER_LINE=$(sed -ne "${SED_CMD}" ${ODBC_INI} \
248
+ SERVER_LINE=$(sed -ne "${SED_CMD}" "${ODBC_INI}" \
244
249
  | grep -Ei '^[[:space:]]*server(name)*[[:space:]]*=')
245
250
 
246
- ATTRIBUTE=$(echo ${SERVER_LINE} | awk -F' *= *' '{print $1}')
251
+ ATTRIBUTE=$(echo "${SERVER_LINE}" | awk -F' *= *' '{print $1}')
247
252
 
248
253
  if [ -z "${ATTRIBUTE}" ]
249
254
  then
250
- echo "$(basename $0): neither \"Server\" nor \"Servername\" found for [${DSN}] in $(basename ${ODBC_INI})"
255
+ echo "$(basename "$0"): neither \"Server\" nor \"Servername\" found for [${DSN}] in $(basename "${ODBC_INI}")"
251
256
  exit 1
252
257
  fi
253
258
 
254
- echo ${SERVER_LINE} | grep -i servername >/dev/null
259
+ echo "${SERVER_LINE}" | grep -i servername >/dev/null
255
260
 
256
261
  #
257
262
  # Find the server's hostname
258
263
  #
259
264
  if [ $? -eq 0 ] # ODBC-Combined
260
265
  then
261
- TDS_SERVER=$(echo ${SERVER_LINE} | awk -F ' *= *' '{print $2}')
266
+ TDS_SERVER=$(echo "${SERVER_LINE}" | awk -F ' *= *' '{print $2}')
262
267
  echo 'Using ODBC-Combined strategy'
263
268
  echo "DSN [${DSN}] has servername \"${TDS_SERVER}\" (from ${ODBC_INI})"
264
269
  if [ -z "${TDS_SERVER}" ]
@@ -271,7 +276,7 @@ then
271
276
  FREETDS_DIR=$(tsql -C | grep 'freetds.conf directory' | awk -F: '{print $2}' | sed 's/^ *//')
272
277
  if [ -z "${FREETDS_DIR}" ]
273
278
  then
274
- echo "$(basename $0): error: unable to locate directory for freetds.conf using \"$(command -v tsql)\""
279
+ echo "$(basename "$0"): error: unable to locate directory for freetds.conf using \"$(command -v tsql)\""
275
280
  exit 1
276
281
  fi
277
282
 
@@ -279,27 +284,27 @@ then
279
284
  do
280
285
  if [ -r "$F" ]
281
286
  then
282
- echo $F is a readable file
287
+ echo "$F is a readable file"
283
288
  else
284
- echo cannot read \"$F\"
289
+ echo "cannot read \"$F\""
285
290
  continue
286
291
  fi
287
292
 
288
293
  echo "looking for [${TDS_SERVER}] in $F"
289
- grep -F "[${TDS_SERVER}]" $F > /dev/null
294
+ grep -F "[${TDS_SERVER}]" "$F" > /dev/null
290
295
 
291
296
  if [ $? -eq 0 ]
292
297
  then
293
298
  FREETDS_CONF=$F
294
299
  break
295
300
  else
296
- echo "[${TDS_SERVER}]" not found in $F
301
+ echo "[${TDS_SERVER}] not found in $F"
297
302
  fi
298
303
  done
299
304
 
300
305
  if [ -z "${FREETDS_CONF}" ]
301
306
  then
302
- echo "$(basename $0): error: unable to locate ${TDS_SERVER} in any freetds.conf"
307
+ echo "$(basename "$0"): error: unable to locate ${TDS_SERVER} in any freetds.conf"
303
308
  exit 1
304
309
  fi
305
310
 
@@ -307,29 +312,29 @@ then
307
312
 
308
313
  echo found this section:
309
314
  SED_CMD="/^\[${TDS_SERVER}\]/,/^[[:space:]]*$/ { s/^/ /; p; }"
310
- sed -ne "${SED_CMD}" ${FREETDS_CONF}
315
+ sed -ne "${SED_CMD}" "${FREETDS_CONF}"
311
316
 
312
- SERVER_LINE=$(sed -ne "${SED_CMD}" ${FREETDS_CONF} \
317
+ SERVER_LINE=$(sed -ne "${SED_CMD}" "${FREETDS_CONF}" \
313
318
  | grep -Ei '^[[:space:]]*host[[:space:]]*=')
314
319
 
315
320
  # No character class support in mawk,
316
321
  # cf. "Mawk does not support Posix character classes in expressions"
317
322
  # https://bugs.launchpad.net/ubuntu/+source/mawk/+bug/69724
318
- HOST=$(echo ${SERVER_LINE} | awk -F' *= *' '{print $2}')
323
+ HOST=$(echo "${SERVER_LINE}" | awk -F' *= *' '{print $2}')
319
324
 
320
325
  if [ -z "${HOST}" ]
321
326
  then
322
- echo "$(basename $0): no \"host\" entry found for [${TDS_SERVER}] in $(basename ${FREETDS_CONF})"
327
+ echo "$(basename "$0"): no \"host\" entry found for [${TDS_SERVER}] in $(basename "${FREETDS_CONF}")"
323
328
  exit 1
324
329
  fi
325
330
 
326
331
  else # odbc.ini contains a "server", a DNS host
327
- HOST=$(echo ${SERVER_LINE} | awk -F ' *= *' '{print $2}')
332
+ HOST=$(echo "${SERVER_LINE}" | awk -F ' *= *' '{print $2}')
328
333
  echo "\"${ATTRIBUTE}\" found, not using freetds.conf"
329
334
  echo "${ATTRIBUTE} is \"${HOST}\""
330
335
  if [ -z "${HOST}" ]
331
336
  then
332
- echo "$(basename $0): no value found for \"${ATTRIBUTE}\" entry in $(basename ${ODBC_INI})"
337
+ echo "$(basename "$0"): no value found for \"${ATTRIBUTE}\" entry in $(basename "${ODBC_INI}")"
333
338
  exit 1
334
339
  fi
335
340
  fi
@@ -337,14 +342,14 @@ fi
337
342
  # If the "host" is an ip address, look up the name, for neatness, e.g.
338
343
  ## $ host 10.81.36.39
339
344
  ## 39.36.81.10.IN-ADDR.ARPA domain name pointer ntc5003.eg.com
340
- if [ "${HOST}" = "$(echo ${HOST} | sed 's/[^.0-9]*//')" ]
345
+ if [ "${HOST}" = "$(echo "${HOST}" | sed 's/[^.0-9]*//')" ]
341
346
  then
342
347
  ADDRESS=${HOST}
343
- echo 'looking up hostname for ip address' ${ADDRESS}
344
- HOST=$(host ${HOST} | awk '/domain/ {print $5}' | sed 's/\.$//')
348
+ echo "looking up hostname for ip address ${ADDRESS}"
349
+ HOST=$(host "${HOST}" | awk '/domain/ {print $5}' | sed 's/\.$//')
345
350
  if [ -z "${HOST}" ]
346
351
  then
347
- echo "$(basename $0): warning: no DNS hostname found for \"${ADDRESS}\""
352
+ echo "$(basename "$0"): warning: no DNS hostname found for \"${ADDRESS}\""
348
353
  HOST=${ADDRESS} # restore host address string
349
354
  fi
350
355
  fi
@@ -352,11 +357,11 @@ fi
352
357
  # Now we have a DNS hostname for the server in HOST
353
358
  if [ "${HOST}" != "${ADDRESS}" ]
354
359
  then
355
- ADDRESS=$(host ${HOST} | awk '/has address/ {print $4}' | head -1)
360
+ ADDRESS=$(host "${HOST}" | awk '/has address/ {print $4}' | head -1)
356
361
  fi
357
362
  if [ -z "${ADDRESS}" ]
358
363
  then
359
- echo "$(basename $0): no IP address found for \"${HOST}\""
364
+ echo "$(basename "$0"): no IP address found for \"${HOST}\""
360
365
  exit 1
361
366
  fi
362
367
 
@@ -366,23 +371,23 @@ fi
366
371
 
367
372
  printf "\n"
368
373
  printf "Configuration looks OK. Connection details:\n\n"
369
- printf "%22s:\t%-30s\n" DSN ${DSN}
374
+ printf "%22s:\t%-30s\n" DSN "${DSN}"
370
375
  printf "%22s:\t%-30s\n" odbc.ini "${ODBC_INI}"
371
- printf "%22s:\t%-30s\n" Driver ${DRIVER}
372
- printf "%22s:\t%-30s\n" "Server hostname" ${HOST}
373
- printf "%22s:\t%-30s\n" Address ${ADDRESS}
376
+ printf "%22s:\t%-30s\n" Driver "${DRIVER}"
377
+ printf "%22s:\t%-30s\n" "Server hostname" "${HOST}"
378
+ printf "%22s:\t%-30s\n" Address "${ADDRESS}"
374
379
  printf "\n"
375
380
 
376
- echo Attempting connection as ${USERNAME} ...
381
+ echo "Attempting connection as ${USERNAME} ..."
377
382
 
378
383
  if [ -z "${TDSDUMP}" ]
379
- then
380
- TDSDUMP_AUTO="/tmp/$(basename $0).dump.$$"
384
+ then
385
+ TDSDUMP_AUTO="/tmp/$(basename "$0").dump.$$"
381
386
  export TDSDUMP=${TDSDUMP_AUTO}
382
387
  fi
383
388
 
384
- ( set -x; isql ${DSN} ${USERNAME} ${PASSWORD} -v ) \
385
- || sed -ne 's/Connecting/FAILED &/p' ${TDSDUMP}
389
+ ( set -x; isql "${DSN}" "${USERNAME}" "${PASSWORD}" -v ) \
390
+ || sed -ne 's/Connecting/FAILED &/p' "${TDSDUMP}"
386
391
 
387
- test "${TDSDUMP_AUTO}" && rm -f ${TDSDUMP_AUTO}
392
+ test "${TDSDUMP_AUTO}" && rm -f "${TDSDUMP_AUTO}"
388
393