数据库更新

This commit is contained in:
hoteas 2017-09-19 07:39:35 +00:00
parent 497d78ab4e
commit 24cf680d91
3 changed files with 53 additions and 72 deletions

79
.idea/workspace.xml generated
View File

@ -5,13 +5,6 @@
</component>
<component name="ChangeListManager">
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/ddsms" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/upload" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/ddsms/ddsms.go" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/upload/upload.go" />
<change type="DELETED" beforePath="$PROJECT_DIR$/config/config.json" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/config" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
</list>
<ignored path=".idea/dataSources.local.xml" />
@ -34,7 +27,7 @@
<file leaf-file-name="map.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<state relative-caret-position="748">
<caret line="49" column="0" lean-forward="false" selection-start-line="49" selection-start-column="0" selection-end-line="58" selection-end-column="1" />
<folding>
<element signature="e#16#72#0" expanded="true" />
@ -46,7 +39,7 @@
<file leaf-file-name="func.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/func.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-255">
<state relative-caret-position="204">
<caret line="21" column="5" lean-forward="false" selection-start-line="21" selection-start-column="5" selection-end-line="21" selection-end-column="5" />
<folding />
</state>
@ -77,7 +70,7 @@
<entry file="file://$PROJECT_DIR$/dri/ddsms/ddsms.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1292">
<caret line="83" column="22" lean-forward="true" selection-start-line="83" selection-start-column="22" selection-end-line="83" selection-end-column="22" />
<caret line="83" column="22" lean-forward="false" selection-start-line="83" selection-start-column="22" selection-end-line="83" selection-end-column="22" />
<folding />
</state>
</provider>
@ -86,8 +79,8 @@
<file leaf-file-name="upload.go" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/dri/upload/upload.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1173">
<caret line="69" column="1" lean-forward="true" selection-start-line="69" selection-start-column="1" selection-end-line="69" selection-end-column="1" />
<state relative-caret-position="510">
<caret line="30" column="5" lean-forward="false" selection-start-line="30" selection-start-column="5" selection-end-line="30" selection-end-column="5" />
<folding>
<element signature="e#16#121#0" expanded="true" />
</folding>
@ -108,7 +101,7 @@
<file leaf-file-name="objtoobj.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/objtoobj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="493">
<state relative-caret-position="2703">
<caret line="163" column="20" lean-forward="false" selection-start-line="163" selection-start-column="20" selection-end-line="163" selection-end-column="20" />
<folding />
</state>
@ -128,7 +121,7 @@
<file leaf-file-name="slice.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/slice.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="544">
<state relative-caret-position="493">
<caret line="32" column="42" lean-forward="false" selection-start-line="32" selection-start-column="42" selection-end-line="32" selection-end-column="42" />
<folding>
<element signature="e#16#53#0" expanded="true" />
@ -227,7 +220,6 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scratches" />
<pane id="ProjectPane">
<subPane>
<PATH>
@ -278,6 +270,7 @@
</PATH>
</subPane>
</pane>
<pane id="Scratches" />
<pane id="Scope" />
</panes>
</component>
@ -481,7 +474,8 @@
<workItem from="1504252839700" duration="18000" />
<workItem from="1504488004086" duration="365000" />
<workItem from="1504488391347" duration="840000" />
<workItem from="1504575702799" duration="10681000" />
<workItem from="1504575702799" duration="11303000" />
<workItem from="1504661068799" duration="698000" />
</task>
<task id="LOCAL-00001">
<created>1500458878821</created>
@ -658,11 +652,18 @@
<option name="project" value="LOCAL" />
<updated>1504596978308</updated>
</task>
<option name="localTasksCounter" value="26" />
<task id="LOCAL-00026" summary="工具">
<created>1504601110529</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1504601110529</updated>
</task>
<option name="localTasksCounter" value="27" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="88219000" />
<option name="totallyTimeSpent" value="89539000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -675,14 +676,13 @@
</component>
<component name="ToolWindowManager">
<frame x="55" y="-8" width="1873" height="1084" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.33756205" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.34142306" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.6330179" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32912722" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32912722" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24972437" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
@ -724,7 +724,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="15" column="0" lean-forward="false" selection-start-line="15" selection-start-column="0" selection-end-line="15" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
@ -768,7 +767,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="15" column="0" lean-forward="false" selection-start-line="15" selection-start-column="0" selection-end-line="15" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
@ -900,7 +898,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
@ -908,7 +905,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
@ -916,7 +912,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="527">
<caret line="34" column="36" lean-forward="false" selection-start-line="34" selection-start-column="36" selection-end-line="34" selection-end-column="36" />
<folding />
</state>
</provider>
</entry>
@ -932,7 +927,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="11" column="19" lean-forward="false" selection-start-line="11" selection-start-column="19" selection-end-line="11" selection-end-column="19" />
<folding />
</state>
</provider>
</entry>
@ -948,7 +942,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="13" lean-forward="false" selection-start-line="9" selection-start-column="4" selection-end-line="9" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
@ -956,7 +949,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="816">
<caret line="92" column="1" lean-forward="false" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
@ -964,7 +956,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-289">
<caret line="10" column="15" lean-forward="false" selection-start-line="10" selection-start-column="15" selection-end-line="10" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
@ -972,7 +963,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="236" column="0" lean-forward="false" selection-start-line="236" selection-start-column="0" selection-end-line="236" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
@ -980,9 +970,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1210">
<caret line="85" column="0" lean-forward="false" selection-start-line="85" selection-start-column="0" selection-end-line="85" selection-end-column="0" />
<folding>
<element signature="e#14#137#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -990,7 +977,6 @@
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="0" lean-forward="false" selection-start-line="9" selection-start-column="0" selection-end-line="16" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
@ -1004,7 +990,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/objtoobj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="493">
<state relative-caret-position="2703">
<caret line="163" column="20" lean-forward="false" selection-start-line="163" selection-start-column="20" selection-end-line="163" selection-end-column="20" />
<folding />
</state>
@ -1020,7 +1006,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/slice.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="544">
<state relative-caret-position="493">
<caret line="32" column="42" lean-forward="false" selection-start-line="32" selection-start-column="42" selection-end-line="32" selection-end-column="42" />
<folding>
<element signature="e#16#53#0" expanded="true" />
@ -1030,7 +1016,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<state relative-caret-position="748">
<caret line="49" column="0" lean-forward="false" selection-start-line="49" selection-start-column="0" selection-end-line="58" selection-end-column="1" />
<folding>
<element signature="e#16#72#0" expanded="true" />
@ -1040,7 +1026,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/func.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-255">
<state relative-caret-position="204">
<caret line="21" column="5" lean-forward="false" selection-start-line="21" selection-start-column="5" selection-end-line="21" selection-end-column="5" />
<folding />
</state>
@ -1054,14 +1040,7 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="18" column="1" lean-forward="true" selection-start-line="18" selection-start-column="1" selection-end-line="18" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/config.json" />
<entry file="file://$PROJECT_DIR$/example/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
@ -1073,15 +1052,15 @@
<entry file="file://$PROJECT_DIR$/dri/ddsms/ddsms.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1292">
<caret line="83" column="22" lean-forward="true" selection-start-line="83" selection-start-column="22" selection-end-line="83" selection-end-column="22" />
<caret line="83" column="22" lean-forward="false" selection-start-line="83" selection-start-column="22" selection-end-line="83" selection-end-column="22" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/dri/upload/upload.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1173">
<caret line="69" column="1" lean-forward="true" selection-start-line="69" selection-start-column="1" selection-end-line="69" selection-end-column="1" />
<state relative-caret-position="510">
<caret line="30" column="5" lean-forward="false" selection-start-line="30" selection-start-column="5" selection-end-line="30" selection-end-column="5" />
<folding>
<element signature="e#16#121#0" expanded="true" />
</folding>

