public override DataObject CastTo(DataObject value, SqlType destType) { var xmlNode = value.Value as SqlXmlNode; if (xmlNode == null) { return(DataObject.Null(this)); } var destTypeCode = destType.TypeCode; switch (destTypeCode) { case SqlTypeCode.String: case SqlTypeCode.VarChar: case SqlTypeCode.LongVarChar: // TODO: more advanced casting... return(DataObject.String(xmlNode.ToSqlString())); case SqlTypeCode.Binary: case SqlTypeCode.LongVarBinary: case SqlTypeCode.VarBinary: // TODO: more advanced casting... return(DataObject.Binary(xmlNode.ToSqlBinary())); default: throw new InvalidCastException(String.Format("Cannot cast XML node to type '{0}'.", destType)); } }
public static DataObject ToWkb(DataObject geometry) { if (geometry.IsNull) { return(DataObject.Null(PrimitiveTypes.String())); } var g = (SqlGeometry)geometry.Value; return(DataObject.Binary(ToWkb(g))); }
public void CreateTrigger(TriggerInfo triggerInfo) { if (!transaction.TableExists(SystemSchema.TriggerTableName)) { return; } try { var args = new TriggerArgument(triggerInfo.Arguments.ToArray()); var binArgs = SerializeArguments(args); var schema = triggerInfo.TriggerName.ParentName; var name = triggerInfo.TriggerName.Name; var type = (int)triggerInfo.TriggerType; var onTable = triggerInfo.TableName == null ? null : triggerInfo.TableName.FullName; var procedureName = triggerInfo.ProcedureName != null ? triggerInfo.ProcedureName.FullName : null; var action = (int)triggerInfo.EventType; // TODO: if the trigger has a body, create a special procedure and set the name // Insert the entry into the trigger table, var table = transaction.GetMutableTable(SystemSchema.TriggerTableName); var row = table.NewRow(); row.SetValue(0, DataObject.String(schema)); row.SetValue(1, DataObject.String(name)); row.SetValue(2, DataObject.Integer(type)); row.SetValue(3, DataObject.String(onTable)); row.SetValue(4, DataObject.Integer(action)); row.SetValue(5, DataObject.String(procedureName)); row.SetValue(6, DataObject.Binary(binArgs)); table.AddRow(row); InvalidateTriggerCache(); transaction.Registry.RegisterEvent(new ObjectCreatedEvent(triggerInfo.TriggerName, DbObjectType.Trigger)); tableModified = true; } catch (Exception) { // TODO: use a specialized exception throw; } }
public void DefineView(ViewInfo viewInfo) { if (viewInfo == null) { throw new ArgumentNullException("viewInfo"); } var dataTableInfo = viewInfo.TableInfo; var viewTable = Transaction.GetMutableTable(SystemSchema.ViewTableName); var viewName = dataTableInfo.TableName; var query = viewInfo.QueryExpression; var viewInfoData = viewInfo.AsBinary(); // Create the view record var rdat = viewTable.NewRow(); rdat.SetValue(0, dataTableInfo.SchemaName.Name); rdat.SetValue(1, dataTableInfo.Name); rdat.SetValue(2, query.ToString()); rdat.SetValue(3, DataObject.Binary(viewInfoData)); // Find the entry from the view that equals this name var t = FindViewEntry(viewName); // Delete the entry if it already exists. if (t.RowCount == 1) { viewTable.Delete(t); } // Insert the new view entry in the system view table viewTable.AddRow(rdat); // Notify that this database object has been successfully created. Transaction.Registry.RegisterEvent(new ObjectCreatedEvent(viewName, DbObjectType.View)); // Change to the view table viewTableChanged = true; }
public void SetValue(int columnIndex, SqlBinary binary) { SetValue(columnIndex, DataObject.Binary(binary)); }
public void SetValue(int columnIndex, byte[] bytes) { SetValue(columnIndex, DataObject.Binary(bytes)); }