|
@@ -39,10 +39,13 @@ type ODBCImporter struct {
|
|
|
}
|
|
|
|
|
|
func NewODBCImporter() *ODBCImporter {
|
|
|
- return &ODBCImporter{
|
|
|
- client: odbc.ODBC(),
|
|
|
+ odbci := &ODBCImporter{
|
|
|
classinfos: cmap.New[string, *classinfo](),
|
|
|
}
|
|
|
+ if odbc.DevPhase&(odbc.DP_CREATECLASS|odbc.DP_INSERTDATA) != 0 {
|
|
|
+ odbci.client = odbc.ODBC()
|
|
|
+ }
|
|
|
+ return odbci
|
|
|
}
|
|
|
|
|
|
// 根据数据修正类定义
|
|
@@ -112,9 +115,11 @@ func (odbci *ODBCImporter) InsertData(classname string, data map[string]any) (er
|
|
|
|
|
|
values = append(values, v)
|
|
|
}
|
|
|
- _, err = odbci.client.Query(ci.insertmql, values...).Do()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ if odbci.client != nil {
|
|
|
+ _, err = odbci.client.Query(ci.insertmql, values...).Do()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
atomic.AddInt64(&ci.insertcount, 1)
|
|
|
ci.mutex.Lock()
|
|
@@ -154,27 +159,29 @@ func (odbci *ODBCImporter) alldone() {
|
|
|
}
|
|
|
|
|
|
func (odbci *ODBCImporter) reload() error {
|
|
|
- _, e := odbci.client.Query(`delete from "/cgitest/x10/x1001" with version`).Do()
|
|
|
- _ = e
|
|
|
- _, e = odbci.client.Query(`delete from "/cgitest/x10/x1002" with version`).Do()
|
|
|
- _ = e
|
|
|
- _, e = odbci.client.Query(`delete from "/cgitest/x10/x1003" with version`).Do()
|
|
|
- _ = e
|
|
|
- _, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1001"`).Do()
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
- }
|
|
|
- _, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1002"`).Do()
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
- }
|
|
|
- _, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1003"`).Do()
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
- }
|
|
|
- _, e = odbci.client.Query(`drop class if exists "/cgitest/x10"`).Do()
|
|
|
- if e != nil {
|
|
|
- return e
|
|
|
+ if odbci.client != nil {
|
|
|
+ _, e := odbci.client.Query(`delete from "/cgitest/x10/x1001" with version`).Do()
|
|
|
+ _ = e
|
|
|
+ _, e = odbci.client.Query(`delete from "/cgitest/x10/x1002" with version`).Do()
|
|
|
+ _ = e
|
|
|
+ _, e = odbci.client.Query(`delete from "/cgitest/x10/x1003" with version`).Do()
|
|
|
+ _ = e
|
|
|
+ _, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1001"`).Do()
|
|
|
+ if e != nil {
|
|
|
+ return e
|
|
|
+ }
|
|
|
+ _, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1002"`).Do()
|
|
|
+ if e != nil {
|
|
|
+ return e
|
|
|
+ }
|
|
|
+ _, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1003"`).Do()
|
|
|
+ if e != nil {
|
|
|
+ return e
|
|
|
+ }
|
|
|
+ _, e = odbci.client.Query(`drop class if exists "/cgitest/x10"`).Do()
|
|
|
+ if e != nil {
|
|
|
+ return e
|
|
|
+ }
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
@@ -206,9 +213,11 @@ func (odbci *ODBCImporter) createClass(nickname, classname string, fieldinfoslis
|
|
|
mql += ", keys(" + strings.Join(keyfields, ",") + ")"
|
|
|
}
|
|
|
mql += `)with namespace="cgitest" and key=manu and nickname='` + nickname + `'`
|
|
|
- _, err = odbci.client.Query(mql).Do()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ if odbci.client != nil {
|
|
|
+ _, err = odbci.client.Query(mql).Do()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
var insertmql string
|
|
|
if len(fieldslist) > 0 {
|