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") } } }