Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: introduce begin and end in mssql batcher (#16285)

h3n4l617a6bd52664
diff --git a/backend/component/sheet/sheet.go b/backend/component/sheet/sheet.go
index 9d25ca7363..82abda661c 100644
--- a/backend/component/sheet/sheet.go
+++ b/backend/component/sheet/sheet.go
@@ -19,7 +19,6 @@ import (
tidbast "github.com/pingcap/tidb/pkg/parser/ast"
"github.com/bytebase/bytebase/backend/common"
- "github.com/bytebase/bytebase/backend/plugin/db/mssql"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
crparser "github.com/bytebase/bytebase/backend/plugin/parser/cockroachdb"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
@@ -155,17 +154,17 @@ func getSheetCommandsFromByteOffset(engine storepb.Engine, statement string) []*
func getSheetCommandsForMSSQL(statement string) []*storepb.SheetCommand {
var sheetCommands []*storepb.SheetCommand
- p := 0
- batch := mssql.NewBatch(statement)
+ batch := tsqlbatch.NewBatcher(statement)
for {
command, err := batch.Next()
if err == io.EOF {
- np := p + len(batch.String())
+ b := batch.Batch()
sheetCommands = append(sheetCommands, &storepb.SheetCommand{
- Start: int32(p),
- End: int32(np),
+ Start: int32(b.Start),
+ End: int32(b.End),
})
+ batch.Reset(nil)
break
}
if err != nil {
@@ -177,12 +176,12 @@ func getSheetCommandsForMSSQL(statement string) []*storepb.SheetCommand {
}
switch command.(type) {
case *tsqlbatch.GoCommand:
- np := p + len(batch.String())
+ b := batch.Batch()
sheetCommands = append(sheetCommands, &storepb.SheetCommand{
- Start: int32(p),
- End: int32(np),
+ Start: int32(b.Start),
+ End: int32(b.End),
})
- p = np
+ batch.Reset(nil)
default:
}
if len(sheetCommands) > common.MaximumCommands {
diff --git a/backend/plugin/db/mssql/mssql.go b/backend/plugin/db/mssql/mssql.go
index 12a63cdb9c..99f5d37ee2 100644
--- a/backend/plugin/db/mssql/mssql.go
+++ b/backend/plugin/db/mssql/mssql.go
@@ -185,18 +185,18 @@ func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteO
totalAffectRows := int64(0)
- batch := NewBatch(statement)
+ batch := tsqlbatch.NewBatcher(statement)
for idx := 0; ; {
command, err := batch.Next()
if err != nil {
if err == io.EOF {
// Try send the last batch to server.
- v := batch.String()
- if v != "" {
+ v := batch.Batch()
+ if v != nil && len(v.Text) > 0 {
indexes := []int32{int32(idx)}
opts.LogCommandExecute(indexes)
- rowsAffected, err := execute(ctx, tx, v)
+ rowsAffected, err := execute(ctx, tx, v.Text)
if err != nil {
opts.LogCommandResponse(indexes, 0, nil, err.Error())
return 0, err
@@ -206,20 +206,20 @@ func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteO
}
break
}
- return 0, errors.Wrapf(err, "failed to get next batch for statement: %s", batch.String())
+ return 0, errors.Wrapf(err, "failed to get next batch for statement: %s", batch.Batch().Text)
}
if command == nil {
continue
}
switch v := command.(type) {
case *tsqlbatch.GoCommand:
- stmt := batch.String()
+ b := batch.Batch()
// Try send the batch to server.
indexes := []int32{int32(idx)}
idx++
for i := uint(0); i < v.Count; i++ {
opts.LogCommandExecute(indexes)
- rowsAffected, err := execute(ctx, tx, stmt)
+ rowsAffected, err := execute(ctx, tx, b.Text)
if err != nil {
opts.LogCommandResponse(indexes, 0, nil, err.Error())
return 0, err
@@ -279,16 +279,16 @@ func (d *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement string
// Special handling for EXPLAIN queries in MSSQL is now integrated into queryBatch
// Regular query processing (unchanged)
- batch := NewBatch(statement)
+ batch := tsqlbatch.NewBatcher(statement)
var results []*v1pb.QueryResult
for {
command, err := batch.Next()
if err != nil {
if err == io.EOF {
- v := batch.String()
- if v != "" {
+ v := batch.Batch()
+ if v != nil && len(v.Text) > 0 {
// Query the last batch.
- qr, err := d.queryBatch(ctx, conn, v, queryContext)
+ qr, err := d.queryBatch(ctx, conn, v.Text, queryContext)
results = append(results, qr...)
if err != nil {
return results, err
@@ -297,16 +297,16 @@ func (d *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement string
batch.Reset(nil)
break
}
- return results, errors.Wrapf(err, "failed to get next batch for statement: %s", batch.String())
+ return results, errors.Wrapf(err, "failed to get next batch for statement: %s", batch.Batch().Text)
}
if command == nil {
continue
}
switch v := command.(type) {
case *tsqlbatch.GoCommand:
- stmt := batch.String()
+ b := batch.Batch()
// Query the batch.
- qr, err := d.queryBatch(ctx, conn, stmt, queryContext)
+ qr, err := d.queryBatch(ctx, conn, b.Text, queryContext)
results = append(results, qr...)
if err != nil {
return results, err
@@ -525,17 +525,3 @@ func getNextResultSetIdx(s []stmtType, beginIdx int) int {
}
return len(s)
}
-
-func NewBatch(statement string) *tsqlbatch.Batch {
- // Split to batches to support some client commands like GO.
- s := strings.Split(statement, "\n")
- scanner := func() (string, error) {
- if len(s) > 0 {
- z := s[0]
- s = s[1:]
- return z, nil
- }
- return "", io.EOF
- }
- return tsqlbatch.NewBatch(scanner)
-}
diff --git a/backend/plugin/parser/tsql/batch/batch.go b/backend/plugin/parser/tsql/batch/batch.go
index fa10088f56..5328ac888e 100644
--- a/backend/plugin/parser/tsql/batch/batch.go
+++ b/backend/plugin/parser/tsql/batch/batch.go
@@ -2,8 +2,10 @@ package batch
import (
"fmt"
+ "io"
"regexp"
"strconv"
+ "strings"
)
/*
@@ -18,6 +20,15 @@ const (
minCapIncrease = 512
)
+// Batch is a batch of Transact-SQL statements.
+type Batch struct {
+ Text string `yaml:"text"`
+ // Inclusive start position of the batch in the original script, starting from 0 and calculated by byte offset.
+ Start int `yaml:"start"`
+ // Exclusive end position of the batch in the original script, starting from 0 and calculated by byte offset.
+ End int `yaml:"end"`
+}
+
type Command interface {
// String returns the string representation of the command.
String() string
@@ -77,11 +88,35 @@ func buildGoCommand(input string) Command {
}
}
-type Scan func() (string, error)
+type scan func() (string, int, error)
-type Batch struct {
+func newDefaultScan(statement string) scan {
+ // Split the statement into lines to support some client commands like GO.
+ s := strings.Split(statement, string(lineEnd))
+ byteOffset := 0
+ scanner := func() (string, int, error) {
+ if len(s) > 0 {
+ z := s[0]
+ s = s[1:]
+ byteOffsetSnapshot := byteOffset
+ byteOffset += len(z)
+ if len(s) > 0 {
+ byteOffset += len(lineEnd)
+ }
+ return z, byteOffsetSnapshot, nil
+ }
+ return "", byteOffset, io.EOF
+ }
+ return scanner
+}
+
+type Batcher struct {
// read provides the next chunk of runes.
- read Scan
+ read scan
+ // beginByteOffset is the byte offset of the first byte of the current buffer in the original script.
+ beginByteOffset int
+ // firstByteOffset is the byte offset of the first byte of the current raw content in the original script.
+ firstByteOffset int
// buffer is the current batch text.
buffer []rune
// length is the length of the statement.
@@ -96,27 +131,33 @@ type Batch struct {
comment bool
}
-// NewBatch returns a new Batch.
-func NewBatch(read Scan) *Batch {
- return &Batch{
- read: read,
+// NewBatcher returns a new Batch.
+func NewBatcher(statement string) *Batcher {
+ scanner := newDefaultScan(statement)
+ return &Batcher{
+ read: scanner,
}
}
-// String returns the current SQL batch next.
-func (b *Batch) String() string {
- return string(b.buffer)
+// Batch returns the current SQL batch text.
+func (b *Batcher) Batch() *Batch {
+ return &Batch{
+ Text: string(b.buffer),
+ Start: b.beginByteOffset,
+ End: b.beginByteOffset + len(b.buffer),
+ }
}
// Next returns the next command in the batch.
-func (b *Batch) Next() (Command, error) {
+func (b *Batcher) Next() (Command, error) {
var i int
if b.rawLen == 0 {
- s, err := b.read()
+ s, firstByteOffset, err := b.read()
if err != nil {
return nil, err
}
+ b.firstByteOffset = firstByteOffset
b.raw = []rune(s)
b.rawLen = len(b.raw)
}
@@ -196,11 +237,12 @@ parse:
//
// After a call to append, b.Len will be len(b.Buf)+len(sep)+len(r). Call Reset
// to reset the Buf.
-func (b *Batch) append(r, sep []rune) {
+func (b *Batcher) append(r, sep []rune) {
rlen := len(r)
// initial
if b.buffer == nil {
b.buffer, b.length = r, rlen
+ b.beginByteOffset = b.firstByteOffset
return
}
blen, seplen := b.length, len(sep)
@@ -223,7 +265,7 @@ func (b *Batch) append(r, sep []rune) {
// or not the string's end was found.
// If the string's terminator was not found, then the result will be the passed
// end.
-func (*Batch) readString(r []rune, i, end int, quote rune) (int, bool) {
+func (*Batcher) readString(r []rune, i, end int, quote rune) (int, bool) {
var prev, c, next rune
for ; i < end; i++ {
c, next = r[i], grab(r, i+1, end)
@@ -243,7 +285,7 @@ func (*Batch) readString(r []rune, i, end int, quote rune) (int, bool) {
}
// Reset clears the current batch text and replaces it with new runes.
-func (b *Batch) Reset(r []rune) {
+func (b *Batcher) Reset(r []rune) {
b.buffer, b.length = nil, 0
b.quote = 0
b.comment = false
diff --git a/backend/plugin/parser/tsql/batch/batch_test.go b/backend/plugin/parser/tsql/batch/batch_test.go
index 39f0d3eaee..1d2f2cc1a5 100644
--- a/backend/plugin/parser/tsql/batch/batch_test.go
+++ b/backend/plugin/parser/tsql/batch/batch_test.go
@@ -3,7 +3,6 @@ package batch
import (
"io"
"os"
- "strings"
"testing"
"github.com/stretchr/testify/require"
@@ -50,7 +49,7 @@ func TestBuildGoCommands(t *testing.T) {
}
type batchResult struct {
- Statements string `yaml:"statements"`
+ Statements Batch `yaml:"statements"`
Command string `yaml:"command"`
}
@@ -95,25 +94,16 @@ func TestBatch(t *testing.T) {
}
func getBatchResults(a *require.Assertions, input string) []batchResult {
- s := strings.Split(input, "\n")
- scanner := func() (string, error) {
- if len(s) > 0 {
- z := s[0]
- s = s[1:]
- return z, nil
- }
- return "", io.EOF
- }
- batch := NewBatch(scanner)
+ batch := NewBatcher(input)
var batchResults []batchResult
for {
command, err := batch.Next()
if err != nil {
if err == io.EOF {
- if v := batch.String(); v != "" {
+ if v := batch.Batch(); v != nil && len(v.Text) > 0 {
// If meet the end of file, get the last batch.
batchResults = append(batchResults, batchResult{
- Statements: batch.String(),
+ Statements: *v,
})
}
batch.Reset(nil)
@@ -123,7 +113,7 @@ func getBatchResults(a *require.Assertions, input string) []batchResult {
}
if command != nil {
batchResults = append(batchResults, batchResult{
- Statements: batch.String(),
+ Statements: *batch.Batch(),
Command: command.String(),
})
batch.Reset(nil)
diff --git a/backend/plugin/parser/tsql/batch/testdata/test_batch.yaml b/backend/plugin/parser/tsql/batch/testdata/test_batch.yaml
index 453e4bf30f..f9fb92fa58 100644
--- a/backend/plugin/parser/tsql/batch/testdata/test_batch.yaml
+++ b/backend/plugin/parser/tsql/batch/testdata/test_batch.yaml
@@ -1,484 +1,17 @@
-- input: |-
- USE [smp_inv]
- GO
- /****** Object: StoredProcedure [dbo].[user_script_2] Script Date: 2023/11/30 17:27:18 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- -- =============================================
- -- Author: Bytebase
- -- Create date: 2023-11-30
- -- Description: Adjust
- -- =============================================
- CREATE PROCEDURE [dbo].[user_script_2]
- @TenantCode VARCHAR(20),
- @OrgId VARCHAR(10), -- Organization Id
- -- @StoreCode VARCHAR(20), -- Store Code
- -- @GoodsGid INT, -- Goods Id
- @GoodsCode CHAR(8), -- 8-digit Goods Code
- @BarCode VARCHAR(20), -- International Bar Code
- @GoodsName VARCHAR(50), -- Goods Name
- @SrcChannel VARCHAR(30), -- Source Channel
- @BillType VARCHAR(10), -- Business Type
- @BillNo VARCHAR(50), -- Bill Number
- @BeginTime DATETIME, -- Start Time
- @EndTime DATETIME, -- End Time
- @Sorting VARCHAR(50), -- Sorting
- @SkipCount INT, -- Skip Count
- @MaxResultCount INT -- Maximum Result Count
- AS
- -- [Important] Template tags to generate dynamic scripts for different architectures
- BEGIN
- SET NOCOUNT ON;
- DECLARE @bts BIGINT,
- @ets BIGINT;
- IF ISNULL(@BeginTime, '') <> ''
- BEGIN
- SET @bts = CONCAT(DATEDIFF(SS, '1970-1-1 00:00:00', @BeginTime), '000');
- END;
- IF ISNULL(@EndTime, '') <> ''
- BEGIN
- SET @ets = CONCAT(DATEDIFF(SS, '1970-1-1 00:00:00', @EndTime), '000');
- END;
- -- Bill types
- IF OBJECT_ID('tempdb..#tp_bill_type') IS NOT NULL
- DROP TABLE #tp_bill_type;
- SELECT DISTINCT BillType,BillName INTO #tp_bill_type FROM t_cod_inv_bill_rule;
- -- Output total count
- SELECT COUNT(1)
- FROM smp_his.dbo.t_log_inv_flow flw WITH (NOLOCK)
- LEFT JOIN smp_mid..syst_smp_md_goods_basic_information_v1_0 md WITH (NOLOCK)
- ON md.myj_goods_id = flw.GoodsGid
- AND md.companycode=@TenantCode
- WHERE flw.OrgId = @OrgId
- AND flw.ChgOccQty <> 0
- AND
- (
- ISNULL(@GoodsCode, '') = ''
- OR flw.GoodsCode = @GoodsCode
- )
- AND
- (
- ISNULL(@BarCode, '') = ''
- OR md.goods_common_code = @BarCode
- )
- AND
- (
- ISNULL(@GoodsName, '') = ''
- OR md.myj_goods_chname LIKE CONCAT('%', @GoodsName, '%')
- )
- AND
- (
- ISNULL(@SrcChannel, '') = ''
- OR flw.SrcChannel = @SrcChannel
- )
- AND
- (
- ISNULL(@BillType, '') = ''
- OR flw.BillType = @BillType
- )
- AND
- (
- ISNULL(@BillNo, '') = ''
- OR flw.BillNo = @BillNo
- )
- AND
- (
- @bts IS NULL
- OR flw.OccurTime >= @bts
- )
- AND
- (
- @ets IS NULL
- OR flw.OccurTime <= @ets
- );
- -- Output data
- SELECT flw.OrgId,
- flw.OrgCode,
- flw.GoodsGid,
- flw.GoodsCode,
- md.goods_common_code AS BarCode,
- md.myj_goods_chname AS GoodsName,
- flw.BillType,
- bt.BillName,
- flw.BillNo,
- CASE
- WHEN flw.ChgOccQty > 0 THEN
- 'Inbound (Increase Inventory)'
- ELSE
- 'Outbound (Decrease Inventory)'
- END AS ChangeMsg,
- flw.ChgOccQty AS ChangeQty,
- flw.OccQtyBef AS QtyBef,
- flw.OccQtyAft AS QtyAft,
- flw.SrcChannel,
- flw.Remark,
- flw.Operator,
- flw.OccurTime,
- flw.CreationTime
- FROM smp_his.dbo.t_log_inv_flow flw WITH (NOLOCK)
- LEFT JOIN smp_mid..syst_smp_md_goods_basic_information_v1_0 md WITH (NOLOCK)
- ON md.myj_goods_id = flw.GoodsGid
- AND md.companycode=@TenantCode
- INNER JOIN #tp_bill_type bt ON bt.BillType = flw.BillType
- WHERE flw.OrgId = @OrgId
- AND flw.ChgOccQty <> 0
- AND
- (
- ISNULL(@GoodsCode, '') = ''
- OR flw.GoodsCode = @GoodsCode
- )
- AND
- (
- ISNULL(@BarCode, '') = ''
- OR md.goods_common_code = @BarCode
- )
- AND
- (
- ISNULL(@GoodsName, '') = ''
- OR md.myj_goods_chname LIKE CONCAT('%', @GoodsName, '%')
- )
- AND
- (
- ISNULL(@SrcChannel, '') = ''
- OR flw.SrcChannel = @SrcChannel
- )
- AND
- (
- ISNULL(@BillType, '') = ''
- OR flw.BillType = @BillType
- )
- AND
- (
- ISNULL(@BillNo, '') = ''
- OR flw.BillNo = @BillNo
- )
- AND
- (
- @bts IS NULL
- OR flw.OccurTime >= @bts
- )
- AND
- (
- @ets IS NULL
- OR flw.OccurTime <= @ets
- )
- ORDER BY flw.CreationTime DESC,
- flw.OrgId,
- flw.GoodsGid DESC OFFSET @SkipCount ROWS FETCH NEXT @MaxResultCount ROWS ONLY;
- END;
- GO
- description: Sanitize user script#2
- batches:
- - statements: USE [smp_inv]
- command: GO 1
- - statements: |-
- /****** Object: StoredProcedure [dbo].[user_script_2] Script Date: 2023/11/30 17:27:18 ******/
- SET ANSI_NULLS ON
- command: GO 1
- - statements: SET QUOTED_IDENTIFIER ON
- command: GO 1
- - statements: |-
- -- =============================================
- -- Author: Bytebase
- -- Create date: 2023-11-30
- -- Description: Adjust
- -- =============================================
- CREATE PROCEDURE [dbo].[user_script_2]
- @TenantCode VARCHAR(20),
- @OrgId VARCHAR(10), -- Organization Id
- -- @StoreCode VARCHAR(20), -- Store Code
- -- @GoodsGid INT, -- Goods Id
- @GoodsCode CHAR(8), -- 8-digit Goods Code
- @BarCode VARCHAR(20), -- International Bar Code
- @GoodsName VARCHAR(50), -- Goods Name
- @SrcChannel VARCHAR(30), -- Source Channel
- @BillType VARCHAR(10), -- Business Type
- @BillNo VARCHAR(50), -- Bill Number
- @BeginTime DATETIME, -- Start Time
- @EndTime DATETIME, -- End Time
- @Sorting VARCHAR(50), -- Sorting
- @SkipCount INT, -- Skip Count
- @MaxResultCount INT -- Maximum Result Count
- AS
- -- [Important] Template tags to generate dynamic scripts for different architectures
- BEGIN
- SET NOCOUNT ON;
- DECLARE @bts BIGINT,
- @ets BIGINT;
- IF ISNULL(@BeginTime, '') <> ''
- BEGIN
- SET @bts = CONCAT(DATEDIFF(SS, '1970-1-1 00:00:00', @BeginTime), '000');
- END;
- IF ISNULL(@EndTime, '') <> ''
- BEGIN
- SET @ets = CONCAT(DATEDIFF(SS, '1970-1-1 00:00:00', @EndTime), '000');
- END;
- -- Bill types
- IF OBJECT_ID('tempdb..#tp_bill_type') IS NOT NULL
- DROP TABLE #tp_bill_type;
- SELECT DISTINCT BillType,BillName INTO #tp_bill_type FROM t_cod_inv_bill_rule;
- -- Output total count
- SELECT COUNT(1)
- FROM smp_his.dbo.t_log_inv_flow flw WITH (NOLOCK)
- LEFT JOIN smp_mid..syst_smp_md_goods_basic_information_v1_0 md WITH (NOLOCK)
- ON md.myj_goods_id = flw.GoodsGid
- AND md.companycode=@TenantCode
- WHERE flw.OrgId = @OrgId
- AND flw.ChgOccQty <> 0
- AND
- (
- ISNULL(@GoodsCode, '') = ''
- OR flw.GoodsCode = @GoodsCode
- )
- AND
- (
- ISNULL(@BarCode, '') = ''
- OR md.goods_common_code = @BarCode
- )
- AND
- (
- ISNULL(@GoodsName, '') = ''
- OR md.myj_goods_chname LIKE CONCAT('%', @GoodsName, '%')
- )
- AND
- (
- ISNULL(@SrcChannel, '') = ''
- OR flw.SrcChannel = @SrcChannel
- )
- AND
- (
- ISNULL(@BillType, '') = ''
- OR flw.BillType = @BillType
- )
- AND
- (
- ISNULL(@BillNo, '') = ''
- OR flw.BillNo = @BillNo
- )
- AND
- (
- @bts IS NULL
- OR flw.OccurTime >= @bts
- )
- AND
- (
- @ets IS NULL
- OR flw.OccurTime <= @ets
- );
- -- Output data
- SELECT flw.OrgId,
- flw.OrgCode,
- flw.GoodsGid,
- flw.GoodsCode,
- md.goods_common_code AS BarCode,
- md.myj_goods_chname AS GoodsName,
- flw.BillType,
- bt.BillName,
- flw.BillNo,
- CASE
- WHEN flw.ChgOccQty > 0 THEN
- 'Inbound (Increase Inventory)'
- ELSE
- 'Outbound (Decrease Inventory)'
- END AS ChangeMsg,
- flw.ChgOccQty AS ChangeQty,
- flw.OccQtyBef AS QtyBef,
- flw.OccQtyAft AS QtyAft,
- flw.SrcChannel,
- flw.Remark,
- flw.Operator,
- flw.OccurTime,
- flw.CreationTime
- FROM smp_his.dbo.t_log_inv_flow flw WITH (NOLOCK)
- LEFT JOIN smp_mid..syst_smp_md_goods_basic_information_v1_0 md WITH (NOLOCK)
- ON md.myj_goods_id = flw.GoodsGid
- AND md.companycode=@TenantCode
- INNER JOIN #tp_bill_type bt ON bt.BillType = flw.BillType
- WHERE flw.OrgId = @OrgId
- AND flw.ChgOccQty <> 0
- AND
- (
- ISNULL(@GoodsCode, '') = ''
- OR flw.GoodsCode = @GoodsCode
- )
- AND
- (
- ISNULL(@BarCode, '') = ''
- OR md.goods_common_code = @BarCode
- )
- AND
- (
- ISNULL(@GoodsName, '') = ''
- OR md.myj_goods_chname LIKE CONCAT('%', @GoodsName, '%')
- )
- AND
- (
- ISNULL(@SrcChannel, '') = ''
- OR flw.SrcChannel = @SrcChannel
- )
- AND
- (
- ISNULL(@BillType, '') = ''
- OR flw.BillType = @BillType
- )
- AND
- (
- ISNULL(@BillNo, '') = ''
- OR flw.BillNo = @BillNo
- )
- AND
- (
- @bts IS NULL
- OR flw.OccurTime >= @bts
- )
- AND
- (
- @ets IS NULL
- OR flw.OccurTime <= @ets
- )
- ORDER BY flw.CreationTime DESC,
- flw.OrgId,
- flw.GoodsGid DESC OFFSET @SkipCount ROWS FETCH NEXT @MaxResultCount ROWS ONLY;
- END;
- command: GO 1
-- input: |-
- USE [run]
- GO
-
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER OFF
- GO
-
- if exists(select * from sys.objects where name = 'user_proc_01')
- drop proc user_proc_01
- go
-
- CREATE proc [dbo].[user_proc_01]
- @p_orgid dtorgid,
- @p_custid dtcustid,
- @p_flag dtkind
- as
-
- declare @serverid dtsno, @sysdate dtdate,@p_qsdm dtchar255
- declare @money_rmb dtkind, @money_hk dtkind
-
- select @money_rmb = dbo.convertmoneytype('RMB') --0
- select @money_hk = dbo.convertmoneytype('HK') --1
- declare @szAmarket dtkind,@szBmarket dtkind,@thirdAmarket dtkind, @thirdBmarket dtkind,@HGTmarket dtkind,@shBmarket dtkind
- select @szAmarket = dbo.convertmarket('SZAG') --0
- select @szBmarket = dbo.convertmarket('SZBG') --2
- select @shBmarket = dbo.convertmarket('SHBG') --3
- select @thirdAmarket = dbo.convertmarket('ZRA') --6
- select @thirdBmarket = dbo.convertmarket('ZRB') --7
- select @HGTmarket = dbo.convertmarket('HGT') --5
- select @serverid = 0
- select top 1 @sysdate = sysdate,@serverid = serverid from sysconfig
- select @p_qsdm = paravalue from dbo.mixedconfig where paraid = 'oes_zqgsdm_zy'
- select errorcode = 0 , errormsg = 'Success'
-
- begin
- select sum(cn.num) as num from(
- select count(1) as num
- from dbo.logasset a
- inner join dbo.custbaseinfo c on a.custid = c.custid and a.serverid = c.serverid
- where a.serverid = @serverid and a.digestid in (220000,221001)
- and a.bizdate = @sysdate and a.orgid = @p_orgid and a.custid = @p_custid
- union all
- select count(1) as num
- from dbo.logmateno a
- inner join dbo.custbaseinfo c on a.custid = c.custid and a.serverid = c.serverid
- where a.serverid = @serverid and a.bizdate = @sysdate and a.orgid = @p_orgid and a.custid = @p_custid
- union all
- select count(1) as num
- from dbo.logasset a
- inner join dbo.custbaseinfo c on a.custid = c.custid and a.serverid = c.serverid
- where a.digestid in(221008,221009,250163)
- and a.bizdate = @sysdate and a.serverid = @serverid
- and a.orgid = @p_orgid and a.custid = @p_custid) cn
-
-
- end
- return 0
-
- GO
- description: Sanitize user script#1
- batches:
- - statements: USE [run]
- command: GO 1
- - statements: |2-
-
- SET ANSI_NULLS ON
- command: GO 1
- - statements: SET QUOTED_IDENTIFIER OFF
- command: GO 1
- - statements: |2-
-
- if exists(select * from sys.objects where name = 'user_proc_01')
- drop proc user_proc_01
- command: GO 1
- - statements: |2
-
- CREATE proc [dbo].[user_proc_01]
- @p_orgid dtorgid,
- @p_custid dtcustid,
- @p_flag dtkind
- as
-
- declare @serverid dtsno, @sysdate dtdate,@p_qsdm dtchar255
- declare @money_rmb dtkind, @money_hk dtkind
-
- select @money_rmb = dbo.convertmoneytype('RMB') --0
- select @money_hk = dbo.convertmoneytype('HK') --1
- declare @szAmarket dtkind,@szBmarket dtkind,@thirdAmarket dtkind, @thirdBmarket dtkind,@HGTmarket dtkind,@shBmarket dtkind
- select @szAmarket = dbo.convertmarket('SZAG') --0
- select @szBmarket = dbo.convertmarket('SZBG') --2
- select @shBmarket = dbo.convertmarket('SHBG') --3
- select @thirdAmarket = dbo.convertmarket('ZRA') --6
- select @thirdBmarket = dbo.convertmarket('ZRB') --7
- select @HGTmarket = dbo.convertmarket('HGT') --5
- select @serverid = 0
- select top 1 @sysdate = sysdate,@serverid = serverid from sysconfig
- select @p_qsdm = paravalue from dbo.mixedconfig where paraid = 'oes_zqgsdm_zy'
- select errorcode = 0 , errormsg = 'Success'
-
- begin
- select sum(cn.num) as num from(
- select count(1) as num
- from dbo.logasset a
- inner join dbo.custbaseinfo c on a.custid = c.custid and a.serverid = c.serverid
- where a.serverid = @serverid and a.digestid in (220000,221001)
- and a.bizdate = @sysdate and a.orgid = @p_orgid and a.custid = @p_custid
- union all
- select count(1) as num
- from dbo.logmateno a
- inner join dbo.custbaseinfo c on a.custid = c.custid and a.serverid = c.serverid
- where a.serverid = @serverid and a.bizdate = @sysdate and a.orgid = @p_orgid and a.custid = @p_custid
- union all
- select count(1) as num
- from dbo.logasset a
- inner join dbo.custbaseinfo c on a.custid = c.custid and a.serverid = c.serverid
- where a.digestid in(221008,221009,250163)
- and a.bizdate = @sysdate and a.serverid = @serverid
- and a.orgid = @p_orgid and a.custid = @p_custid) cn
-
-
- end
- return 0
- command: GO 1
- input: |-
INSERT INTO T VALUES ('
Bytebase Inc.
');
description: Cross line string using `'` as quote.
batches:
- - statements: |-
- INSERT INTO T VALUES ('
- Bytebase Inc.
- ');
- command: ""
+ - statements:
+ text: |-
+ INSERT INTO T VALUES ('
+ Bytebase Inc.
+ ');
+ start: 0
+ end: 43
+ command: ""
- input: |-
SELECT * FROM T;
GO
@@ -486,10 +19,16 @@
GO
description: Multiple batches
batches:
- - statements: SELECT * FROM T;
- command: GO 1
- - statements: INSERT INTO T VALUES (1);
- command: GO 1
+ - statements:
+ text: SELECT * FROM T;
+ start: 0
+ end: 16
+ command: GO 1
+ - statements:
+ text: INSERT INTO T VALUES (1);
+ start: 20
+ end: 45
+ command: GO 1
- input: |-
/*
* Bytebase Inc.
@@ -499,32 +38,44 @@
INSERT INTO T VALUES (1);
description: Multi-line comment
batches:
- - statements: |-
- /*
- * Bytebase Inc.
- * Migration SQL File 2023/11/30
- * INSERT INTO XXX VALUES (1);
- */
- INSERT INTO T VALUES (1);
- command: ""
+ - statements:
+ text: |-
+ /*
+ * Bytebase Inc.
+ * Migration SQL File 2023/11/30
+ * INSERT INTO XXX VALUES (1);
+ */
+ INSERT INTO T VALUES (1);
+ start: 0
+ end: 109
+ command: ""
- input: |-
-- Migration SQL File 2023/11/30
INSERT INTO T VALUES (1);
description: ""
batches:
- - statements: |-
- -- Migration SQL File 2023/11/30
- INSERT INTO T VALUES (1);
- command: ""
+ - statements:
+ text: |-
+ -- Migration SQL File 2023/11/30
+ INSERT INTO T VALUES (1);
+ start: 0
+ end: 58
+ command: ""
- input: |-
SELECT * FROM T;
GO 2
description: Run a batch twice
batches:
- - statements: SELECT * FROM T;
- command: GO 2
+ - statements:
+ text: SELECT * FROM T;
+ start: 0
+ end: 16
+ command: GO 2
- input: SELECT * FROM T;
description: Simple statement
batches:
- - statements: SELECT * FROM T;
- command: ""
+ - statements:
+ text: SELECT * FROM T;
+ start: 0
+ end: 16
+ command: ""