Exemplo n.º 1
0
        public Table GetPrimitiveTable(string tableName, BangDBPrimitiveDataType dataType = BangDBPrimitiveDataType.PrimitiveLong, DBOpenType flag = DBOpenType.Opencreate, TableEnv tblEnv = null)
        {
            IntPtr _tblenv = tblEnv == null ? IntPtr.Zero : tblEnv.GetHandle();
            IntPtr _tbl    = BangDBNative.GetPrimitiveTable(_database, tableName, (int)dataType, (int)flag, _tblenv);

            return((_tbl != IntPtr.Zero) ? new Table(tableName, _tbl) : null);
        }
Exemplo n.º 2
0
        public unsafe ResultSet ScanDoc(string idxName, string skey, string ekey, ScanFilter sf, DataVar dv)
        {
            ScanFilterStruct sfs   = sf.sfs;
            long *           sfptr = (long *)&sfs;
            int sklen = (skey != null) ? skey.Length : 0;
            int eklen = (ekey != null) ? ekey.Length : 0;

            IntPtr pBuf   = dv.bufferPointer;
            int    buflen = dv.bufferLength;
            int    dlen   = dv.dataLength;
            int    dofft  = dv.dataOffset;
            int    eflag  = (int)dv.opsFlag;

            IntPtr rsptr = BangDBNative.Scan_Doc_Idx_DV(_wconnection, idxName, skey, sklen, ekey, eklen, (IntPtr)sfptr, pBuf, buflen, ref dlen, dofft, ref eflag);

            dv.opsFlag       = (BangDBDataOpsFlag)eflag;
            dv.bufferPointer = pBuf;
            dv.dataLength    = dlen;

            if (rsptr == IntPtr.Zero)
            {
                return(null);
            }
            sf.skeyOp     = sfs.skeyOp;
            sf.ekeyOp     = sfs.ekeyOp;
            sf.skip_count = sfs.skip_count;
            return(new ResultSet(rsptr));
        }
Exemplo n.º 3
0
 public static unsafe int CompareBuffers(byte[] buffer1, int offset1, byte[] buffer2, int offset2, int count)
 {
     fixed(byte *b1 = buffer1, b2 = buffer2)
     {
         return(BangDBNative.memcmp(b1 + offset1, b2 + offset2, count));
     }
 }
Exemplo n.º 4
0
        public unsafe ResultSet Scan(byte[] skey, byte[] ekey, Transaction txn, ScanFilter sf, DataVar dv)
        {
            ScanFilterStruct sfs   = sf.sfs;
            long *           sfptr = (long *)&sfs;

            IntPtr pBuf   = dv.bufferPointer;
            int    buflen = dv.bufferLength;
            int    dlen   = dv.dataLength;
            int    dofft  = dv.dataOffset;
            int    eflag  = (int)dv.opsFlag;

            IntPtr rsptr = BangDBNative.Scan_DV_TranW(_wconnection, skey, skey.Length, ekey, ekey.Length, txn.GetTranPtr(), (IntPtr)sfptr, pBuf, buflen, ref dlen, dofft, ref eflag);

            dv.opsFlag       = (BangDBDataOpsFlag)eflag;
            dv.bufferPointer = pBuf;
            dv.dataLength    = dlen;

            if (rsptr == IntPtr.Zero)
            {
                return(null);
            }
            sf.skeyOp     = sfs.skeyOp;
            sf.ekeyOp     = sfs.ekeyOp;
            sf.skip_count = sfs.skip_count;
            return(new ResultSet(rsptr));
        }
Exemplo n.º 5
0
 public int CloseTable(DBCloseType flag = DBCloseType.Default)
 {
     int r = BangDBNative.CloseThisTable(_table, (int)flag);
     BangDBNative.FreeHandle(ref _table);
     _table = IntPtr.Zero;
     return r;
 }
Exemplo n.º 6
0
        public WideTable GetWideTable(string tableName, DBOpenType flag = DBOpenType.Opencreate, TableEnv tblEnv = null)
        {
            IntPtr _tblenv = tblEnv == null ? IntPtr.Zero : tblEnv.GetHandle();
            IntPtr _tbl    = BangDBNative.GetWideTable(_database, tableName, (int)flag, _tblenv);

            return((_tbl != IntPtr.Zero) ? new WideTable(tableName, _tbl) : null);
        }
