示例#1
0
 public List <AUTHOR> List()  //Retrieves all authors
 {
     using (var db = new LibDb())
     {
         var query = db.AUTHORs.OrderBy(x => x.LastName);
         return(query.ToList());
     }
 }
示例#2
0
 public List <USER> List()  //Retrieves all books
 {
     using (var db = new LibDb())
     {
         var query = db.USERs.OrderBy(x => x.UserName);
         return(query.ToList());
     }
 }
示例#3
0
 public void Update(USER user)
 {
     using (var db = new LibDb())
     {
         db.USERs.Attach(user);
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#4
0
        // should be run in a CER, under a lock on rscLock, and not throw exceptions
        internal DbRetVal AllocateHandle(DB *dbp, UInt32 flags)
        {
            DbRetVal ret;

            lock (rscLock) {
                DB_SEQUENCE *seqp;
                ret = LibDb.db_sequence_create(out seqp, dbp, flags);
                if (ret == DbRetVal.SUCCESS)
                {
                    this.seqp          = seqp;
                    seqp->api_internal = (IntPtr)instanceHandle;
                }
            }
            return(ret);
        }
示例#5
0
        public SequenceStats GetStats(StatFlags flags)
        {
            SequenceStats     value;
            DB_SEQUENCE_STAT *sp;

            lock (rscLock) {
                DB_SEQUENCE *seqp = CheckDisposed();
                RuntimeHelpers.PrepareConstrainedRegions();
                try { }
                finally {
                    DbRetVal ret = seqp->Stat(seqp, out sp, unchecked ((UInt32)flags));
                    Util.CheckRetVal(ret);
                    value.seqStats = *sp;
                    LibDb.os_ufree(null, sp);
                }
            }
            return(value);
        }
示例#6
0
 public static void CheckRetVal(DbRetVal ret)
 {
     if (ret != DbRetVal.SUCCESS)
     {
         string errStr;
         if (ret > BdbLowError)
         {
             errStr = LibDb.db_strerror(ret);
         }
         else if (ret > DotNetLowError)
         {
             errStr = DotNetStr(ret);
         }
         else
         {
             errStr = UnknownStr(ret);
         }
         throw new BdbException(ret, errStr);
     }
 }
示例#7
0
 public void Delete(USER user)
 {
     using (var db = new LibDb())
     {
         using (DbContextTransaction transaction = db.Database.BeginTransaction())
         {
             db.USERs.Attach(user);
             try
             {
                 db.USERs.Remove(user);
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
             }
         }
     }
 }
示例#8
0
 public void Add(BOOK bookObj)
 {
     using (var db = new LibDb())
     {
         using (DbContextTransaction transaction = db.Database.BeginTransaction())
         {
             try
             {
                 foreach (var au in bookObj.AUTHORs)
                 {
                     db.AUTHORs.Attach(au);
                 }
                 db.BOOKs.Add(bookObj);  // Prepare query
                 db.SaveChanges();       // Run the query
                 transaction.Commit();   //  Permanent the result, writing to disc and closing transaction
             }
             catch (Exception ex)
             {
                 transaction.Rollback();  //Undo all changes if exception is thrown
             }
         }
     }
 }
示例#9
0
        public static void BufferToPtr(byte[] buffer, int start, int length, ref byte *ptr)
        {
            void *mem = ptr;

            // we pass null for the environment, as we don't want error call-backs
            // DbRetVal ret = LibDb.ReallocMem(null, (uint)length, ref mem);  // not exported
            if (ptr != null)
            {
                LibDb.os_ufree(null, mem);
            }
            DbRetVal ret;

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally {
                ret = LibDb.os_umalloc(null, (uint)length, out mem);
                if (ret == DbRetVal.SUCCESS)
                {
                    ptr = (byte *)mem;
                }
            }
            Util.CheckRetVal(ret);
            Marshal.Copy(buffer, start, (IntPtr)ptr, length);
        }
示例#10
0
 public static unsafe int Compare(Lsn lsn0, Lsn lsn1)
 {
     return(LibDb.log_compare(&lsn0.lsn, &lsn1.lsn));
 }