国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

一個小巧的MySQL Shell

2024-07-24 12:54:55
字體:
來源:轉載
供稿:網友

#!/usr/bin/python
# -*- coding: cp936 -*-

#################################
#   written by caocao           #
#   [email protected]          #
#   http://nethermit.yeah.net   #
#################################

import sys, string, os
from types import *
import mysqldb

print "written by caocao"
print "[email protected]"
print "http://nethermit.yeah.net"
print

def iif(expression, whentrue, whenfalse):
 if expression:
  return whentrue
 else:
  return whenfalse

class mysqltest:
 def __init__(self, host="localhost", user="root", passwd="", db=""):
  self.connection=none
  self.host=host
  self.user=user
  self.passwd=passwd
  self.db=db
  self.result=none

  print "-"*40
  print "mysql shell v 1.0"
  print "usage: python mysql.shell.py [host] [user] [passwd(% is empty)] [db]"
  print "connect..."
  try:
   self.connection=mysqldb.connect(host=self.host, user=self.user, passwd=self.passwd, db=self.db)
  except:
   print "can't connect to mysql server./nplease make sure your username or password is right."
   sys.exit(1)
  print "-"*40
  print self.printcomment("connection", "get_server_info")
  print self.printcomment("connection", "get_host_info")
  print self.printcomment("connection", "get_proto_info")
  print self.printcomment("connection", "info")
  print self.printcomment("connection", "character_set_name")
  print self.printcomment("connection", "thread_id")
  print self.printcomment("connection", "stat")

 def __del__(self):
  if self.connection!=none:
   self.connection.close()
  print "-"*40
  print "quit..."

 def printcomment(self, instance, function):
  return "%s = %s" % (string.rjust(function, 18), eval("self."+instance+"."+function+"()"))

 def printall(self):
  output, row="", self.result.fetch_row(0)
  for i in range(self.result.num_fields()):
   output+=repr(self.result.describe()[i][0])+"/n"
  for i in range(self.result.num_rows()):
   for j in range(self.result.num_fields()):
    output+=iif(type(row[i][j]) is stringtype, row[i][j], repr(row[i][j]))+"/n"
  return output

 def runsql(self, querystring="show databases"):
  print "-"*40
  try:
   self.connection.query(querystring)
  except:
   print "can't run sql."
  else:
   self.result=self.connection.store_result()
   print self.printcomment("connection", "field_count")
   print self.printcomment("connection", "affected_rows")
   print self.printcomment("connection", "insert_id")
   print self.printcomment("result", "num_fields")
   print self.printcomment("result", "num_rows")
   print self.printcomment("result", "field_flags")
   print "-"*40
   print self.printall()

if __name__=="__main__":
 argarray=sys.argv
 del argarray[0]
 test=eval(("mysqltest(/"%s/")" % "/",/"".join(argarray)).replace("%", ""))
 while true:
  try:
   command=string.strip(raw_input("ps mysql>"), " ")
   commandlow=string.lower(command)
  except eoferror:
   break
  else:
   if commandlow=="exit" or commandlow=="quit":
    break
   elif commandlow=="":
    continue
   else:
    test.runsql(command)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陵水| 巴东县| 湘西| 天全县| 若尔盖县| 东方市| 肇东市| 如东县| 比如县| 尤溪县| 信阳市| 赤壁市| 乐昌市| 会泽县| 鹿泉市| 娱乐| 信丰县| 敦化市| 丹寨县| 什邡市| 和顺县| 郧西县| 荃湾区| 铁岭市| 上犹县| 白玉县| 柞水县| 曲阳县| 多伦县| 乐都县| 九龙城区| 瑞丽市| 林周县| 呼伦贝尔市| 凌海市| 大同县| 寿光市| 禹州市| 驻马店市| 盐亭县| 泰兴市|