Exemplo n.º 7
0
 public int CloseConnection(Connection conn)
 {
     IntPtr _conn = conn.GetHandle();
     int r = BangDBNative.CloseTableConnection(_table, _conn);
     BangDBNative.FreeHandle(ref _conn);
     return r;
 }
Exemplo n.º 8
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         BangDBNative.FreeHandle(ref _txn);
         _txn = IntPtr.Zero;
     }
 }
Exemplo n.º 9
0
 public long Del(string key)
 {
     if (key == null)
     {
         throw new Exception("key can't be null");
     }
     return(BangDBNative.Del(_connection, key, key.Length));
 }
Exemplo n.º 10
0
        public int CloseTable(WideTable wtbl, DBCloseType flag = DBCloseType.Default)
        {
            IntPtr _tblhandle = wtbl.GetHandle();
            int    retval     = BangDBNative.CloseWideTableHandle(_database, _tblhandle, (int)flag);

            _tblhandle = IntPtr.Zero;
            return(retval);
        }
Exemplo n.º 11
0
        public int CloseConnection()
        {
            int r = BangDBNative.CloseConnectionW(_wconnection);

            BangDBNative.FreeHandle(ref _wconnection);
            _wconnection = IntPtr.Zero;
            return(r);
        }
Exemplo n.º 12
0
        public bool Get(int key, ref int val)
        {
            long _val = val;
            int  r    = BangDBNative.GetPrim(_connection, (long)key, ref _val);

            val = (int)_val;
            return(r < 0 ? false : true);
        }
Exemplo n.º 13
0
 public long Put(string key, byte[] val, InsertOptions flag)
 {
     if (key == null || val == null)
     {
         throw new Exception("key or/and val can't be null");
     }
     return(BangDBNative.Put(_connection, key, key.Length, val, val.Length, (int)flag));
 }
Exemplo n.º 14
0
 public long Del(string key, Transaction txn)
 {
     if (key == null)
     {
         throw new Exception("key can't be null");
     }
     return(BangDBNative.Del_Tran(_connection, key, key.Length, txn.GetTranPtr()));
 }
Exemplo n.º 15
0
 public long Del(byte[] key)
 {
     if (key == null)
     {
         throw new Exception("key can't be null");
     }
     return(BangDBNative.DelPrim_Byte(_connection, key, key.Length));
 }
Exemplo n.º 16
0
 public long Put(byte[] key, string val, InsertOptions flag, Transaction txn)
 {
     if (key == null || val == null)
     {
         throw new Exception("key or/and val can't be null");
     }
     return(BangDBNative.Put_Tran(_connection, key, key.Length, val, val.Length, (int)flag, txn.GetTranPtr()));
 }
Exemplo n.º 17
0
 public void CloseDatabase(DBCloseType flag = DBCloseType.Default)
 {
     if (_dbState)
     {
         BangDBNative.CloseDatabase(_database, (int)flag);
     }
     _dbState  = false;
     _database = IntPtr.Zero;
 }
Exemplo n.º 18
0
        public ResultSet ScanRemaining(long fromTime, int lag)
        {
            IntPtr rs = BangDBNative.ScanRemainingSWTable(_swTable, fromTime, lag);

            if (rs == null)
            {
                return(null);
            }
            return(new ResultSet(rs));
        }
Exemplo n.º 19
0
        public ResultSet ScanFull()
        {
            IntPtr rs = BangDBNative.ScanFullSWTable(_swTable);

            if (rs == null)
            {
                return(null);
            }
            return(new ResultSet(rs));
        }
Exemplo n.º 20
0
        public ResultSet Scan(int period, int lag)
        {
            IntPtr rs = BangDBNative.ScanLagSWTable(_swTable, period, lag);

            if (rs == null)
            {
                return(null);
            }
            return(new ResultSet(rs));
        }
