数据库操作
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

844 lines
19 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package dbquery
  2. import (
  3. "database/sql"
  4. "errors"
  5. "log"
  6. "strconv"
  7. "strings"
  8. "git.tetele.net/tgo/helper"
  9. )
  10. var stmt *sql.Stmt
  11. var err error
  12. type Query struct {
  13. dbname string
  14. table string
  15. alias string
  16. title string
  17. where []string
  18. where_or []string
  19. join [][]string //[["tablea as a","a.id=b.id","left"]]
  20. save_data []map[string]interface{} //批量操作的数据[["title":"a","num":1,],["title":"a","num":1,]]
  21. upd_field []string // 批量更新时需要更新的字段,为空时按除id外的字段进行更新
  22. data []string
  23. value []interface{}
  24. orderby string
  25. groupby string
  26. having string
  27. page int
  28. page_size int
  29. stmt *sql.Stmt
  30. conn *sql.DB
  31. debug bool
  32. dbtype string
  33. }
  34. func NewQuery(t ...string) *Query {
  35. var conn_type *sql.DB = DB
  36. var db_type string = "mysql"
  37. if len(t) > 0 {
  38. switch t[0] {
  39. case "mysql":
  40. conn_type = DB
  41. db_type = "mysql"
  42. case "mssql": //sql server
  43. conn_type = MSDB_CONN
  44. db_type = "mssql"
  45. }
  46. }
  47. return &Query{
  48. conn: conn_type,
  49. dbtype: db_type,
  50. }
  51. }
  52. func (this *Query) Conn(conn *sql.DB) *Query {
  53. this.conn = conn
  54. return this
  55. }
  56. func (this *Query) Db(dbname string) *Query {
  57. this.dbname = dbname
  58. return this
  59. }
  60. func (this *Query) Table(tablename string) *Query {
  61. this.table = tablename
  62. return this
  63. }
  64. func (this *Query) Alias(tablename string) *Query {
  65. this.alias = tablename
  66. return this
  67. }
  68. func (this *Query) Title(title string) *Query {
  69. this.title = title
  70. return this
  71. }
  72. func (this *Query) Page(page int) *Query {
  73. this.page = page
  74. return this
  75. }
  76. func (this *Query) PageSize(page_num int) *Query {
  77. this.page_size = page_num
  78. return this
  79. }
  80. func (this *Query) Having(having string) *Query {
  81. this.having = having
  82. return this
  83. }
  84. func (this *Query) Orderby(orderby string) *Query {
  85. this.orderby = orderby
  86. return this
  87. }
  88. func (this *Query) Groupby(groupby string) *Query {
  89. this.groupby = groupby
  90. return this
  91. }
  92. func (this *Query) Where(where string) *Query {
  93. this.where = append(this.where, where)
  94. return this
  95. }
  96. func (this *Query) Wheres(wheres []string) *Query {
  97. if len(wheres) > 0 {
  98. this.where = append(this.where, wheres...)
  99. }
  100. return this
  101. }
  102. func (this *Query) WhereOr(where string) *Query {
  103. this.where_or = append(this.where_or, where)
  104. return this
  105. }
  106. func (this *Query) SaveData(value map[string]interface{}) *Query {
  107. this.save_data = append(this.save_data, value)
  108. return this
  109. }
  110. func (this *Query) SaveDatas(value []map[string]interface{}) *Query {
  111. this.save_data = append(this.save_data, value...)
  112. return this
  113. }
  114. func (this *Query) UpdField(value string) *Query {
  115. this.upd_field = append(this.upd_field, value)
  116. return this
  117. }
  118. func (this *Query) UpdFields(value []string) *Query {
  119. this.upd_field = append(this.upd_field, value...)
  120. return this
  121. }
  122. func (this *Query) Value(value interface{}) *Query {
  123. this.value = append(this.value, value)
  124. return this
  125. }
  126. func (this *Query) Values(values []interface{}) *Query {
  127. this.value = append(this.value, values...)
  128. return this
  129. }
  130. func (this *Query) Join(join []string) *Query {
  131. this.join = append(this.join, join)
  132. return this
  133. }
  134. func (this *Query) Data(data string) *Query {
  135. this.data = append(this.data, data)
  136. return this
  137. }
  138. func (this *Query) Datas(datas []string) *Query {
  139. this.data = append(this.data, datas...)
  140. return this
  141. }
  142. func (this *Query) Debug(debug bool) *Query {
  143. this.debug = debug
  144. return this
  145. }
  146. /*
  147. * 清理上次查询
  148. */
  149. func (this *Query) Clean() *Query {
  150. this.title = ""
  151. this.where = this.where[0:0]
  152. this.where_or = this.where_or[0:0]
  153. this.join = this.join[0:0]
  154. this.data = this.data[0:0]
  155. this.value = this.value[0:0]
  156. this.orderby = ""
  157. this.groupby = ""
  158. this.page = 0
  159. this.page_size = 0
  160. this.save_data = this.save_data[0:0]
  161. this.upd_field = this.upd_field[0:0]
  162. this.having = ""
  163. return this
  164. }
  165. //获取表格信息
  166. func (this *Query) GetTableInfo(table string) (map[string]interface{}, error) {
  167. field := []string{
  168. "COLUMN_NAME", //字段名
  169. "COLUMN_DEFAULT", //默认值
  170. "DATA_TYPE", //数据类型
  171. "COLUMN_TYPE", //数据类型+长度
  172. "COLUMN_COMMENT", //备注
  173. "IS_NULLABLE", //是否为空
  174. }
  175. sql := "select `" + strings.Join(field, "`,`") + "` from information_schema.COLUMNS where table_name = ? and table_schema = ?"
  176. if this.conn == nil {
  177. this.conn = DB
  178. }
  179. stmtSql, err := this.conn.Prepare(sql)
  180. if err != nil {
  181. return nil, err
  182. }
  183. list, err := StmtForQueryList(stmtSql, []interface{}{table, this.dbname})
  184. if err != nil {
  185. return nil, err
  186. }
  187. rows := make([]interface{}, 0, len(list))
  188. fieldName := make([]string, 0, len(list))
  189. for _, item := range list {
  190. info := map[string]interface{}{
  191. "name": "",
  192. "column_type": "",
  193. "is_null": true,
  194. "data_type": "",
  195. "comment": "",
  196. "default": "",
  197. }
  198. for _, k := range field {
  199. index := helper.StrFirstToUpper(k)
  200. if v, ok := item[index]; ok {
  201. switch k {
  202. case "COLUMN_NAME":
  203. info["name"] = v
  204. case "COLUMN_DEFAULT":
  205. info["default"] = v
  206. case "DATA_TYPE":
  207. info["data_type"] = v
  208. case "COLUMN_TYPE":
  209. info["column_type"] = helper.ToInt64(v)
  210. case "COLUMN_COMMENT":
  211. info["comment"] = helper.ToInt64(v)
  212. case "IS_NULLABLE":
  213. if v == "NO" {
  214. info["is_null"] = false
  215. }
  216. }
  217. }
  218. }
  219. name := helper.ToStr(info["name"])
  220. if name != "" {
  221. rows = append(rows, info)
  222. fieldName = append(fieldName, name)
  223. }
  224. }
  225. return map[string]interface{}{
  226. "field": fieldName,
  227. "list": rows,
  228. }, nil
  229. }
  230. //构造子查询
  231. func (this *Query) BuildSelectSql() (map[string]interface{}, error) {
  232. if this.dbname == "" && this.table == "" {
  233. return nil, errors.New("参数错误,没有数据表")
  234. }
  235. var table = ""
  236. if strings.Contains(this.table, "select ") {
  237. table = this.table
  238. } else {
  239. table = getTableName(this.dbname, this.table, this.dbtype)
  240. }
  241. // var err error
  242. var sql, title string
  243. if this.title != "" {
  244. title = this.title
  245. } else {
  246. title = "*"
  247. }
  248. sql = helper.StringJoin("/*slave*/ select ", title)
  249. if this.alias != "" {
  250. table = helper.StringJoin(table, " as ", this.alias)
  251. }
  252. sql = helper.StringJoin(sql, " from ", table)
  253. if len(this.join) > 0 {
  254. for _, joinitem := range this.join {
  255. if len(joinitem) < 2 {
  256. continue
  257. }
  258. if len(joinitem) == 3 {
  259. sql = helper.StringJoin(sql, " ", joinitem[2], " join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1])
  260. } else { //默认左连接
  261. sql = helper.StringJoin(sql, " left join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1])
  262. }
  263. }
  264. }
  265. if len(this.where) > 0 || len(this.where_or) > 0 {
  266. sql = helper.StringJoin(sql, " where ")
  267. }
  268. if len(this.where) > 0 {
  269. sql = helper.StringJoin(sql, " (", strings.Join(this.where, " and "), " ) ")
  270. }
  271. if len(this.where_or) > 0 {
  272. if len(this.where) > 0 {
  273. sql = helper.StringJoin(sql, " or ", strings.Join(this.where_or, " or "))
  274. } else {
  275. sql = helper.StringJoin(sql, strings.Join(this.where_or, " or "))
  276. }
  277. }
  278. if this.groupby != "" {
  279. sql = helper.StringJoin(sql, " group by ", this.groupby)
  280. }
  281. if this.having != "" {
  282. sql = helper.StringJoin(sql, " having ", this.having)
  283. }
  284. if this.orderby != "" {
  285. sql = helper.StringJoin(sql, " order by ", this.orderby)
  286. }
  287. if this.page > 0 || this.page_size > 0 {
  288. if this.page < 1 {
  289. this.page = 1
  290. }
  291. if this.page_size < 1 {
  292. this.page_size = 10
  293. }
  294. from := strconv.Itoa((this.page - 1) * this.page_size)
  295. offset := strconv.Itoa(this.page_size)
  296. if from != "" && offset != "" {
  297. sql = helper.StringJoin(sql, " limit ", from, " , ", offset)
  298. }
  299. }
  300. if this.debug {
  301. log.Println("query sql:", sql, this.value)
  302. }
  303. condition_len := 0 //所有条件数
  304. for _, ch2 := range sql {
  305. if string(ch2) == "?" {
  306. condition_len++
  307. }
  308. }
  309. if condition_len != len(this.value) {
  310. return nil, errors.New("参数错误,条件值错误")
  311. }
  312. return map[string]interface{}{
  313. "sql": sql,
  314. "value": this.value,
  315. }, nil
  316. }
  317. // 拼查询sql
  318. func (this *Query) QueryStmt() error {
  319. res := map[string]interface{}{}
  320. res, err = this.BuildSelectSql()
  321. if err != nil {
  322. return err
  323. }
  324. sql := helper.ToStr(res["sql"])
  325. if SLAVER_DB != nil {
  326. this.conn = SLAVER_DB
  327. } else {
  328. this.conn = DB
  329. }
  330. stmt, err = this.conn.Prepare(sql)
  331. if err != nil {
  332. return err
  333. }
  334. this.stmt = stmt
  335. return nil
  336. }
  337. // 拼更新sql
  338. func (this *Query) UpdateStmt() error {
  339. if this.dbname == "" && this.table == "" {
  340. return errors.New("参数错误,没有数据表")
  341. }
  342. if len(this.where) < 1 {
  343. return errors.New("参数错误,缺少条件")
  344. }
  345. dbName := getTableName(this.dbname, this.table, this.dbtype)
  346. var sql string
  347. sql = helper.StringJoin("update ", dbName, " set ", strings.Join(this.data, " , "))
  348. sql = helper.StringJoin(sql, " where ", strings.Join(this.where, " and "))
  349. if this.debug {
  350. log.Println("update sql:", sql, this.value)
  351. }
  352. condition_len := 0 //所有条件数
  353. for _, ch2 := range sql {
  354. if string(ch2) == "?" {
  355. condition_len++
  356. }
  357. }
  358. if condition_len != len(this.value) {
  359. return errors.New("参数错误,条件值错误")
  360. }
  361. if this.conn == nil {
  362. this.conn = DB
  363. }
  364. stmt, err = this.conn.Prepare(sql)
  365. if err != nil {
  366. return err
  367. }
  368. this.stmt = stmt
  369. return nil
  370. }
  371. // 拼批量存在更新不存在插入sql
  372. func (this *Query) UpdateAllStmt() error {
  373. if this.dbname == "" && this.table == "" {
  374. return errors.New("参数错误,没有数据表")
  375. }
  376. dbName := getTableName(this.dbname, this.table)
  377. var sql string
  378. var dataSql []string //一组用到的占位字符
  379. var valSql []string //占位字符组
  380. var updSql []string //更新字段的sql
  381. var updFieldLen = len(this.upd_field) //需要更新的字段数量,为0时更新除id外添加值
  382. dataLen := len(this.save_data)
  383. if dataLen > 0 {
  384. //批量操作
  385. this.data = this.data[0:0]
  386. this.value = this.value[0:0]
  387. var dataSqlText string //占位字符组
  388. for i := 0; i < dataLen; i++ {
  389. if i == 0 {
  390. //第一组时分配变量空间
  391. fieldLen := len(this.save_data[i])
  392. this.data = make([]string, 0, fieldLen)
  393. dataSql = make([]string, 0, fieldLen)
  394. this.value = make([]interface{}, 0, fieldLen*dataLen)
  395. valSql = make([]string, 0, dataLen)
  396. switch updFieldLen {
  397. case 0:
  398. //预览创建数据的长度
  399. updSql = make([]string, 0, fieldLen)
  400. default:
  401. //按照需要更新字段数长度
  402. updSql = make([]string, 0, updFieldLen)
  403. for _, k := range this.upd_field {
  404. updSql = append(updSql, k+"=values("+k+")") //存储需要更新的字段
  405. }
  406. }
  407. for k := range this.save_data[i] {
  408. this.data = append(this.data, k) //存储添加的字段
  409. dataSql = append(dataSql, "?") //存储需要的占位符
  410. if updFieldLen == 0 && k != "id" {
  411. updSql = append(updSql, k+"=values("+k+")") //存储需要更新的字段
  412. }
  413. }
  414. dataSqlText = strings.Join(dataSql, ",") //组成每组占位字符格式
  415. }
  416. for j := 0; j < len(this.data); j++ {
  417. this.value = append(this.value, this.save_data[i][this.data[j]]) //存储值
  418. }
  419. valSql = append(valSql, "("+dataSqlText+")") //组成占位字符组
  420. }
  421. } else {
  422. //添加一条(原理同上)
  423. fieldLen := len(this.data)
  424. dataSql = make([]string, 0, fieldLen)
  425. valSql = make([]string, 0, 1)
  426. switch updFieldLen {
  427. case 0:
  428. updSql = make([]string, 0, fieldLen)
  429. default:
  430. updSql = make([]string, 0, updFieldLen)
  431. for _, k := range this.upd_field {
  432. updSql = append(updSql, k+"=values("+k+")")
  433. }
  434. }
  435. for i := 0; i < fieldLen; i++ {
  436. dataSql = append(dataSql, "?")
  437. if updFieldLen == 0 && this.data[i] != "id" {
  438. updSql = append(updSql, this.data[i]+"=values("+this.data[i]+")")
  439. }
  440. }
  441. if updFieldLen > 0 {
  442. for _, k := range this.upd_field {
  443. updSql = append(updSql, k+"=values("+k+")")
  444. }
  445. }
  446. valSql = append(valSql, "("+strings.Join(dataSql, " , ")+")")
  447. }
  448. if len(this.data) == 0 {
  449. return errors.New("参数错误,没有字段值")
  450. }
  451. if len(this.value) == 0 {
  452. return errors.New("参数错误,条件值错误")
  453. }
  454. setText := " values "
  455. if len(valSql) > 1 {
  456. setText = " value "
  457. }
  458. sql = helper.StringJoin("insert into ", dbName, " (", strings.Join(this.data, " , "), ")", setText, strings.Join(valSql, ","), " ON DUPLICATE KEY UPDATE ", strings.Join(updSql, " , "))
  459. if this.debug {
  460. log.Println("insert on duplicate key update sql:", sql, this.value)
  461. }
  462. conditionLen := 0 //所有条件数
  463. for _, ch2 := range sql {
  464. if string(ch2) == "?" {
  465. conditionLen++
  466. }
  467. }
  468. if conditionLen != len(this.value) {
  469. return errors.New("参数错误,条件值数量不匹配")
  470. }
  471. if this.conn == nil {
  472. this.conn = DB
  473. }
  474. stmt, err = this.conn.Prepare(sql)
  475. if err != nil {
  476. return err
  477. }
  478. this.stmt = stmt
  479. return nil
  480. }
  481. // 拼批量插入sql
  482. func (this *Query) CreateAllStmt() error {
  483. if this.dbname == "" && this.table == "" {
  484. return errors.New("参数错误,没有数据表")
  485. }
  486. dbName := getTableName(this.dbname, this.table)
  487. var sql string
  488. var dataSql []string //一组用到的占位字符
  489. var valSql []string //占位字符组
  490. dataLen := len(this.save_data)
  491. if dataLen > 0 {
  492. //清空字段和值
  493. this.data = this.data[0:0]
  494. this.value = this.value[0:0]
  495. var dataSqlText string //占位字符组
  496. for i := 0; i < dataLen; i++ {
  497. if i == 0 {
  498. //第一组时分配变量空间
  499. fieldLen := len(this.save_data[i])
  500. this.data = make([]string, 0, fieldLen)
  501. dataSql = make([]string, 0, fieldLen)
  502. this.value = make([]interface{}, 0, fieldLen*dataLen)
  503. valSql = make([]string, 0, dataLen)
  504. for k := range this.save_data[i] {
  505. this.data = append(this.data, k) //存储字段
  506. dataSql = append(dataSql, "?") //存储需要的占位符
  507. }
  508. dataSqlText = strings.Join(dataSql, ",") //组成每组占位字符格式
  509. }
  510. for j := 0; j < len(this.data); j++ {
  511. this.value = append(this.value, this.save_data[i][this.data[j]]) //存储值
  512. }
  513. valSql = append(valSql, "("+dataSqlText+")") //组成占位字符组
  514. }
  515. } else {
  516. //添加一条(原理同上)
  517. fieldLen := len(this.data)
  518. dataSql = make([]string, 0, fieldLen)
  519. for i := 0; i < fieldLen; i++ {
  520. dataSql = append(dataSql, "?")
  521. }
  522. valSql = make([]string, 0, 1)
  523. valSql = append(valSql, "("+strings.Join(dataSql, " , ")+")")
  524. }
  525. if len(this.data) == 0 {
  526. return errors.New("参数错误,字段名错误")
  527. }
  528. if len(this.value) == 0 {
  529. return errors.New("参数错误,条件值错误")
  530. }
  531. //通过sql关键字优化批量操作和单个操作效率
  532. setText := " values "
  533. if len(valSql) > 1 {
  534. setText = " value "
  535. }
  536. sql = helper.StringJoin("insert into ", dbName, " (", strings.Join(this.data, " , "), ")", setText, strings.Join(valSql, ","))
  537. if this.debug {
  538. log.Println("insert sql:", sql, this.value)
  539. }
  540. conditionLen := 0 //所有条件数
  541. for _, ch2 := range sql {
  542. if string(ch2) == "?" {
  543. conditionLen++
  544. }
  545. }
  546. if conditionLen != len(this.value) {
  547. return errors.New("参数错误,条件值数量不匹配")
  548. }
  549. if this.conn == nil {
  550. this.conn = DB
  551. }
  552. stmt, err = this.conn.Prepare(sql)
  553. if err != nil {
  554. return err
  555. }
  556. this.stmt = stmt
  557. return nil
  558. }
  559. // 拼插入sql
  560. func (this *Query) CreateStmt() error {
  561. if this.dbname == "" && this.table == "" {
  562. return errors.New("参数错误,没有数据表")
  563. }
  564. dbName := getTableName(this.dbname, this.table, this.dbtype)
  565. var sql string
  566. sql = helper.StringJoin("insert into ", dbName, " set ", strings.Join(this.data, " , "))
  567. if this.debug {
  568. log.Println("insert sql:", sql, this.value)
  569. }
  570. condition_len := 0 //所有条件数
  571. for _, ch2 := range sql {
  572. if string(ch2) == "?" {
  573. condition_len++
  574. }
  575. }
  576. if condition_len != len(this.value) {
  577. return errors.New("参数错误,条件值错误")
  578. }
  579. if this.conn == nil {
  580. this.conn = DB
  581. }
  582. stmt, err = this.conn.Prepare(sql)
  583. if err != nil {
  584. return err
  585. }
  586. this.stmt = stmt
  587. return nil
  588. }
  589. // 拼删除sql
  590. func (this *Query) DeleteStmt() error {
  591. if this.dbname == "" && this.table == "" {
  592. return errors.New("参数错误,没有数据表")
  593. }
  594. if len(this.where) < 1 {
  595. return errors.New("参数错误,缺少条件")
  596. }
  597. dbName := getTableName(this.dbname, this.table, this.dbtype)
  598. var sql string
  599. sql = helper.StringJoin("delete from ", dbName, " where ", strings.Join(this.where, " and "))
  600. if this.page_size > 0 {
  601. sql = helper.StringJoin(sql, " limit ", strconv.Itoa(this.page_size))
  602. }
  603. if this.debug {
  604. log.Println("delete sql:", sql, this.value)
  605. }
  606. condition_len := 0 //所有条件数
  607. for _, ch2 := range sql {
  608. if string(ch2) == "?" {
  609. condition_len++
  610. }
  611. }
  612. if condition_len != len(this.value) {
  613. return errors.New("参数错误,条件值错误")
  614. }
  615. if this.conn == nil {
  616. this.conn = DB
  617. }
  618. stmt, err = this.conn.Prepare(sql)
  619. if err != nil {
  620. return err
  621. }
  622. this.stmt = stmt
  623. return nil
  624. }
  625. /**
  626. * 执行查询列表
  627. * return list error
  628. */
  629. func (this *Query) Select() ([]map[string]string, error) {
  630. _, rows, err := FetchRows(this.dbname, this.table, this.alias, this.title, this.join,
  631. this.where, this.where_or, this.value, this.orderby, this.groupby, this.having, this.page, this.page_size, this.debug)
  632. return rows, err
  633. }
  634. /**
  635. * 执行查询多条数据
  636. * return row error
  637. * 2022/01/05
  638. */
  639. func (this *Query) List() ([]map[string]string, error) {
  640. err := this.QueryStmt()
  641. if err != nil {
  642. return []map[string]string{}, err
  643. }
  644. if this.stmt == nil {
  645. return []map[string]string{}, errors.New("缺少必要参数")
  646. }
  647. return StmtForQueryList(this.stmt, this.value)
  648. }
  649. /**
  650. * 执行查询一条数据
  651. * return row error
  652. */
  653. func (this *Query) Find() (map[string]string, error) {
  654. _, row, err := GetRow(this.dbname, this.table, this.alias, this.title, this.join,
  655. this.where, this.where_or, this.value, this.orderby, this.groupby, this.having, this.debug)
  656. return row, err
  657. }
  658. /**
  659. * 执行查询一条数据
  660. * return row error
  661. * 2022/01/05
  662. */
  663. func (this *Query) Get() (map[string]string, error) {
  664. this.page = 1
  665. this.page_size = 1
  666. err := this.QueryStmt()
  667. if err != nil {
  668. return map[string]string{}, err
  669. }
  670. if this.stmt == nil {
  671. return nil, errors.New("缺少必要参数")
  672. }
  673. return StmtForQueryRow(this.stmt, this.value)
  674. }
  675. /**
  676. * 执行更新
  677. * return is_updated error
  678. */
  679. func (this *Query) Update() (int64, error) {
  680. err := this.UpdateStmt()
  681. if err != nil {
  682. return 0, err
  683. }
  684. return StmtForUpdateExec(this.stmt, this.value)
  685. }
  686. //批量更新
  687. func (this *Query) UpdateAll() (int64, error) {
  688. err := this.UpdateAllStmt()
  689. if err != nil {
  690. return 0, err
  691. }
  692. return StmtForUpdateExec(this.stmt, this.value)
  693. }
  694. /**
  695. * 执行删除
  696. * return is_delete error
  697. */
  698. func (this *Query) Delete() (int64, error) {
  699. err := this.DeleteStmt()
  700. if err != nil {
  701. return 0, err
  702. }
  703. return StmtForUpdateExec(this.stmt, this.value)
  704. }
  705. /**
  706. * 执行写入
  707. * return is_insert error
  708. */
  709. func (this *Query) Create() (int64, error) {
  710. err := this.CreateStmt()
  711. if err != nil {
  712. return 0, err
  713. }
  714. return StmtForInsertExec(this.stmt, this.value)
  715. }
  716. func (this *Query) CreateAll() (int64, error) {
  717. err := this.CreateAllStmt()
  718. if err != nil {
  719. return 0, err
  720. }
  721. return StmtForInsertExec(this.stmt, this.value)
  722. }