Size: 1045
Comment:
|
Size: 2003
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 24: | Line 24: |
== Zoomq 快速重构 == * 从简单之处进行处理 {{{#!python # file sqlanalyzer.py #/** # @brief 把一段sql中的数据字段名还有字段类型长度等给抽取出来然后写在一个空的txt或者tex格式的文本里 # @version 0.1 stephen chan <[email protected]> # @version 0.2 Zoom.Quiet debug # @author Zoom Quiet # @attention Released under GNU Lesser GPL library license # @par # @return # @sa #*/ import sys, os #Write DD Document from SQL,Small Script Just test. fr="JGGZ_Table_script.sql" #读文件1内容 fw="JGGZ_Table_script_dd.txt"#写入文件2,文件2是自己创建的,初为空 exp = "" i=0 for line in open(fr).readlines(): i+=1 if " "==line[:2] and "CONSTRAINT" not in line and "REFERENCES" not in line and "PRIMARY" not in line: print line exp+= line else: print i,".",line open(fw,"w").write(exp) }}} |
07-01-29.非常非常初级的小程序--SQL分析
stephen chan <[email protected]>
- 是这样的,我想用python把一段sql中的数据字段名还有字段类型长度等给抽取出来然后写在一个空的txt或者tex格式的文本里,可是程序有错误,感觉不是我想要的,首先我想把sql文本中没有含有括号"("和")"的整行去除,抽取出"("")"内的数据,然后进行数据处理,用limodou的ulipad不好调试,郁闷死我了,可否帮我看看这段程序错在哪?非常短
1 #Write DD Document from SQL,Small Script Just test.
2 file1r=open("E:\JGGZ_Table_script.sql","r") #读文件1内容
3 file1w=open("E:\JGGZ_Table_script_dd.tex","w") #写入文件2,文件2是自己创建的,初为空
4 i=0
5 for line in file1r.readlines():
6 if not(line.find("(") | line.find(")")):
7 line=''
8 else:
9 pass
10 i+=1
11 print i,
12 print ".",
13 print line
14 file1r.close()
15 file1w.close()
- attachment:JGGZ_Table_script.sql
Zoomq 快速重构
- 从简单之处进行处理
1 # file sqlanalyzer.py
2
3 #/**
4
5 # @brief 把一段sql中的数据字段名还有字段类型长度等给抽取出来然后写在一个空的txt或者tex格式的文本里
6
7 # @version 0.1 stephen chan <[email protected]>
8
9 # @version 0.2 Zoom.Quiet debug
10
11 # @author Zoom Quiet
12
13 # @attention Released under GNU Lesser GPL library license
14
15 # @par
16
17 # @return
18
19 # @sa
20
21 #*/
22
23
24
25 import sys, os
26
27 #Write DD Document from SQL,Small Script Just test.
28 fr="JGGZ_Table_script.sql" #读文件1内容
29 fw="JGGZ_Table_script_dd.txt"#写入文件2,文件2是自己创建的,初为空
30 exp = ""
31 i=0
32 for line in open(fr).readlines():
33 i+=1
34 if " "==line[:2] and "CONSTRAINT" not in line and "REFERENCES" not in line and "PRIMARY" not in line:
35 print line
36 exp+= line
37 else:
38 print i,".",line
39 open(fw,"w").write(exp)