private Dictionary<string, GenericField> GetTableDef() { if (mAllTableDefs == null) DoOnetimeInits(); if (mAllTableDefs.ContainsKey(mFullTablePath)) return mAllTableDefs[mFullTablePath]; bool HasIdField = false; //remove brakets string tableName = mTableName.Substring(1, mTableName.Length - 2); string sel = "select a.name,a.length,a.xtype,a.colstat, a.iscomputed from syscolumns as a " + "inner join sysobjects as b on a.id = b.id " + "where b.name = '" + tableName + "'"; Dictionary<string, GenericField> def = new Dictionary<string, GenericField>(); mHasIdentityCache[mFullTablePath] = false; DataTable oResult = mSqlUtil.ExecuteSingleResultSetSQLQuery(sel); Type DbtypeEnum = typeof(MyDbTypes); foreach (DataRow oRow in oResult.Rows) { if (oRow["name"].Equals(mIdColumn)) { mIdColumnHash[mFullTablePath] = mIdColumn; HasIdField = true; if ((short)oRow["colstat"] == 1 || (short)oRow["colstat"] == 9) mHasIdentityCache[mFullTablePath] = true; } else { GenericField f = new GenericField(); f.mType = (byte)oRow["xtype"]; f.mLength = (short)oRow["length"]; if (!Enum.IsDefined(DbtypeEnum, f.mType)) throw new Exception(mFullTablePath + ":undefined DBtype " + f.mType + " for field " + (string)oRow["name"]); f.mEncrypted = DBMetaData.isColumnEncrypted(mFullTablePath, (string)oRow["name"]); if (f.mEncrypted && (f.mType != (int)MyDbTypes.String && f.mType != (int)MyDbTypes.Image)) { throw new Exception(mFullTablePath + ":Column " + (string)oRow["name"] + " is not type varchar and cannot be set as an encrypted column."); } def[(string)oRow["name"]] = f; if ((int)oRow["iscomputed"] == 1) { f.mReadOnly = true; } } } if (!HasIdField) return null; mAllTableDefs[mFullTablePath] = def; return def; }
private void EncryptCol(ref object FieldValue, GenericField gf, string FieldName) { switch (gf.mType) { case (int)MyDbTypes.String: FieldValue = EncryptionUtil.SimpleEncrypt((string)mData[FieldName], FieldName); break; case (int)MyDbTypes.Image: FieldValue = EncryptionUtil.SimpleEncrypt((byte[])mData[FieldName], FieldName); break; } }