gitee.com/curryzheng/dm@v0.0.1/zo.go (about)

     1  /*
     2   * Copyright (c) 2000-2018, 达梦数据库有限公司.
     3   * All rights reserved.
     4   */
     5  package dm
     6  
     7  const (
     8  	LOB_FLAG_BYTE = 0
     9  	LOB_FLAG_CHAR = 1
    10  
    11  	LOB_IN_ROW  = 0x1
    12  	LOB_OFF_ROW = 0x2
    13  
    14  	NBLOB_HEAD_IN_ROW_FLAG = 0
    15  	NBLOB_HEAD_BLOBID      = NBLOB_HEAD_IN_ROW_FLAG + BYTE_SIZE
    16  	NBLOB_HEAD_BLOB_LEN    = NBLOB_HEAD_BLOBID + DDWORD_SIZE
    17  
    18  	NBLOB_HEAD_OUTROW_GROUPID = NBLOB_HEAD_BLOB_LEN + ULINT_SIZE
    19  	NBLOB_HEAD_OUTROW_FILEID  = NBLOB_HEAD_OUTROW_GROUPID + USINT_SIZE
    20  	NBLOB_HEAD_OUTROW_PAGENO  = NBLOB_HEAD_OUTROW_FILEID + USINT_SIZE
    21  
    22  	NBLOB_EX_HEAD_TABLE_ID   = NBLOB_HEAD_OUTROW_PAGENO + ULINT_SIZE
    23  	NBLOB_EX_HEAD_COL_ID     = NBLOB_EX_HEAD_TABLE_ID + ULINT_SIZE
    24  	NBLOB_EX_HEAD_ROW_ID     = NBLOB_EX_HEAD_COL_ID + USINT_SIZE
    25  	NBLOB_EX_HEAD_FPA_GRPID  = NBLOB_EX_HEAD_ROW_ID + LINT64_SIZE
    26  	NBLOB_EX_HEAD_FPA_FILEID = NBLOB_EX_HEAD_FPA_GRPID + USINT_SIZE
    27  	NBLOB_EX_HEAD_FPA_PAGENO = NBLOB_EX_HEAD_FPA_FILEID + USINT_SIZE
    28  	NBLOB_EX_HEAD_SIZE       = NBLOB_EX_HEAD_FPA_PAGENO + ULINT_SIZE
    29  
    30  	NBLOB_OUTROW_HEAD_SIZE = NBLOB_HEAD_OUTROW_PAGENO + ULINT_SIZE
    31  
    32  	NBLOB_INROW_HEAD_SIZE = NBLOB_HEAD_BLOB_LEN + ULINT_SIZE
    33  )
    34  
    35  type lob struct {
    36  	blobId int64
    37  	inRow  bool
    38  
    39  	groupId   int16
    40  	fileId    int16
    41  	pageNo    int32
    42  	tabId     int32
    43  	colId     int16
    44  	rowId     int64
    45  	exGroupId int16
    46  	exFileId  int16
    47  	exPageNo  int32
    48  
    49  	curFileId     int16
    50  	curPageNo     int32
    51  	curPageOffset int16
    52  	totalOffset   int32
    53  	readOver      bool
    54  
    55  	connection       *DmConnection
    56  	local            bool
    57  	updateable       bool
    58  	lobFlag          int8
    59  	length           int64
    60  	compatibleOracle bool
    61  	fetchAll         bool
    62  	freed            bool
    63  	modify           bool
    64  
    65  	Valid bool
    66  }
    67  
    68  func (lob *lob) GetLength() (int64, error) {
    69  	var err error
    70  	if err = lob.checkValid(); err != nil {
    71  		return -1, err
    72  	}
    73  	if err = lob.checkFreed(); err != nil {
    74  		return -1, err
    75  	}
    76  	if lob.length == -1 {
    77  
    78  		if lob.length, err = lob.connection.Access.dm_build_849(lob); err != nil {
    79  			return -1, err
    80  		}
    81  	}
    82  	return lob.length, nil
    83  }
    84  
    85  func (lob *lob) resetCurrentInfo() {
    86  	lob.curFileId = lob.fileId
    87  	lob.curPageNo = lob.pageNo
    88  	lob.totalOffset = 0
    89  	lob.curPageOffset = 0
    90  }
    91  
    92  func (lob *lob) getLengthFromHead(head []byte) int64 {
    93  	return int64(Dm_build_1.Dm_build_103(head, NBLOB_HEAD_BLOB_LEN))
    94  }
    95  
    96  func (lob *lob) canOptimized(connection *DmConnection) bool {
    97  	return !(lob.inRow || lob.fetchAll || lob.local || connection != lob.connection)
    98  }
    99  
   100  func (lob *lob) buildCtlData() (bytes []byte) {
   101  	if lob.connection.NewLobFlag {
   102  		bytes = make([]byte, NBLOB_EX_HEAD_SIZE, NBLOB_EX_HEAD_SIZE)
   103  	} else {
   104  		bytes = make([]byte, NBLOB_OUTROW_HEAD_SIZE, NBLOB_OUTROW_HEAD_SIZE)
   105  	}
   106  	Dm_build_1.Dm_build_2(bytes, NBLOB_HEAD_IN_ROW_FLAG, LOB_OFF_ROW)
   107  	Dm_build_1.Dm_build_22(bytes, NBLOB_HEAD_BLOBID, lob.blobId)
   108  	Dm_build_1.Dm_build_17(bytes, NBLOB_HEAD_BLOB_LEN, -1)
   109  
   110  	Dm_build_1.Dm_build_12(bytes, NBLOB_HEAD_OUTROW_GROUPID, lob.groupId)
   111  	Dm_build_1.Dm_build_12(bytes, NBLOB_HEAD_OUTROW_FILEID, lob.fileId)
   112  	Dm_build_1.Dm_build_17(bytes, NBLOB_HEAD_OUTROW_PAGENO, lob.pageNo)
   113  
   114  	if lob.connection.NewLobFlag {
   115  		Dm_build_1.Dm_build_17(bytes, NBLOB_EX_HEAD_TABLE_ID, lob.tabId)
   116  		Dm_build_1.Dm_build_12(bytes, NBLOB_EX_HEAD_COL_ID, lob.colId)
   117  		Dm_build_1.Dm_build_22(bytes, NBLOB_EX_HEAD_ROW_ID, lob.rowId)
   118  		Dm_build_1.Dm_build_12(bytes, NBLOB_EX_HEAD_FPA_GRPID, lob.exGroupId)
   119  		Dm_build_1.Dm_build_12(bytes, NBLOB_EX_HEAD_FPA_FILEID, lob.exFileId)
   120  		Dm_build_1.Dm_build_17(bytes, NBLOB_EX_HEAD_FPA_PAGENO, lob.exPageNo)
   121  	}
   122  	return
   123  }
   124  
   125  func (lob *lob) checkFreed() (err error) {
   126  	if lob.freed {
   127  		err = ECGO_LOB_FREED.throw()
   128  	}
   129  	return
   130  }
   131  
   132  func (lob *lob) checkValid() error {
   133  	if !lob.Valid {
   134  		return ECGO_IS_NULL.throw()
   135  	}
   136  	return nil
   137  }