void _SysTablesXML(System.IO.Stream output) { string xml; using (GlobalCriticalSection.GetLock()) { xml = LoadSysTablesXml_unlocked(); } int ColLineLength = 1 + (200 * 2); foreach (string _line in xml.Split('\n')) { string line = _line.Trim('\n', '\r'); recordset rs = recordset.Prepare(); rs.PutByte(0); // Nullable byte. rs.PutString(line); { ByteSlice bs = rs.ToByteSlice(); if (bs.Length > ColLineLength) { throw new Exception("Column Line: length is too long: " + line); } for (int ibs = 0; ibs < bs.Length; ibs++) { output.WriteByte(bs[ibs]); } for (int ibs = bs.Length; ibs < DSpace_OutputRecordLength; ibs++) { output.WriteByte(0); } } } }
public static List <byte> NumberLiteralToTypeBuffer(string sNum, DbTypeID typeID, List <byte> buffer) { if (DbTypeID.INT == typeID) { Int32 x = Int32.Parse(sNum); if (null == buffer) { buffer = new List <byte>(1 + 4); } buffer.Clear(); buffer.Add(0); Entry.ToBytesAppend((Int32)Entry.ToUInt32(x), buffer); } else if (DbTypeID.LONG == typeID) { Int64 x = Int64.Parse(sNum); if (null == buffer) { buffer = new List <byte>(1 + 8); } buffer.Clear(); buffer.Add(0); Entry.ToBytesAppend64((Int64)Entry.ToUInt64(x), buffer); } else if (DbTypeID.DOUBLE == typeID) { double x = double.Parse(sNum); if (null == buffer) { buffer = new List <byte>(1 + 9); } buffer.Clear(); buffer.Add(0); recordset rs = recordset.Prepare(); rs.PutDouble(x); for (int id = 0; id < 9; id++) { buffer.Add(0); } rs.GetBytes(buffer, 1, 9); } else { // This type isn't comparable with a number! if (null == buffer) { buffer = new List <byte>(1); } buffer.Clear(); buffer.Add(1); // Nullable byte; IsNull=true; } return(buffer); }
public double GetDouble(ByteSlice input) { #if DEBUG_FTGET if (Types.IsNullValue(input)) { throw new Exception("DEBUG: GetDouble: (Types.IsNullValue(input))"); } #endif recordset rs = recordset.Prepare(ByteSlice.Prepare(input, 1, input.Length - 1)); double x = rs.GetDouble(); return(x); }
void _SysHelp(System.IO.Stream output) { string xml = LoadUsageXml(); const int ColLineChars = 1000; int ColLineLength = 1 + (ColLineChars * 2); foreach (string _linex in xml.Split('\n')) { string linex = _linex.Trim(); while (linex.Length > 0) { string line; if (linex.Length > ColLineChars - 1) { line = linex.Substring(0, ColLineChars - 1); linex = linex.Substring(ColLineChars - 1); } else { line = linex; linex = ""; } recordset rs = recordset.Prepare(); rs.PutByte(0); // Nullable byte. rs.PutString(line); { ByteSlice bs = rs.ToByteSlice(); if (bs.Length > ColLineLength) { //DSpace_Log("bs.Length = " + bs.Length.ToString()); //DSpace_Log("ColLineLength = " + ColLineLength.ToString()); throw new Exception("Column Line: length is too long: " + line); } for (int ibs = 0; ibs < bs.Length; ibs++) { output.WriteByte(bs[ibs]); } for (int ibs = bs.Length; ibs < DSpace_OutputRecordLength; ibs++) { output.WriteByte(0); } } } } }
void _SysIndexes(System.IO.Stream output) { const int ColLineChars = 1000; int ColLineLength = 1 + (ColLineChars * 2); int ip = TableName.IndexOf('('); if (-1 == ip || TableName[TableName.Length - 1] != ')') { return; } string indexdir = QlArgsUnescape(TableName.Substring(ip + 1, TableName.Length - ip - 1 - 1)); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(indexdir); System.IO.FileInfo[] files = dir.GetFiles("ind.Index.*.ind"); foreach (System.IO.FileInfo file in files) { string[] parts = file.Name.Split('.'); string indexname = parts[2]; recordset rs = recordset.Prepare(); rs.PutByte(0); // Nullable byte. rs.PutString(indexname); { ByteSlice bs = rs.ToByteSlice(); if (bs.Length > ColLineLength) { throw new Exception("Column Line: length is too long: " + indexname); } for (int ibs = 0; ibs < bs.Length; ibs++) { output.WriteByte(bs[ibs]); } for (int ibs = bs.Length; ibs < DSpace_OutputRecordLength; ibs++) { output.WriteByte(0); } } } }
// _ReadNextLiteral kept for _ReadNextLiteral static List <byte> _NumberLiteralToType(string sNum, DbColumn ci) { List <byte> buf; if ("int" == ci.Type.Name) { Int32 x = Int32.Parse(sNum); buf = new List <byte>(1 + 4); buf.Add(0); Entry.ToBytesAppend((Int32)Entry.ToUInt32(x), buf); } else if ("long" == ci.Type.Name) { Int64 x = Int64.Parse(sNum); buf = new List <byte>(1 + 8); buf.Add(0); Entry.ToBytesAppend64((Int64)Entry.ToUInt64(x), buf); } else if ("double" == ci.Type.Name) { double x = double.Parse(sNum); buf = new List <byte>(1 + 9); buf.Add(0); recordset rs = recordset.Prepare(); rs.PutDouble(x); for (int id = 0; id < 9; id++) { buf.Add(0); } rs.GetBytes(buf, 1, 9); } else { // This type isn't comparable with a number! buf = new List <byte>(1); buf.Add(1); // Nullable byte; IsNull=true; } return(buf); }
void _SysTables(System.IO.Stream output) { System.Xml.XmlDocument systables; using (GlobalCriticalSection.GetLock()) { systables = LoadSysTables_unlocked(); } foreach (System.Xml.XmlNode xn in systables.SelectNodes("/tables/table")) { recordset rs = recordset.Prepare(); int ColTableLength = 1 + (100 * 2); string Table = xn["name"].InnerText; rs.PutByte(0); // Nullable byte. rs.PutString(Table); { ByteSlice bs = rs.ToByteSlice(); if (bs.Length > ColTableLength) { throw new Exception("Column Table: length is too long: " + Table); } for (int ibs = bs.Length; ibs < ColTableLength; ibs++) { rs.PutByte(0); } } int ColFileLength = 1 + (120 * 2); string File = xn["file"].InnerText; rs.PutByte(0); // Nullable byte. rs.PutString(File); { ByteSlice bs = rs.ToByteSlice(); if (bs.Length > ColTableLength + ColFileLength) { throw new Exception("Column File: length is too long: " + File); } for (int ibs = bs.Length; ibs < ColTableLength + ColFileLength; ibs++) { rs.PutByte(0); } } { ByteSlice bs = rs.ToByteSlice(); if (bs.Length > DSpace_OutputRecordLength) { throw new Exception("Record too long"); } for (int ibs = 0; ibs < bs.Length; ibs++) { output.WriteByte(bs[ibs]); } for (int ibs = bs.Length; ibs < DSpace_OutputRecordLength; ibs++) { output.WriteByte(0); } } } }
public override void OnRemote(IEnumerator <ByteSlice> input, System.IO.Stream output) { string TableName = DSpace_ExecArgs[0]; string DfsOutputName = DSpace_ExecArgs[1]; // Actually the input of this job. string RowInfo = Qa.QlArgsUnescape(DSpace_ExecArgs[2]); string DisplayInfo = DSpace_ExecArgs[3]; long TopCount = long.Parse(DSpace_ExecArgs[4]); string sOptions = (DSpace_ExecArgs.Length > 5) ? DSpace_ExecArgs[5] : ""; bool joined = -1 != sOptions.IndexOf("JOINED"); InitColInfos(RowInfo, DisplayInfo); StringBuilder sb = new StringBuilder(); sb.Length = 0; bool ShouldCleanName = !joined; foreach (ColInfo ci in cols) { string name = ci.Name; if (ShouldCleanName) { name = CleanColumnName(ci.Name); } sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", name); } string hsep = new string('-', sb.Length); DSpace_Log(sb.ToString()); DSpace_Log(hsep); for (ByteSlice rowbuf; (TopCount == -1 || TopCount > 0) && input.MoveNext(); ) { rowbuf = input.Current; sb.Length = 0; foreach (ColInfo ci in cols) { ByteSlice cval = ByteSlice.Prepare(rowbuf, ci.StartOffset, ci.Size); if (0 != cval[0]) { sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", "NULL"); } else { if (ci.Type.StartsWith("char")) { string charsvalue = System.Text.Encoding.Unicode.GetString(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); charsvalue = charsvalue.TrimEnd('\0'); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", charsvalue); } else if ("int" == ci.Type) { Int32 x = Entry.BytesToInt(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); x = Entry.ToInt32((UInt32)x); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x); } else if ("long" == ci.Type) { Int64 x = Entry.BytesToLong(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); x = Entry.ToInt64((UInt64)x); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x); } else if ("double" == ci.Type) { recordset rs = recordset.Prepare(ByteSlice.Prepare(cval, 1, cval.Length - 1)); double x = rs.GetDouble(); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x); } else if ("DateTime" == ci.Type) { Int64 x = Entry.BytesToLong(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); DateTime dt = new DateTime(x); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", dt); } else { sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", "?"); // Not supported yet. } } } DSpace_Log(sb.ToString()); if (TopCount != -1) { TopCount--; } } DSpace_Log(hsep); }