public override bool SerializeContent(ddl db, Stream destination) { DataSet ds; /* obtain */ try { using (var p = new commandadhoc(db, new selectstatement( /* leave out the actual binary */ new selectlist() { new selectfield("BinID"), new selectfield("iMIME"), new selectfield("sMIME"), new selectfield("LCID"), new selectfield("URI"), new selectfield("Filename"), new selectfield("Label"), new selectliteral(new literal(new Byte[] { 0 }, DbType.Object, 0), "Chunk"), new selectfield("OriginalSizeBytes"), /* added [dlatikay 20120203] */ new selectfield("EOK"), new selectfield("Compression"), new selectfield("crea_who"), new selectfield("crea_when") }, new tableexpressions(this.GetType()), null, null ))) { using (var table = p.ExecuteSelectToNew()) { /* prepare */ if (table.DataSet == null) { ds = new DataSet(); ds.Tables.Add(table); } else { ds = table.DataSet; } /* serialize */ ds.RemotingFormat = SerializationFormat.Binary; BinaryFormatter fmt = new BinaryFormatter(); fmt.Serialize(destination, ds); } } /* succeeded */ return(true); } catch (Exception ex) { /* something went wrong */ throw new DALException("failed to serialize " + TableName + ": " + ex.Message, ex); } }
/// <summary> /// When this is first called, OT and OK must already have been set /// </summary> internal virtual void Flush(Iddl db, string fieldname, object val_before, object val_after) { /* 1. do we need to get a new number? */ if (know_next_id_in_trans <= 0) { know_next_id_in_trans = 0; using (var p = new commandadhoc(db, new selectstatement( /* flexible, honoring the instance */ new selectlist() { new selectfield(selectfunctiondef.max, "L", "LogID") }, new tableexpressions(this.GetType(), "L"), null, null, null, null, null ))) { using (var table = p.ExecuteSelectToNew()) { if (table != null) { if (table.Rows.Count == 1) { if (!table.Rows[0][0].Equals(DBNull.Value)) { know_next_id_in_trans = Convert.ToInt32(table.Rows[0][0]); } } } } } } LogID = ++know_next_id_in_trans; /* 2. set the values */ Fieldname = fieldname; /* snapshot before */ var valBefore = val_before as string; sVal_Before = (valBefore != null) ? (valBefore.Length > 255 ? valBefore.Substring(0, 255) : valBefore) : null; mVal_Before = (valBefore != null) ? (valBefore.Length > 255 ? valBefore : null) : null; iVal_Before = (val_before is Int32) ? (int?)Convert.ToInt32(val_before) : null; cVal_Before = (val_before is decimal) ? (decimal?)Convert.ToDecimal(val_before) : null; dVal_Before = (val_before is DateTime) ? (DateTime?)Convert.ToDateTime(val_before) : null; /* snapshot after */ sVal = (val_after is string) ? ((val_after as string).Length > 255 ? (val_after as string).Substring(0, 255) : val_after as string) : null; mVal = (val_after is string) ? ((val_after as string).Length > 255 ? (val_after as string) : null) : null; iVal = (val_after is Int32) ? (int?)Convert.ToInt32(val_after) : null; cVal = (val_after is decimal) ? (decimal?)Convert.ToDecimal(val_after) : null; dVal = (val_after is DateTime) ? (DateTime?)Convert.ToDateTime(val_after) : null; /* add this */ DbInsert(db as ddl); }
/// <summary> /// Especially useful for the binary tables, which contain huge chunks (files) /// </summary> private void CopyBinRowwise(ddl db1, ddl db2, string tablename) { var binids_to_copy = new List <int>(); Istatement sel_keys = new plainselect( new string[] { "BinID" }, tablename ); using (var p = new commandadhoc(db1, sel_keys)) { using (var table = p.ExecuteSelectToNew()) { foreach (DataRow dr in table.Rows) { binids_to_copy.Add(Convert.ToInt32(dr[0])); } } } /* prepare a command which selects the data from a row */ /* -!!- continue here if time, ever * when ready, undo commenting out call in above function */ }