Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 76f7d9a

Browse files
authored
Merge pull request #556 from BruceCowan-AI/FixOracleProviderTestingSomewhat
Fix oracle provider testing somewhat
2 parents 4990cf0 + 2c77773 commit 76f7d9a

File tree

12 files changed

+52
-304
lines changed

12 files changed

+52
-304
lines changed

src/ServiceStack.OrmLite.Oracle/OracleOrmLiteDialectProvider.cs

Lines changed: 1 addition & 277 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public static OracleOrmLiteDialectProvider Instance
5858
get { return _instance ?? (_instance = new OracleOrmLiteDialectProvider()); }
5959
}
6060

61-
//protected bool CompactGuid;
62-
63-
//internal const string StringGuidDefinition = "VARCHAR2(37)";
64-
//internal const string CompactGuidDefinition = "RAW(16)";
65-
6661
private readonly DbProviderFactory _factory;
6762
private readonly OracleTimestampConverter _timestampConverter;
6863

@@ -78,24 +73,10 @@ public OracleOrmLiteDialectProvider(bool compactGuid, bool quoteNames, string cl
7873
// Not nice to slow down, but need to read some types via Oracle-specific read methods so can't read all fields in single call
7974
OrmLiteConfig.DeoptimizeReader = true;
8075
ClientProvider = clientProvider;
81-
//CompactGuid = compactGuid;
8276
QuoteNames = quoteNames;
83-
//BoolColumnDefinition = "NUMBER(1)";
84-
//GuidColumnDefinition = CompactGuid ? CompactGuidDefinition : StringGuidDefinition;
85-
//LongColumnDefinition = "NUMERIC(18)";
8677
AutoIncrementDefinition = string.Empty;
87-
//DateTimeColumnDefinition = "TIMESTAMP";
88-
//DateTimeOffsetColumnDefinition = "TIMESTAMP WITH TIME ZONE";
89-
//TimeColumnDefinition = LongColumnDefinition;
90-
//RealColumnDefinition = "FLOAT";
91-
// Order-dependency here: must set following values before setting DefaultStringLength
92-
//StringLengthNonUnicodeColumnDefinitionFormat = "VARCHAR2({0})";
93-
//StringLengthUnicodeColumnDefinitionFormat = "NVARCHAR2({0})";
94-
//MaxStringColumnDefinition = StringLengthNonUnicodeColumnDefinitionFormat.Fmt(MaxStringColumnLength);
95-
//DefaultStringLength = 128;
9678

9779
ParamString = ":";
98-
// OrmLiteConfig.UseParameterizeSqlExpressions = true;
9980

10081
NamingStrategy = new OracleNamingStrategy(MaxNameLength);
10182
ExecFilter = new OracleExecFilter();
@@ -138,37 +119,6 @@ public OracleOrmLiteDialectProvider(bool compactGuid, bool quoteNames, string cl
138119
};
139120
}
140121

141-
//public override void OnAfterInitColumnTypeMap()
142-
//{
143-
// base.OnAfterInitColumnTypeMap();
144-
145-
// DbTypeMap.Set<bool>(DbType.Int16, BoolColumnDefinition);
146-
// DbTypeMap.Set<bool?>(DbType.Int16, BoolColumnDefinition);
147-
148-
// DbTypeMap.Set<sbyte>(DbType.Int16, IntColumnDefinition);
149-
// DbTypeMap.Set<sbyte?>(DbType.Int16, IntColumnDefinition);
150-
// DbTypeMap.Set<ushort>(DbType.Int32, IntColumnDefinition);
151-
// DbTypeMap.Set<ushort?>(DbType.Int32, IntColumnDefinition);
152-
// DbTypeMap.Set<uint>(DbType.Int64, LongColumnDefinition);
153-
// DbTypeMap.Set<uint?>(DbType.Int64, LongColumnDefinition);
154-
// DbTypeMap.Set<ulong>(DbType.Int64, LongColumnDefinition);
155-
// DbTypeMap.Set<ulong?>(DbType.Int64, LongColumnDefinition);
156-
157-
// if (CompactGuid)
158-
// {
159-
// DbTypeMap.Set<Guid>(DbType.Binary, GuidColumnDefinition);
160-
// DbTypeMap.Set<Guid?>(DbType.Binary, GuidColumnDefinition);
161-
// }
162-
// else
163-
// {
164-
// DbTypeMap.Set<Guid>(DbType.String, GuidColumnDefinition);
165-
// DbTypeMap.Set<Guid?>(DbType.String, GuidColumnDefinition);
166-
// }
167-
168-
// DbTypeMap.Set<DateTimeOffset>(DbType.String, DateTimeOffsetColumnDefinition);
169-
// DbTypeMap.Set<DateTimeOffset?>(DbType.String, DateTimeOffsetColumnDefinition);
170-
//}
171-
172122
protected string ClientProvider = OdpProvider;
173123
public static string RowVersionTriggerFormat = "{0}RowVersionUpdateTrigger";
174124