41
db.go
View File

@ -17,9 +17,9 @@ type HoTimeDB struct {
LastQuery string
LastData []interface{}
ConnectFunc func(err ...*Error) *sql.DB
LastErr Error
limit Slice
Tx *sql.Tx //事务对象
LastErr Error
limit Slice
Tx *sql.Tx //事务对象
}
@ -31,15 +31,14 @@ func (this *HoTimeDB) SetConnect(connect func(err ...*Error) *sql.DB, err ...*Er
//事务如果action返回true则执行成功false则回滚
func (this *HoTimeDB) Action(action func(db HoTimeDB) bool) bool {
db:=HoTimeDB{DB:this.DB,Cached:this.Cached}
db := HoTimeDB{DB: this.DB, Cached: this.Cached}
tx, err := db.Begin()
if err != nil {
this.LastErr.SetError(err)
return false
}
db.Tx=tx
db.Tx = tx
result := action(db)
@ -284,13 +283,12 @@ func (this *HoTimeDB) Query(query string, args ...interface{}) []Map {
return nil
}
if this.Tx!=nil{
if this.Tx != nil {
resl, err = this.Tx.Query(query, args...)
}else{
} else {
resl, err = this.DB.Query(query, args...)
}
this.LastErr.SetError(err)
if err != nil {
if err = this.DB.Ping(); err != nil {
@ -314,20 +312,18 @@ func (this *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, Error
var e error
var resl sql.Result
if this.DB == nil {
err := errors.New("没有初始化数据库")
this.LastErr.SetError(err)
return nil, this.LastErr
}
if this.Tx!=nil{
if this.Tx != nil {
resl, e = this.Tx.Exec(query, args...)
}else{
} else {
resl, e = this.DB.Exec(query, args...)
}
this.LastErr.SetError(e)
//判断是否连接断开了
@ -383,10 +379,17 @@ func (this *HoTimeDB) Select(table string, qu ...interface{}) []Map {
query += " " + qu[intQs].(string)
} else {
for i := 0; i < len(qu[intQs].(Slice)); i++ {
if i+1 != len(qu[intQs].(Slice)) {
query += " `" + qu[intQs].(Slice)[i].(string) + "`,"
k := qu[intQs].(Slice)[i].(string)
if strings.Contains(k, " AS ") {
query += " " + k + " "
} else {
query += " `" + qu[intQs].(Slice)[i].(string) + "`"
query += " `" + k + "` "
}
if i+1 != len(qu[intQs].(Slice)) {
query = query + ", "
}
}
@ -574,6 +577,7 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
length := len(k)
if length > 4 {
def := false
switch Substr(k, length-3, 3) {
case "[>]":
k = strings.Replace(k, "[>]", "", -1)
@ -588,7 +592,7 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
where, res = this.notIn(k, v, where, res)
case "[#]":
k = strings.Replace(k, "[#]", "", -1)
where += "`" + k + "`=" + ObjToStr(v)
where += " " + k + "=" + ObjToStr(v)
case "[~]":
k = strings.Replace(k, "[~]", "", -1)
where += "`" + k + "` LIKE ? "
@ -638,6 +642,9 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
}
}
} else if k == "[#]" {
k = strings.Replace(k, "[#]", "", -1)
where += " " + ObjToStr(v) + " "
} else {
//fmt.Println(reflect.ValueOf(v).Type().String())
if reflect.ValueOf(v).Type().String() == "hotime.Slice" {

View File

@ -61,11 +61,6 @@ func (this Slice) Get(key int, err ...*Error) interface{} {
func (this Slice) Put(key int, value interface{}) {
this[key] = value
}
func (this Slice) Append(value interface{}) {
this = append(this, value)
}
func (this Slice) GetJsonString() string {
return ObjToStr(this)