Exemplo n.º 21
0
        public string GetTopKJson(int k = 0)
        {
            IntPtr str = IntPtr.Zero;

            BangDBNative.GetTopkJson(_topk, out str, k);
            string jstr = Marshal.PtrToStringAnsi(str);

            BangDBNative.FreeHandle(ref str);
            return(jstr);
        }
Exemplo n.º 22
0
        public WideConnection GetConnection()
        {
            IntPtr wconnptr = BangDBNative.GetWideConnection(_wtable);

            if (wconnptr == null)
            {
                return(null);
            }
            return(new WideConnection(wconnptr));
        }
Exemplo n.º 23
0
        public string ListCount_Str()
        {
            IntPtr list = IntPtr.Zero;

            BangDBNative.ListCount2SWEntity(_swentity, out list);
            string str = Marshal.PtrToStringAnsi(list);

            BangDBNative.FreeHandle(ref list);
            return(str);
        }
Exemplo n.º 24
0
 public Connection GetConnection()
 {
     if (GetTableType() != BangDBTableType.NormalTable)
     {
         Common.BangDBLogger("error - the table type (BangDBTableType) is not NormalTable");
         return null;
     }
     IntPtr _conn = BangDBNative.GetConnection(_table);
     Connection conn = new Connection(_conn);
     return conn;
 }
Exemplo n.º 25
0
        public int[] List(int span)
        {
            int[] list      = null;
            int   list_size = 0;

            if (BangDBNative.ListSWCount(_swsc, span, ref list, ref list_size, (int)BangDBWindowType.SlidingWindowUnit) < 0)
            {
                return(null);
            }
            return(list);
        }
Exemplo n.º 26
0
        public unsafe long Count(long skey, long ekey, ScanFilter sf)
        {
            ScanFilterStruct sfs   = sf.sfs;
            long *           sfptr = (long *)&sfs;
            long             rc    = BangDBNative.Count_LongW(_wconnection, skey, ekey, (IntPtr)sfptr);

            sf.skeyOp     = sfs.skeyOp;
            sf.ekeyOp     = sfs.ekeyOp;
            sf.skip_count = sfs.skip_count;
            return(rc);
        }
Exemplo n.º 27
0
        public unsafe long Count(int sk, int ek, ScanFilter sf)
        {
            ScanFilterStruct sfs   = sf.sfs;
            long *           sfptr = (long *)&sfs;
            long             rc    = BangDBNative.Count_LONG(_connection, sk, ek, (IntPtr)sfptr);

            sf.skeyOp     = sfs.skeyOp;
            sf.ekeyOp     = sfs.ekeyOp;
            sf.skip_count = sfs.skip_count;
            return(rc);
        }
Exemplo n.º 28
0
 public PrimConnection GetPrimConnection()
 {
     BangDBTableType tp = GetTableType();
     if (tp != BangDBTableType.PrimitiveTableInt && tp != BangDBTableType.PrimitiveTableLong && tp != BangDBTableType.PrimitiveTableString)
     {
         Common.BangDBLogger("error - the table type (BangDBTableType) is not primitive type");
         return null;
     }
     IntPtr _conn = BangDBNative.GetPrimConnection(_table);
     PrimConnection conn = new PrimConnection(_conn);
     return conn;
 }
Exemplo n.º 29
0
        public bool GetNextKey(out string key)
        {
            IntPtr kptr;
            int    klen;

            if (BangDBNative.GetNextKey(_rs, out kptr, out klen) < 0)
            {
                key = null;
                return(false);
            }
            key = Marshal.PtrToStringAnsi(kptr, klen);
            return(true);
        }
Exemplo n.º 30
0
        public unsafe long Count(byte[] skey, byte[] ekey, ScanFilter sf)
        {
            ScanFilterStruct sfs   = sf.sfs;
            long *           sfptr = (long *)&sfs;
            int  sklen             = (skey != null) ? skey.Length : 0;
            int  eklen             = (ekey != null) ? ekey.Length : 0;
            long rc = BangDBNative.CountW(_wconnection, skey, sklen, ekey, eklen, (IntPtr)sfptr);

            sf.skeyOp     = sfs.skeyOp;
            sf.ekeyOp     = sfs.ekeyOp;
            sf.skip_count = sfs.skip_count;
            return(rc);
        }