@@ -225,203 +175,6 @@ public override long InsertAndGetLastInsertId<T>(IDbCommand dbCmd)
225175
return Convert.ToInt64(identityParameter.Value);
226176
}
227177

228-
//Moved to converters.FromDbValue()
229-
//public override void SetDbValue(FieldDefinition fieldDef, IDataReader reader, int colIndex, object instance)
230-
//{
231-
// if (OrmLiteUtils.HandledDbNullValue(fieldDef, reader, colIndex, instance)) return;
232-
233-
// var value = reader.GetValue(colIndex);
234-
// var convertedValue = ConvertDbValue(value, fieldDef.FieldType);
235-
236-
// try
237-
// {
238-
// fieldDef.SetValueFn(instance, convertedValue);
239-
// }
240-
// catch (NullReferenceException ex)
241-
// {
242-
// Log.Warn("Unexpected NullReferenceException", ex);
243-
// }
244-
//}
245-
246-
//Moved to converters.FromDbValue()
247-
//public override object ConvertDbValue(object value, Type type)
248-
//{
249-
// if (value == null || value is DBNull) return null;
250-
251-
// if (type == typeof (DateTimeOffset))
252-
// {
253-
// return Convert.ChangeType(value, type);
254-
// }
255-
256-
// if (type == typeof(bool))
257-
// return Convert.ToBoolean(value);
258-
259-
// if (type == typeof(Guid))
260-
// {
261-
// if (CompactGuid)
262-
// {
263-
// var raw = (byte[])value;
264-
// return new Guid(raw);
265-
// }
266-
// return new Guid(value.ToString());
267-
// }
268-
269-
// if (type == typeof(byte[]))
270-
// return value;
271-
272-
// if (type == typeof(TimeSpan))
273-
// {
274-
// var ticks = long.Parse(value.ToString());
275-
// return TimeSpan.FromTicks(ticks);
276-
// }
277-
278-
// return base.ConvertDbValue(value, type);
279-
//}
280-
281-
//Moved to Converters.ToQuotedString()
282-
//public override string GetQuotedValue(object value, Type fieldType)
283-
//{
284-
// if (value == null) return "NULL";
285-
286-
// if (fieldType == typeof(Guid))
287-
// {
288-
// var guid = (Guid)value;
289-
// return CompactGuid ? string.Format("CAST('{0}' AS {1})", BitConverter.ToString(guid.ToByteArray()).Replace("-", ""), CompactGuidDefinition)
290-
// : string.Format("CAST('{0}' AS {1})", guid, StringGuidDefinition);
291-
// }
292-
293-
// if (fieldType == typeof(DateTime) || fieldType == typeof(DateTime?))
294-
// {
295-
// return GetQuotedDateTimeValue((DateTime)value);
296-
// }
297-
298-
// if (fieldType == typeof(DateTimeOffset) || fieldType == typeof(DateTimeOffset?))
299-
// {
300-
// return GetQuotedDateTimeOffsetValue((DateTimeOffset)value);
301-
// }
302-
303-
// if ((value is TimeSpan) && (fieldType == typeof(Int64) || fieldType == typeof(Int64?)))
304-
// {
305-
// var longValue = ((TimeSpan)value).Ticks;
306-
// return base.GetQuotedValue(longValue, fieldType);
307-
// }
308-
309-
// if (fieldType == typeof(bool?) || fieldType == typeof(bool))
310-
// {
311-
// var boolValue = (bool)value;
312-
// return base.GetQuotedValue(boolValue ? "1" : "0", typeof(string));
313-
// }
314-
315-
// if (fieldType == typeof(decimal?) || fieldType == typeof(decimal) ||
316-
// fieldType == typeof(double?) || fieldType == typeof(double) ||
317-
// fieldType == typeof(float?) || fieldType == typeof(float))
318-
// {
319-
// var s = base.GetQuotedValue(value, fieldType);
320-
// if (s.Length > 20) s = s.Substring(0, 20);
321-
// return "'" + s + "'"; // when quoted exception is more clear!
322-
// }
323-
324-
// //Moved to OracleEnumConverter.ToQuotedString()
325-
// if (fieldType.IsEnum)
326-
// {
327-
// if (value is int && !fieldType.IsEnumFlags())
328-
// {
329-
// value = fieldType.GetEnumName(value);
330-
// }
331-
332-
// var enumValue = StringSerializer.SerializeToString(value);
333-
// // Oracle stores empty strings in varchar columns as null so match that behavior here
334-
// if (enumValue == null)
335-
// return null;
336-
// enumValue = GetQuotedValue(enumValue.Trim('"'));
337-
// return enumValue == "''"
338-
// ? "null"
339-
// : enumValue;
340-
// }
341-
342-
// if (fieldType == typeof(byte[]))
343-
// {
344-
// return "hextoraw('" + BitConverter.ToString((byte[])value).Replace("-", "") + "')";
345-
// }
346-
347-
// return base.GetQuotedValue(value, fieldType);
348-
//}
349-
350-
//Moved to Converters.ToDbParamValue()
351-
//public override object GetParamValue(object value, Type fieldType)
352-
//{
353-
// if (value == null) return "NULL";
354-
355-
// if (fieldType == typeof(Guid))
356-
// {
357-
// var guid = (Guid)value;
358-
359-
// if (CompactGuid)
360-
// return guid.ToByteArray();
361-
362-
// return guid.ToString();
363-
// }
364-
365-
// if (fieldType == typeof(DateTimeOffset) || fieldType == typeof(DateTimeOffset?))
366-
// {
367-
// return GetQuotedDateTimeOffsetValue((DateTimeOffset)value);
368-
// }
369-
370-
// if ((value is TimeSpan) && (fieldType == typeof(Int64) || fieldType == typeof(Int64?)))
371-
// {
372-
// var longValue = ((TimeSpan)value).Ticks;
373-
// return base.GetQuotedValue(longValue, fieldType);
374-
// }
375-
376-
// if (fieldType == typeof(TimeSpan))
377-
// return ((TimeSpan)value).Ticks;
378-
379-
// if (fieldType == typeof(bool?) || fieldType == typeof(bool))
380-
// {
381-
// var boolValue = (bool)value;
382-
// return boolValue ? 1 : 0;
383-
// }
384-
385-
// //Moved to OracleEnumConverter.ToDbParamValue()
386-
// if (fieldType.IsEnum)
387-
// {
388-
// if (value is int && !fieldType.IsEnumFlags())
389-
// {
390-
// value = fieldType.GetEnumName(value);
391-
// }
392-
393-
// var enumValue = StringSerializer.SerializeToString(value);
394-
// // Oracle stores empty strings in varchar columns as null so match that behavior here
395-
// if (enumValue == null)
396-
// return null;
397-
// enumValue = enumValue.Trim('"');
398-
// return enumValue == ""
399-
// ? "null"
400-
// : enumValue;
401-
// }
402-
403-
// if (fieldType == typeof(byte[]))
404-
// {
405-
// return "hextoraw('" + BitConverter.ToString((byte[])value).Replace("-", "") + "')";
406-
// }
407-
408-
// //override default by setting base.ReferenceTypeConverter
409-
// if (fieldType.IsRefType())
410-
// {
411-
// return StringSerializer.SerializeToString(value);
412-
// }
413-
414-
// switch (fieldType.GetTypeCode())
415-
// {
416-
// case TypeCode.UInt16:
417-
// case TypeCode.UInt32:
418-
// case TypeCode.UInt64:
419-
// return Convert.ToDecimal(value);
420-
// }
421-
422-
// return value;
423-
//}
424-
425178
public override object ToDbValue(object value, Type type)
426179
{
427180
if (value == null || value is DBNull)
@@ -624,35 +377,6 @@ public override void SetParameterValues<T>(IDbCommand dbCmd, object obj)
624377
}
625378
}
626379

