MySQL は MyODBC プログラムで ODBC 機能を提供します。
MyODBC は Windows95 と NT の 32ビット ODBC (2.50) level 0 ドライバです。我々は誰かがこれを Windows 3.x へ移植するのを希望します。
MyODBC は以下でテストされました: Access, Admndemo.exe, C++-Builder, Centura Team Developer (formerly Gupta SQL/Windows), ColdFusion (on Solaris and NT with svc pack 5), Crystal Reports, DataJunction, Delphi, ERwin, Excel, iHTML, FileMaker Pro, FoxPro, Notes 4.5/4.6, SBSS, Perl DBD-ODBC, Paradox, Powerbuilder, Powerdesigner 32 bit, VC++ and Visual Basic.
MyODBC で動作する他のアプリケーションについても知っているなら、 myodbc@lists.mysql.com までメールをください!
多くのプログラムが MyODBC で動作します。これらは我々自身がテストしたか、 または何人かの他のユーザから動作するという確証を得たものです:
BLOB
項目を OLE OBJECTS
と認識します。
もし MEMO
項目を代わりに使用したいなら、 ALTER TABLE
を使って、
TEXT
型に項を変更しなくてはなりません。
DATE
項目をいつも正しく扱うことが出来ません。
もしこれらの問題があった場合、項目型を DATETIME
に変えてください。
"Query|SQLSpecific|Pass-Through"
を選択すれば
直すことが可能です。
VARCHAR
rather than ENUM
, as
it exports the latter in a manner that causes MySQL grief.
CONCAT()
関数を使用し、文字として select してみてください。例えば:
select CONCAT(rise_time), CONCAT(set_time) from sunrise_sunset;この方法で文字として返ってきた値を、Excel97 で時間として扱うようにすべきです。 この例の
CONCAT()
の目的は、項目の型が文字列であると ODBC をだますことです。
CONCAT()
がなければ、ODBC は項目の型が日付とわかるので、
Excel が今度はそれを理解できなくなります。
これは Excel のバグです。なぜなら文字を自動で日付に直すのですから。
これは単にテキストファイルの情報を扱う場合ならばいいのですが、
各項目の型を知らせる ODBC 接続の情報を扱う場合は、とても愚かな方法です。
fReg:= TRegistry.Create; fReg.OpenKey('\Software\ODBC\ODBC.INI\DocumentsFab', True); fReg.WriteString('Database', 'Documents'); fReg.WriteString('Description', ' '); fReg.WriteString('Driver', 'C:\WINNT\System32\myodbc.dll'); fReg.WriteString('Flag', '1'); fReg.WriteString('Password', ''); fReg.WriteString('Port', ' '); fReg.WriteString('Server', 'xmark'); fReg.WriteString('User', 'winuser'); fReg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources', True); fReg.WriteString('DocumentsFab', 'MySQL'); fReg.CloseKey; fReg.Free; Memo1.Lines.Add('DATABASE NAME='); Memo1.Lines.Add('USER NAME='); Memo1.Lines.Add('ODBC DSN=DocumentsFab'); Memo1.Lines.Add('OPEN MODE=READ/WRITE'); Memo1.Lines.Add('BATCH COUNT=200'); Memo1.Lines.Add('LANGDRIVER='); Memo1.Lines.Add('MAX ROWS=-1'); Memo1.Lines.Add('SCHEMA CACHE DIR='); Memo1.Lines.Add('SCHEMA CACHE SIZE=8'); Memo1.Lines.Add('SCHEMA CACHE TIME=-1'); Memo1.Lines.Add('SQLPASSTHRU MODE=SHARED AUTOCOMMIT'); Memo1.Lines.Add('SQLQRYMODE='); Memo1.Lines.Add('ENABLE SCHEMA CACHE=FALSE'); Memo1.Lines.Add('ENABLE BCD=FALSE'); Memo1.Lines.Add('ROWSET SIZE=20'); Memo1.Lines.Add('BLOBS TO CACHE=64'); Memo1.Lines.Add('BLOB SIZE=32'); AliasEditor.Add('DocumentsFab','MySQL',Memo1.Lines);
Windows95 上のサーバ名の記述には3つの可能性があります:
ip hostname例えば:
194.216.84.21 my
``ODBC setup''を埋める方法の例:
Windows DSN name: test Description: This is my test database MySql Database: test Server: 194.216.84.21 User: monty Password: my_password Port:
Windows DSN name
フィールドの値は、あなたのwindows ODBC setup における
一意の名前です。
ODBC setup 画面で、Server
, User
, Password
, Port
フィールドを設定する必要はありません。
しかし、ここで設定をすると、後でサーバーに接続する際に、設定した値がデフォルト値として使用されます。
使用時に値を変更するオプションはあります。
ポート番号が設定されていないなら、デフォルトポート (3306) が使用されます。
もしオプションを Read options from C:\my.cnf
にすると,
client
と odbc
グループは `C:\my.cnf' ファイルから読まれます。
mysql_options()
で使用できる全てのオプションが利用可能です。
「20.4.37 mysql_options()
」節参照.
AUTO_INCREMENT
項目の値を ODBC で得る方法
共通の問題は、INSERT
で自動的に生成されるIDの値を得ることです。
ODBCでは、以下のようにします( 例中の auto
が AUTO_INCREMENT
項目です):
INSERT INTO foo (auto,text) VALUES(NULL,'text'); SELECT LAST_INSERT_ID();
もしくは、他のテーブルにIDを挿入するだけなら以下のようにします:
INSERT INTO foo (auto,text) VALUES(NULL,'text'); INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text');
いくつかのODBCアプリケーション(少なくともDelphiとAccess)は、 新しく挿入された行を見つけるのに、以下のクエリが使用できます:
SELECT * FROM tbl_name WHERE auto IS NULL;
もし問題にあたった場合、ODBC マネージャのログファイル(ODBCADMIN からリクエストしたときのログ) と MyODBC のログがほしいです。
これはいかなる問題にも解決の糸口になるはずです。
MyODBC ログを取るには、 MyODBC connect/configure 画面の
'Trace MyODBC' オプションをチェックします。
ログは `C:\myodbc.log' に書き出されます。
このオプションを使用するに当たり、 MYSQL2.DLL
ではなく、 MYSQL.DLL
を使用しなくてはなりません!
Check the queries that MyODBC sends to the MySQL server; You
should be able to find this by searching after the string
>mysql_real_query
in the `myodbc.log' file.
You should also try duplicating the queries in the mysql
monitor
or admndemo
to find out if the error is MyODBC or MySQL.
If you find out something is wrong, please only send the relevant rows (max 40 rows) to the myodbc@lists.mysql.com. Please never send the whole MyODBC or ODBC log file !
If you are unable to find out what's wrong, the last option is to to make a archive (tar or zip) that contains a MyODBC log file, the ODBC log file and a README file that explains the problem. You can send this to ftp://www.mysql.com/pub/mysql/secret. Only we at TCX will have access to the files you upload and we will be very discrete with the data!
If you can create a program that also shows this problem, please upload this too!
If the program works with some other SQL server, you should make a ODBC log file where you do exactly the same thing in the other SQL server.
Remember that the more information you can supply to us, the more likely it is that we can fix the problem!
Go to the first, previous, next, last section, table of contents.