public static List<byte> NumberLiteralToBestTypeBuffer(string sNum, out DbTypeID type, List<byte> buffer) { if(0 == sNum.Length) { type = DbTypeID.NULL; return NumberLiteralToTypeBuffer(sNum, DbTypeID.NULL, buffer); // Null it... } if (-1 != sNum.IndexOf('.')) { type = DbTypeID.DOUBLE; return NumberLiteralToTypeBuffer(sNum, DbTypeID.DOUBLE, buffer); } long x = long.Parse(sNum); if (x < int.MinValue || x > int.MaxValue) { // Stay long. type = DbTypeID.LONG; return NumberLiteralToTypeBuffer(sNum, DbTypeID.LONG, buffer); } else { // Can be int! type = DbTypeID.INT; return NumberLiteralToTypeBuffer(sNum, DbTypeID.INT, buffer); } }
// Returns size. public static int NumberLiteralToBestTypeInfo(string sNum, out DbTypeID type) { if (0 == sNum.Length) { type = DbTypeID.NULL; return(1); } if (-1 != sNum.IndexOf('.')) { type = DbTypeID.DOUBLE; return(1 + 9); } long x = long.Parse(sNum); if (x < int.MinValue || x > int.MaxValue) { // Stay long. type = DbTypeID.LONG; return(1 + 8); } else { // Can be int! type = DbTypeID.INT; return(1 + 4); } }
public static List <byte> NumberLiteralToBestTypeBuffer(string sNum, out DbTypeID type, List <byte> buffer) { if (0 == sNum.Length) { type = DbTypeID.NULL; return(NumberLiteralToTypeBuffer(sNum, DbTypeID.NULL, buffer)); // Null it... } if (-1 != sNum.IndexOf('.')) { type = DbTypeID.DOUBLE; return(NumberLiteralToTypeBuffer(sNum, DbTypeID.DOUBLE, buffer)); } long x = long.Parse(sNum); if (x < int.MinValue || x > int.MaxValue) { // Stay long. type = DbTypeID.LONG; return(NumberLiteralToTypeBuffer(sNum, DbTypeID.LONG, buffer)); } else { // Can be int! type = DbTypeID.INT; return(NumberLiteralToTypeBuffer(sNum, DbTypeID.INT, buffer)); } }
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 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; }
// Returns size. public static int LiteralToValueInfo(string literal, out DbTypeID type) { if (literal.Length > 0) { if ('\'' == literal[0]) { if ('\'' != literal[literal.Length - 1]) { throw new Exception("Expected closing quote in string literal"); } int strbyteslen = System.Text.Encoding.Unicode.GetByteCount(literal); { strbyteslen -= 2 + 2; // Leading and trailing quote are 2 bytes each. for (int i = 1; i <= literal.Length - 2; i++) { if ('\'' == literal[i]) { strbyteslen -= 2; // Un-count 1 quote (2 bytes) of escaped quote ("''" -> "'") i++; // Skip next iteration, it's the other '\''. #if DEBUG if ('\'' != literal[i]) { throw new Exception("DEBUG: ('\'' != literal[i])"); } #endif } } } type = DbTypeID.CHARS; return(1 + strbyteslen); } else if (0 == string.Compare("NULL", literal, true)) { type = DbTypeID.NULL; return(1); } else // Assumed numeric. { try { return(NumberLiteralToBestTypeInfo(literal, out type)); } catch { // Continue on to null on exception. } } } type = DbTypeID.NULL; return(0); }
public static DbType Prepare(int TypeSize, DbTypeID typeID) { DbType type; switch (typeID) { case DbTypeID.CHARS: if (0 == TypeSize) { type = DbType.Prepare("char(0)", 0); } else { #if DEBUG if (0 != ((TypeSize - 1) % 2)) { throw new Exception("DEBUG: DbType.Prepare: case DbTypeID.CHARS: (0 != ((TypeSize - 1) % 2)) (TypeSize=" + TypeSize.ToString() + ")"); } #endif type = DbType.Prepare("char(" + ((TypeSize - 1) / 2).ToString() + ")", TypeSize); } break; case DbTypeID.DOUBLE: type = DbType.Prepare("double", TypeSize); break; case DbTypeID.INT: type = DbType.Prepare("int", TypeSize); break; case DbTypeID.LONG: type = DbType.Prepare("long", TypeSize); break; case DbTypeID.DATETIME: type = DbType.Prepare("DateTime", TypeSize); break; case DbTypeID.NULL: type = DbType.PrepareNull(TypeSize); break; default: throw new Exception("DEBUG: DbType.Prepare: Unknown type specified"); } return(type); }
public ImmediateValue AllocValue(DbTypeID typeID) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, ByteSlice.Prepare(), DbType.Prepare(0, typeID)); values.Add(val); curval++; return(val); } else { ImmediateValue val = values[curval++]; val._value = ByteSlice.Prepare(); val._type = DbType.Prepare(0, typeID); return(val); } }
public static DbType Prepare(string TypeName, int TypeSize, DbTypeID TypeID) { DbType ret; ret.Name = TypeName; ret.Size = TypeSize; ret.ID = TypeID; #if DEBUG if (ret.ID == DbTypeID.NULL) { if (ret.ID != NameToID(NormalizeName(TypeName))) { throw new Exception("DEBUG: DbType.Prepare: type name not normalized: " + TypeName); } } #endif return(ret); }
public static DbType Prepare(int TypeSize, DbTypeID typeID) { DbType type; switch (typeID) { case DbTypeID.CHARS: if (0 == TypeSize) { type = DbType.Prepare("char(0)", 0); } else { #if DEBUG if (0 != ((TypeSize - 1) % 2)) { throw new Exception("DEBUG: DbType.Prepare: case DbTypeID.CHARS: (0 != ((TypeSize - 1) % 2)) (TypeSize=" + TypeSize.ToString() + ")"); } #endif type = DbType.Prepare("char(" + ((TypeSize - 1) / 2).ToString() + ")", TypeSize); } break; case DbTypeID.DOUBLE: type = DbType.Prepare("double", TypeSize); break; case DbTypeID.INT: type = DbType.Prepare("int", TypeSize); break; case DbTypeID.LONG: type = DbType.Prepare("long", TypeSize); break; case DbTypeID.DATETIME: type = DbType.Prepare("DateTime", TypeSize); break; case DbTypeID.NULL: type = DbType.PrepareNull(TypeSize); break; default: throw new Exception("DEBUG: DbType.Prepare: Unknown type specified"); } return type; }
public static ByteSlice LiteralToValueBuffer(string literal, out DbTypeID type, List <byte> buffer) { if (literal.Length > 0) { if ('\'' == literal[0]) { if ('\'' != literal[literal.Length - 1]) { throw new Exception("Expected closing quote in string literal"); } if (null == buffer) { buffer = new List <byte>(1 + (literal.Length - 2) * 2); } buffer.Clear(); buffer.Add(0); for (int i = 1; i <= literal.Length - 2; i++) { int ich = literal[i]; //ConvertCodeValueToBytesUTF16 buffer.Add((byte)ich); buffer.Add((byte)(ich >> 8)); if ('\'' == ich) { i++; // Skip escape quote. #if DEBUG if ('\'' != literal[i]) { throw new Exception("DEBUG: ('\'' != literal[i])"); } #endif } } type = DbTypeID.CHARS; #if DEBUG { DbTypeID _xtype; int ltvi = LiteralToValueInfo(literal, out _xtype); if (buffer.Count != ltvi) { #if DEBUG System.Diagnostics.Debugger.Launch(); #endif throw new Exception("DEBUG: LiteralToValue: (buffer.Count{" + buffer.Count + "} != LiteralToValueInfo(literal, out _xtype)){" + ltvi + "}"); } } #endif return(ByteSlice.Prepare(buffer)); } else if (0 == string.Compare("NULL", literal, true)) { type = DbTypeID.NULL; if (null == buffer) { buffer = new List <byte>(1); } buffer.Clear(); buffer.Add(1); // Nullable, IsNull=true. return(ByteSlice.Prepare(buffer)); } else // Assumed numeric. { try { return(ByteSlice.Prepare(NumberLiteralToBestTypeBuffer(literal, out type, buffer))); } catch { // Continue on to null on exception. } } } type = DbTypeID.NULL; if (buffer == null) { buffer = new List <byte>(0); } buffer.Clear(); return(ByteSlice.Prepare(buffer)); }
public DbValue AllocValue(ByteSlice value, DbTypeID typeID) { return(AllocValue(value, DbType.Prepare(value.Length, typeID))); }
public static ByteSlice LiteralToValue(string literal, out DbTypeID type) { return(LiteralToValueBuffer(literal, out type, null)); }
// Returns size. public static int NumberLiteralToBestTypeInfo(string sNum, out DbTypeID type) { if(0 == sNum.Length) { type = DbTypeID.NULL; return 1; } if (-1 != sNum.IndexOf('.')) { type = DbTypeID.DOUBLE; return 1 + 9; } long x = long.Parse(sNum); if (x < int.MinValue || x > int.MaxValue) { // Stay long. type = DbTypeID.LONG; return 1 + 8; } else { // Can be int! type = DbTypeID.INT; return 1 + 4; } }
public static List <byte> NumberLiteralToType(string sNum, DbTypeID typeID) { return(NumberLiteralToTypeBuffer(sNum, typeID, null)); }
public DbValue AllocValue(ByteSlice value, DbTypeID typeID) { return AllocValue(value, DbType.Prepare(value.Length, typeID)); }
public static List<byte> NumberLiteralToType(string sNum, DbTypeID typeID) { return NumberLiteralToTypeBuffer(sNum, typeID, null); }
public static List <byte> NumberLiteralToBestType(string sNum, out DbTypeID type) { return(NumberLiteralToBestTypeBuffer(sNum, out type, null)); }
public static DbType Prepare(string TypeName, int TypeSize, DbTypeID TypeID) { DbType ret; ret.Name = TypeName; ret.Size = TypeSize; ret.ID = TypeID; #if DEBUG if (ret.ID == DbTypeID.NULL) { if (ret.ID != NameToID(NormalizeName(TypeName))) { throw new Exception("DEBUG: DbType.Prepare: type name not normalized: " + TypeName); } } #endif return ret; }
// Returns size. public static int LiteralToValueInfo(string literal, out DbTypeID type) { if (literal.Length > 0) { if ('\'' == literal[0]) { if ('\'' != literal[literal.Length - 1]) { throw new Exception("Expected closing quote in string literal"); } int strbyteslen = System.Text.Encoding.Unicode.GetByteCount(literal); { strbyteslen -= 2 + 2; // Leading and trailing quote are 2 bytes each. for (int i = 1; i <= literal.Length - 2; i++) { if ('\'' == literal[i]) { strbyteslen -= 2; // Un-count 1 quote (2 bytes) of escaped quote ("''" -> "'") i++; // Skip next iteration, it's the other '\''. #if DEBUG if ('\'' != literal[i]) { throw new Exception("DEBUG: ('\'' != literal[i])"); } #endif } } } type = DbTypeID.CHARS; return 1 + strbyteslen; } else if (0 == string.Compare("NULL", literal, true)) { type = DbTypeID.NULL; return 1; } else // Assumed numeric. { try { return NumberLiteralToBestTypeInfo(literal, out type); } catch { // Continue on to null on exception. } } } type = DbTypeID.NULL; return 0; }
public static ByteSlice LiteralToValueBuffer(string literal, out DbTypeID type, List<byte> buffer) { if (literal.Length > 0) { if ('\'' == literal[0]) { if ('\'' != literal[literal.Length - 1]) { throw new Exception("Expected closing quote in string literal"); } if (null == buffer) { buffer = new List<byte>(1 + (literal.Length - 2) * 2); } buffer.Clear(); buffer.Add(0); for (int i = 1; i <= literal.Length - 2; i++) { int ich = literal[i]; //ConvertCodeValueToBytesUTF16 buffer.Add((byte)ich); buffer.Add((byte)(ich >> 8)); if ('\'' == ich) { i++; // Skip escape quote. #if DEBUG if ('\'' != literal[i]) { throw new Exception("DEBUG: ('\'' != literal[i])"); } #endif } } type = DbTypeID.CHARS; #if DEBUG { DbTypeID _xtype; int ltvi = LiteralToValueInfo(literal, out _xtype); if (buffer.Count != ltvi) { #if DEBUG System.Diagnostics.Debugger.Launch(); #endif throw new Exception("DEBUG: LiteralToValue: (buffer.Count{" + buffer.Count + "} != LiteralToValueInfo(literal, out _xtype)){" + ltvi + "}"); } } #endif return ByteSlice.Prepare(buffer); } else if (0 == string.Compare("NULL", literal, true)) { type = DbTypeID.NULL; if (null == buffer) { buffer = new List<byte>(1); } buffer.Clear(); buffer.Add(1); // Nullable, IsNull=true. return ByteSlice.Prepare(buffer); } else // Assumed numeric. { try { return ByteSlice.Prepare(NumberLiteralToBestTypeBuffer(literal, out type, buffer)); } catch { // Continue on to null on exception. } } } type = DbTypeID.NULL; if (buffer == null) { buffer = new List<byte>(0); } buffer.Clear(); return ByteSlice.Prepare(buffer); }
public static ByteSlice LiteralToValue(string literal, out DbTypeID type) { return LiteralToValueBuffer(literal, out type, null); }
public static List<byte> NumberLiteralToBestType(string sNum, out DbTypeID type) { return NumberLiteralToBestTypeBuffer(sNum, out type, null); }
public ImmediateValue AllocValue(DbTypeID typeID) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, ByteSlice.Prepare(), DbType.Prepare(0, typeID)); values.Add(val); curval++; return val; } else { ImmediateValue val = values[curval++]; val._value = ByteSlice.Prepare(); val._type = DbType.Prepare(0, typeID); return val; } }