0

MySQLdb.connect()既に呼び出された後、MySQLdb 接続オブジェクトからホスト、ユーザー名、パスワードなどの情報にアクセスする方法はありますか?

4

1 に答える 1

0

接続パラメータを取得する方法ではないようです。または、推奨できる少なくとも 1 つ。

私はオブジェクトのすべての変数とメソッドを見てきました (ipython では、接続を持つオブジェクトに対してdictを呼び出すことができます (例: conn. dict ))。与えられたリストは次のようなものです:

{'_server_version': (5, 6),
 '_transactional': 8192L,
 'cursorclass': MySQLdb.cursors.Cursor,
 'encoders': {bool: <function MySQLdb.converters.Bool2Str>,
  instance: <function MySQLdb.converters.Instance2Str>,
  float: <function MySQLdb.converters.Float2Str>,
  int: <function MySQLdb.converters.Thing2Str>,
  list: <function MySQLdb.converters.quote_tuple>,
  long: <function MySQLdb.converters.Thing2Str>,
  dict: <function _mysql.escape_dict>,
  NoneType: <function MySQLdb.converters.None2NULL>,
  set: <function MySQLdb.converters.Set2Str>,
  str: <function MySQLdb.connections.string_literal>,
  tuple: <function MySQLdb.converters.quote_tuple>,
  object: <function MySQLdb.converters.Instance2Str>,
  unicode: <function MySQLdb.connections.unicode_literal>,
  datetime.timedelta: <function MySQLdb.times.DateTimeDelta2literal>,
  datetime.datetime: <function MySQLdb.times.DateTime2literal>,
  array.array: <function MySQLdb.converters.array2Str>},
 'messages': [],
 'string_decoder': <function MySQLdb.connections.string_decoder>,
 'unicode_literal': <function MySQLdb.connections.unicode_literal>}

コードをナビゲートすることにより、「connect」は、既存の _mysql.connection クラスを拡張するクラス Connection のインスタンスを返します。ここでは、接続objで直接呼び出すことができる「get_host_info」などの関数を見つけることができますが、探していると思われるものを提供していないようです。

そのデータを取得する方法は、接続とそれに指定されたパラメーターを含む新しいクラスを作成することです。

お役に立てば幸いです、ジェマ

于 2014-10-24T14:43:10.730 に答える