public override void ReportLookupError(Lookup lookup, Type fail_type) { Dirty = true; if (fail_type == null) { Console.Error.WriteLine("Undefined name “{0}”. Lookup was as follows:", lookup.Name); } else { Console.Error.WriteLine("Non-frame type {1} while resolving name “{0}”. Lookup was as follows:", lookup.Name, fail_type); } var col_width = Math.Max((int)Math.Log(lookup.FrameCount, 10) + 1, 3); for (var name_it = 0; name_it < lookup.NameCount; name_it++) { col_width = Math.Max(col_width, lookup.GetName(name_it).Length); } for (var name_it = 0; name_it < lookup.NameCount; name_it++) { Console.Error.Write("│ {0}", lookup.GetName(name_it).PadRight(col_width, ' ')); } Console.Error.WriteLine("│"); for (var name_it = 0; name_it < lookup.NameCount; name_it++) { Console.Error.Write(name_it == 0 ? "├" : "┼"); for (var s = 0; s <= col_width; s++) { Console.Error.Write("─"); } } Console.Error.WriteLine("┤"); var seen = new Dictionary <SourceReference, bool>(); var known_frames = new Dictionary <Frame, string>(); var frame_list = new List <Frame>(); var null_text = "│ ".PadRight(col_width + 2, ' '); for (var frame_it = 0; frame_it < lookup.FrameCount; frame_it++) { for (var name_it = 0; name_it < lookup.NameCount; name_it++) { var frame = lookup[name_it, frame_it]; if (frame == null) { Console.Error.Write(null_text); continue; } if (!known_frames.ContainsKey(frame)) { frame_list.Add(frame); known_frames[frame] = frame_list.Count.ToString().PadRight(col_width, ' '); } Console.Error.Write("│ {0}", known_frames[frame]); } Console.Error.WriteLine("│"); } Console.Error.WriteLine("Lookup happened here:"); lookup.SourceReference.Write(Console.Error, " ", seen); for (var it = 0; it < frame_list.Count; it++) { Console.Error.WriteLine("Frame {0} defined:", it + 1); frame_list[it].SourceReference.Write(Console.Error, " ", seen); } }
/** * Report an error during lookup. */ public virtual void ReportLookupError(Lookup lookup) { ReportOtherError(lookup.SourceReference, String.Format("Undefined name “{0}”.", lookup.Name)); }
protected override bool Run() { if (connection == null) { new Lookup(task_master, source_ref, new [] { "connection" }, context).Notify(return_value => { if (return_value is ReflectedFrame) { Object backing = ((ReflectedFrame)return_value).Backing; if (backing is DbConnection) { connection = (DbConnection)backing; if (Interlocked.Decrement(ref interlock) == 0) { task_master.Slot(this); } return; } } task_master .ReportOtherError(source_ref, "Expected “connection” to come from “sql:” import."); }); new Lookup(task_master, source_ref, new [] { "sql_query" }, context).Notify(return_value => { if (return_value is Stringish) { query = return_value.ToString(); if (Interlocked.Decrement(ref interlock) == 0) { task_master.Slot(this); } return; } task_master.ReportOtherError(source_ref, string.Format( "Expected type Str for “sql_query”, but got {0}.", Stringish.NameForType(return_value.GetType()))); }); if (Interlocked.Decrement(ref interlock) > 0) { return(false); } } try { var command = connection.CreateCommand(); command.CommandType = System.Data.CommandType.Text; command.CommandText = query; var reader = command.ExecuteReader(); if (debug) { Console.WriteLine("SQL Query to {0}: {1}", connection, query); } NameChooser name_chooser = (rs, it) => TaskMaster.OrdinalNameStr(it); var retrievers = new List <Retriever>(); for (int col = 0; col < reader.FieldCount; col++) { var column = col; if (reader.GetName(col) == "ATTRNAME") { name_chooser = (rs, it) => rs.GetString(column); continue; } if (reader.GetName(col).StartsWith("$")) { var attr_name = reader.GetName(col).Substring(1); if (!task_master.VerifySymbol(source_ref, attr_name)) { return(false); } retrievers.Add((rs, frame) => frame.Set(attr_name, rs.IsDBNull(column) ? Precomputation.Capture(Unit.NULL) : Lookup.Do(rs.GetString(column).Split('.')))); continue; } Unpacker unpacker; if (!unpackers.TryGetValue(reader.GetFieldType(col), out unpacker)) { task_master .ReportOtherError( source_ref, string.Format( "Cannot convert SQL type “{0}” for column “{1}” into Flabbergast type.", reader.GetFieldType(col), reader.GetName(col))); } if (!task_master.VerifySymbol(source_ref, reader.GetName(col))) { return(false); } retrievers.Add(Bind(reader.GetName(col), col, unpacker)); } var list = new MutableFrame(task_master, source_ref, context, self); for (int it = 1; reader.Read(); it++) { var frame = new MutableFrame(task_master, source_ref, list.Context, list); foreach (var r in retrievers) { r(reader, frame); } list.Set(name_chooser(reader, it), frame); } result = list; return(true); } catch (DataException e) { task_master.ReportOtherError(source_ref, e.Message); return(false); } }