627-
// TODO: do we need this?
628-
public override void SetParameterValue<T>(FieldDefinition fieldDef, IDataParameter p, object obj)
629-
{
630-
p.Value = GetValueOrDbNull<T>(fieldDef, obj);
631-
}
632-
633-
//Moved to Converters.ToDbValue()
634-
//protected override object GetValue<T>(FieldDefinition fieldDef, object obj)
635-
//{
636-
// var value = base.GetValue<T>(fieldDef, obj);
637-
638-
// if (value != null)
639-
// {
640-
// if (fieldDef.FieldType == typeof(Guid))
641-
// {
642-
// var guid = (Guid)value;
643-
// if (CompactGuid) return guid.ToByteArray();
644-
// return guid.ToString();
645-
// }
646-
647-
// if (fieldDef.FieldType == typeof(DateTimeOffset))
648-
// {
649-
// var timestamp = (DateTimeOffset)value;
650-
// return _timestampConverter.ConvertToOracleTimeStampTz(timestamp);
651-
// }
652-
// }
653-
// return value;
654-
//}
655-
656380
//TODO: Change to parameterized query to match all other ToInsertRowStatement() impls
657381
public override string ToInsertRowStatement(IDbCommand dbCommand, object objWithProperties, ICollection<string> insertFields = null)
658382
{
@@ -1212,7 +936,7 @@ public override bool DoesTableExist(IDbCommand dbCmd, string tableName, string s
1212936
if (!WillQuote(tableName)) tableName = tableName.ToUpper();
1213937

1214938
tableName = RemoveSchemaName(tableName);
1215-
var sql = "SELECT count(*) FROM ALL_TABLES WHERE TABLE_NAME = {0}".SqlFmt(tableName);
939+
var sql = "SELECT count(*) FROM USER_TABLES WHERE TABLE_NAME = {0}".SqlFmt(tableName);
1216940

1217941
if (schema != null)
1218942
sql += " AND OWNER = {0}".SqlFmt(schema);

src/ServiceStack.OrmLite.Oracle/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
//[assembly: AssemblyKeyFile("")]
2121

2222
[assembly: AssemblyVersion("4.0.0.0")]
23+
[assembly: AssemblyFileVersion("4.0.0.0")]

tests/ServiceStack.OrmLite.Tests/EnumTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void CanQueryByEnumValue_using_select_with_string()
6969
db.Save(new TypeWithEnum { Id = 3, EnumValue = SomeEnum.Value2 });
7070

7171
var target = db.Select<TypeWithEnum>(
72-
"EnumValue".SqlColumn() + " = @value", new { value = SomeEnum.Value1 });
72+
"EnumValue".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = SomeEnum.Value1 });
7373

