| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package prepare_batch
- import (
- "fmt"
- "testing"
- "time"
- "git.wecise.com/wecise/odbserver/odb"
- "git.wecise.com/wecise/odbserver/odb/test"
- "gitee.com/wecisecode/util/logger"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- )
- type PrepareInsertBatchTests struct {
- Test *testing.T
- g *odb.Gutil
- }
- func PrepareInsertBatchTest(t *testing.T) {
- g := test.TestG()
- t.Run("InitG", func(t *testing.T) {
- test := &PrepareInsertBatchTests{Test: t, g: g}
- test.InitG()
- })
- t.Run("Class", func(t *testing.T) {
- test := &PrepareInsertBatchTests{Test: t, g: g}
- test.Class()
- })
- t.Run("Data", func(t *testing.T) {
- test := &PrepareInsertBatchTests{Test: t, g: g}
- test.Data()
- })
- time.Sleep(time.Duration(1) * time.Second)
- t.Run("Valid", func(t *testing.T) {
- test := &PrepareInsertBatchTests{Test: t, g: g}
- test.Valid()
- })
- }
- func (t *PrepareInsertBatchTests) InitG() {
- require.NotNil(t.Test, t.g)
- }
- func (t *PrepareInsertBatchTests) Class() {
- _, _, err := t.g.Query(`
- create class if not exists /test/batch (
-
- v_varchar varchar,
- v_text text,
- v_int int,
- v_bigint bigint,
- v_smalldouble double,
- v_double double,
- v_float float,
- v_bool bool,
-
- indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
- keys(v_varchar , v_text)
- ) with ckeys=v_bool`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *PrepareInsertBatchTests) Data() {
- var err error
- stat, err := t.g.Prepare(`
-
- BEGIN BATCH
-
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? );
- insert into /test/batch (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values (?, ?, ?, ?, ?, ?, ?, ? )
-
- END
-
- `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- _, _, err = stat.Exec(
- "4006", "hello word 2003", 4006, 4006, 1.1, 1.1234567890123456, 1.123456, true,
- "40", "hello word 2003", 40, 40, 1.1, 1.1234567890123456, 1.123456, false,
- "400", "hello word 2003", 400, 400, 1.1, 1.1234567890123456, 1.123456, true,
- "74006", "hello word 2003", -4006, 4006, 1.1, 1.1234567890123456, 1.123456, false,
- "409", "hello word 2003", -40, 40, 1.1, 1.1234567890123456, 1.123456, true,
- "500", "hello word 2003", -400, 400, 1.1, 1.1234567890123456, 1.123456, false,
- "600", "hello word 2003", 370, 370, 1.1, 1.1234567890123456, 1.123456, true,
- "700", "hello word 2003", 580, 580, 1.1, 1.1234567890123456, 1.123456, true,
- "602", "hello word 2003", -370, -370, 1.1, 1.1234567890123456, 1.123456, true,
- "708", "hello word 2003", -580, -580, 1.1, 1.1234567890123456, 1.123456, true)
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *PrepareInsertBatchTests) Valid() {
- rtn, _, err := t.g.Query(`select * from /test/batch`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 10, len(rtn), "they should be equal")
- }
- }
- }
|