Skip to content

Commit

Permalink
添加查询数据库功能,删除php生成手册功能
Browse files Browse the repository at this point in the history
添加了查询mysql数据库功能,
删除了php生成手册功能
修复以前查询字段时密码为空不能查询的bug
修复以前调用php命令引号传'命令行无法执行的bug
  • Loading branch information
yangweijie committed Jun 26, 2013
1 parent 0b97011 commit 5ef3cf3
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 161 deletions.
18 changes: 10 additions & 8 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
[
{
"id": "tools",
"children":
[
[
{
"caption": "ThinkPHP",
"children":
[
[
{
"caption": "ThinkPHP delete opened folders' bom",
"id": "ThinkPHP del_bom",
Expand All @@ -32,15 +32,17 @@
"id": "ThinkPHP manual: build book",
"command": "update_thinkphp_manual"
},
{ "caption": "-" },
{
"caption": "ThinkPHP manual: build book with php",
"id": "ThinkPHP manual: build book with php",
"command": "update_thinkphp_manual_with_php"
"caption": "ThinkPHP choose database",
"id": "ThinkPHP choose database",
"command": "query_database",
"args": {"cmd" :"list_database"}
},
{ "caption": "-" },
{ "command": "open_file",
{ "command": "open_file",
"args": {"file": "${packages}/Thinkphp/php.sublime-completions"},
"caption": "Browse Complation - php", "mnemonic": "B"
"caption": "Browse Complation - php", "mnemonic": "B"
},
{
"command": "open_file",
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ Snippet提示
![视频: 用Sublime text2的Thinkphp插件 像zencoding)一样快速开发TP](http://v.youku.com/v_show/id_XNTA1NjE2MTM2.html)
查看函数说明文档
![查看函数说明文档](http://ww3.sinaimg.cn/mw1024/50075709jw1e5r7cp53hcj20n60brq57.jpg "查看函数说明文档")
mysql编辑器内简单查询
![效果图](http://ww2.sinaimg.cn/mw1024/50075709jw1e61cpyt7esj20vc0nbq7p.jpg "效果图")
1.在tools->ThinkPHP->ThinkPHP choose database来添加数据库和选择当前数据库
![选择数据库](http://ww2.sinaimg.cn/mw1024/50075709jw1e61cpzgtwpj20e304tmxg.jpg "选择数据库")

添加数据库选择"add database",后如下图:
![添加数据库](http://ww2.sinaimg.cn/mw1024/50075709jw1e61cpzwnbqj20j10hv0ul.jpg)

注意database里 0 的那个键不要删除,剪切板里会有要添加的模板,自己要么先删除只剩0,保存后。下次选添加进来,粘贴会有1的模板,自己替换下即可。以后会扩展支持sqlserver。

2.替换出来的查询页面里的"here is the sql to be queryed" 为要查询的sql,保存后就切换tab后就能显示结果了。这是bug。应为查询结果是用php写文件的。

##有问题反馈
在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流
Expand Down
127 changes: 100 additions & 27 deletions Thinkphp.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def show_cloums(self, arg):
for dirpath, dirnames, filenames in os.walk(dir[0]):
if(len(filenames)):
for filename in filenames:
if (filename == 'config.php'):
cfg_files.append([filename, dirpath + "/" + filename])
if filename == 'config.php' and dirpath.find('ThinkPHP') == -1:
cfg_files.append([filename, dirpath + os.sep + filename])
if(len(cfg_files)):
self.cfg_files = cfg_files
self.view.window().show_quick_panel(cfg_files, self.choose_conf)
Expand All @@ -219,7 +219,8 @@ def show_cloums(self, arg):

def choose_conf(self, arg):
config_file = self.cfg_files[arg][1]
command_text = "php '" + packages_path+"/command.php' 'show_colums_after_connected_from_file' '" + config_file + "' '" + self.table + "'"
command_text = 'php "' + packages_path + os.sep + 'command.php" "show_colums_after_connected_from_file" "' + config_file + '" ' + self.table + '"'
print command_text
cloums = os.popen(command_text)
data = json.loads(cloums.read())
if(data['status'] == 0):
Expand Down Expand Up @@ -288,6 +289,102 @@ def write(string):
sublime.status_message('must be a word')


class query_database(ThinkphpCommand, sublime_plugin.TextCommand):
def run(self, edit, cmd):
if cmd == 'list_database':
database = []
db_list = settings.get('database')
for i in db_list:
database.insert(int(i), db_list[i]['list_title'])
self.database = database
# print database
self.view.window().show_quick_panel(database, self.choose_database)

def choose_database(self, arg):
if arg == -1:
pass
else:
db_num = len(settings.get('database'))
if arg == 0:
setting_file = packages_path + os.sep + 'Thinkphp.sublime-settings'
new_key = '%d' % db_num
tpl = '"' + new_key + '":' + """{
"list_title":"test",
"DB_HOST": "localhost",
"DB_USER": "xxx",
"DB_PWD": "xxx",
"DB_NAME": "xx",
"DB_PREFIX": ""
}
"""
sublime.set_clipboard(tpl)
self.view.window().open_file(setting_file)
else:
fs_writer(packages_path + os.sep + 'current_database', arg)
window = sublime.active_window()
views = window.views()
view = None
for _view in views:
if _view.name() == 'thinkphp_database_queryer':
view = _view
break

if not view:
tpl = """+------------------------thinkphp_database_queryer-----------------------+
##########################################################################
here is the sql to be queryed
##########################################################################
here will show the result
"""
query_window = packages_path + os.sep + 'thinkphp_database_queryer'
fs_writer(query_window, tpl)
self.view.window().open_file(query_window)


class Thinkphp(sublime_plugin.EventListener):
def on_post_save(self, view):
content = view.substr(sublime.Region(0, view.size()))
print content
title = "thinkphp_database_queryer"
if content.find(title) and (content.find('# -*- coding: utf-8 -*-') == -1):
#get the db_config to connect database
current_database = packages_path + os.sep + 'current_database'
arg = fs_reader(current_database)
database = settings.get('database')
db = database[arg]
print db
seperator = """##########################################################################"""
query = content.split(seperator)
if len(query) == 3:
sql = query[1]
if sql == '':
sublime.status_message('Pls input correct sql')
else:
command_text = 'php "' + packages_path + os.sep + 'command.php" "query"'
thread = queryWithPhp(command_text)
thread.start()
ThreadProgress(thread, 'Is querying', 'Database query complated!')
else:
sublime.status_message('Error format queryer, pls close it the retry query')


class queryWithPhp(threading.Thread):
def __init__(self, command_text):
self.command_text = command_text
threading.Thread.__init__(self)

def run(self):
cloums = os.popen(self.command_text)
# print cloums.read()
data = cloums.read()
if data:
sublime.error_message(data)


class update_thinkphp_manual(ThinkphpCommand, sublime_plugin.TextCommand):
def run(self, edit):
manual_path = packages_path + os.sep + manual_dir + os.sep
Expand All @@ -296,15 +393,6 @@ def run(self, edit):
ThreadProgress(thread, 'Is making ThinkPHP manual', 'ThinkPHP manual generated!')


class update_thinkphp_manual_with_php(ThinkphpCommand, sublime_plugin.TextCommand):
def run(self, edit):
# self.update_manual_with_php()
command_text = "php -d 'extension=php_curl.dll' '" + packages_path + os.sep + "command.php' 'update_manual' '" + packages_path + os.sep + manual_dir + "' '" + api_root_url + "'"
thread = updateManualWithPhp(command_text)
thread.start()
ThreadProgress(thread, 'Is making ThinkPHP manual', 'ThinkPHP manual generated!')


class show_cloums_by_word(ThinkphpCommand, sublime_plugin.TextCommand):
def run(self, edit):
region = self.view.sel()[0]
Expand Down Expand Up @@ -367,21 +455,6 @@ def build(self, id, name, parent_dir=''):
write_tpl(name, content, parent_dir)


class updateManualWithPhp(threading.Thread):
def __init__(self, command_text):
self.command_text = command_text
threading.Thread.__init__(self)

def run(self):
cloums = os.popen(self.command_text)
# print cloums.read()
data = json.loads(cloums.read())
if data['status'] == 0:
sublime.message_dialog(data['info'])
else:
sublime.error_message(data['info'])


class ThreadProgress():
"""
Animates an indicator, [= ], in the status area while a thread runs
Expand Down
Binary file removed Thinkphp.pyc
Binary file not shown.
6 changes: 1 addition & 5 deletions Thinkphp.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
"caption": "view table design",
"command": "show_cloums_by_word"
Expand All @@ -15,10 +15,6 @@
"caption": "ThinkPHP manual: build book",
"command": "update_thinkphp_manual"
},
{
"caption": "ThinkPHP manual: build book with php",
"command": "update_thinkphp_manual_with_php"
},
{
"caption": "ThinkPHP manual: search",
"command": "search_thinkphp_manual"
Expand Down
28 changes: 26 additions & 2 deletions Thinkphp.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
{
"manual_dir":"manual",//手册保存目录
"api_url":"http://www.thinkphp.cn/api"//手册api地址
"manual_dir":"manual",
"api_url":"http://www.thinkphp.cn/api",
"current_database" :"" ,
"database" : {
"0":{
"list_title":"add_database"
},
"1":{
"list_title":"fujian",
"DB_HOST":"192.168.1.200",
"DB_USER": "fujian",
"DB_PWD": "fujian",
"DB_NAME": "fujian",
"DB_PREFIX": "sister_",
"DB_PORT": "3306"
},
"2":{
"list_title":"local",
"DB_HOST": "localhost",
"DB_USER": "root",
"DB_PWD": "",
"DB_NAME": "mysql",
"DB_PREFIX": ""
}

}
}
Loading

0 comments on commit 5ef3cf3

Please sign in to comment.