7474
Assert.AreEqual(2, target.Count());
7575
}
@@ -252,7 +252,7 @@ public void CanQueryByEnumValue_using_select_with_string_enum_flags()
252252
db.Save(new TypeWithFlagsEnum { Id = 3, Flags = FlagsEnum.FlagTwo });
253253

254254
var target = db.Select<TypeWithFlagsEnum>(
255-
"Flags".SqlColumn() + " = @value", new { value = FlagsEnum.FlagOne });
255+
"Flags".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = FlagsEnum.FlagOne });
256256
db.GetLastSql().Print();
257257
Assert.That(target.Count, Is.EqualTo(2));
258258
}
@@ -269,7 +269,7 @@ public void CanQueryByEnumValue_using_select_with_string_EnumAsInt()
269269
db.Save(new TypeWithEnumAsInt { Id = 3, EnumValue = SomeEnumAsInt.Value2 });
270270

271271
var target = db.Select<TypeWithEnumAsInt>(
272-
"EnumValue".SqlColumn() + " = @value", new { value = SomeEnumAsInt.Value1 });
272+
"EnumValue".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = SomeEnumAsInt.Value1 });
273273
db.GetLastSql().Print();
274274
Assert.That(target.Count, Is.EqualTo(2));
275275
}
@@ -336,7 +336,7 @@ public void Can_save_Enum_as_Integers()
336336
db.Insert(new TypeWithTreatEnumAsInt { Id = 2, EnumValue = SomeEnumTreatAsInt.Value2 });
337337

338338
var row = db.Single<TypeWithTreatEnumAsInt>(
339-
"EnumValue".SqlColumn() + " = @value", new { value = "2" });
339+
"EnumValue".SqlColumn() + " = @value".PreNormalizeSql(db), new { value = "2" });
340340

341341
Assert.That(row.Id, Is.EqualTo(2));
342342
}

0 commit comments

Comments
 (0)