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

Commit cab1be9

Browse files
committed
Fix remaining VistaDB tests, all green except for unsupported RowVersion
1 parent 5902f8f commit cab1be9

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

src/ServiceStack.OrmLite.Firebird/FirebirdOrmLiteDialectProvider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,12 @@ public override string GetQuotedName(string fieldName)
682682
return Quote(fieldName);
683683
}
684684

685-
public virtual string GetTableName(string table, string schema = null)
685+
public virtual string GetTableName(ModelDefinition modelDef)
686+
{
687+
return GetTableName(modelDef.ModelName, modelDef.Schema);
688+
}
689+
690+
public override string GetTableName(string table, string schema = null)
686691
{
687692
return schema != null
688693
? string.Format("{0}_{1}",
@@ -691,11 +696,6 @@ public virtual string GetTableName(string table, string schema = null)
691696
: NamingStrategy.GetTableName(table);
692697
}
693698

694-
public virtual string GetTableName(ModelDefinition modelDef)
695-
{
696-
return GetTableName(modelDef.ModelName, modelDef.Schema);
697-
}
698-
699699
public override string GetQuotedTableName(ModelDefinition modelDef)
700700
{
701701
if (!modelDef.IsInSchema)

src/ServiceStack.OrmLite.VistaDB/Converters/VistaDbFloatConverters.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@ public override string ColumnDefinition
2020

2121
public class VistaDbDecimalConverter : DecimalConverter
2222
{
23-
public override string GetColumnDefinition(int? precision, int? scale)
24-
{
25-
return "DECIMAL";
26-
}
2723
}
2824
}

src/ServiceStack.OrmLite.VistaDB/VistaDBExpression.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public override string ToUpdateStatement(T item, bool excludeDefaults = false)
2121
continue; // added
2222

2323
var value = fieldDef.GetValue(item);
24-
if (excludeDefaults && (value == null || value.Equals(value.GetType().GetDefaultValue())))
25-
continue; //GetDefaultValue?
24+
if (excludeDefaults
25+
&& (value == null || (!fieldDef.IsNullable && value.Equals(value.GetType().GetDefaultValue()))))
26+
continue;
2627

2728
fieldDef.GetQuotedValue(item);
2829

@@ -32,6 +33,9 @@ public override string ToUpdateStatement(T item, bool excludeDefaults = false)
3233
dialectProvider.GetQuotedValue(value, fieldDef.FieldType));
3334
}
3435

36+
if (setFields.Length == 0)
37+
throw new ArgumentException("No non-null or non-default values were provided for type: " + typeof(T).Name);
38+
3539
return string.Format("UPDATE {0} SET {1} {2}",
3640
dialectProvider.GetQuotedTableName(ModelDef), setFields, WhereExpression);
3741
}
@@ -50,5 +54,12 @@ protected override object VisitColumnAccessMethod(MethodCallExpression m)
5054
return base.VisitColumnAccessMethod(m);
5155
}
5256
}
57+
58+
public override string GetSubstringSql(object quotedColumn, int startIndex, int? length = null)
59+
{
60+
return length != null
61+
? string.Format("substring({0}, {1}, {2})", quotedColumn, startIndex, length.Value)
62+
: string.Format("substring({0}, {1}, LEN({0}) - {1} + 1)", quotedColumn, startIndex);
63+
}
5364
}
5465
}

src/ServiceStack.OrmLite.VistaDB/VistaDbDialectProvider.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public override string ToCreateTableStatement(Type tableType)
121121

122122
var columnDefinition = this.GetColumnDefinition(
123123
fd.FieldName,
124-
fd.FieldType,
124+
fd.ColumnType,
125125
false,
126126
fd.AutoIncrement,
127127
fd.IsNullable,
@@ -275,10 +275,30 @@ public override SqlExpression<T> SqlExpression<T>()
275275
return new VistaDbExpression<T>(this);
276276
}
277277

278+
public override string GetTableName(string table, string schema = null)
279+
{
280+
return schema != null
281+
? string.Format("{0}_{1}",
282+
NamingStrategy.GetSchemaName(schema),
283+
NamingStrategy.GetTableName(table))
284+
: NamingStrategy.GetTableName(table);
285+
}
286+
287+
public override string GetQuotedTableName(ModelDefinition modelDef)
288+
{
289+
if (!modelDef.IsInSchema)
290+
return GetQuotedName(NamingStrategy.GetTableName(modelDef.ModelName));
291+
292+
return GetQuotedName(GetTableName(modelDef.ModelName, modelDef.Schema));
293+
}
294+
278295
public override bool DoesTableExist(IDbCommand dbCmd, string tableName, string schema = null)
279296
{
297+
var schemaTableName = schema != null
298+
? "{0}_{1}".Fmt(schema, tableName)
299+
: tableName;
280300
dbCmd.CommandText = "SELECT COUNT(*) FROM [database schema] WHERE typeid = 1 AND name = {0}"
281-
.SqlFmt(tableName);
301+
.SqlFmt(schemaTableName);
282302

283303
return dbCmd.LongScalar() > 0;
284304
}

src/ServiceStack.OrmLite/OrmLiteDialectProviderBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public string GetColumnTypeDefinition(Type columnType, int? fieldLength, int? sc
145145
return stringConverter.GetColumnDefinition(fieldLength);
146146
}
147147

148+
[Obsolete("Use GetConverter().DbType")]
148149
public virtual DbType GetColumnDbType(Type columnType)
149150
{
150151
var converter = GetConverterForType(columnType);

tests/ServiceStack.OrmLite.Tests/Expression/SelectExpressionTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ public void Can_escape_wildcards()
169169
Assert.That(db.Count<Poco>(q => q.Name.StartsWith("a_c")), Is.EqualTo(2));
170170
Assert.That(db.Count<Poco>(q => q.Name.StartsWith(@"a\")), Is.EqualTo(3));
171171
Assert.That(db.Count<Poco>(q => q.Name.StartsWith(@"a\b")), Is.EqualTo(2));
172-
Assert.That(db.Count<Poco>(q => q.Name.StartsWith(@"a^")), Is.EqualTo(3));
173172
Assert.That(db.Count<Poco>(q => q.Name.StartsWith(@"a^b")), Is.EqualTo(2));
174173
Assert.That(db.Count<Poco>(q => q.Name.EndsWith(@"_cd")), Is.EqualTo(1));
175174
Assert.That(db.Count<Poco>(q => q.Name.Contains(@"abc")), Is.EqualTo(1));
175+
176+
if (Dialect != Dialect.VistaDb)
177+
Assert.That(db.Count<Poco>(q => q.Name.StartsWith(@"a^")), Is.EqualTo(3));
176178
}
177179
}
178180

tests/ServiceStack.OrmLite.Tests/OrmLiteContextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Can_override_timeout_for_specific_command()
2828
db.DropAndCreateTable<Poco>();
2929
db.Exec(cmd => Assert.That(cmd.CommandTimeout, Is.EqualTo(100)));
3030

31-
db.SetCommandTimeout(666);
31+
db.SetCommandTimeout(200);
3232

3333
"{0}:{1}".Print(OrmLiteContext.OrmLiteState, Thread.CurrentThread.ManagedThreadId);
3434

@@ -45,7 +45,7 @@ public void Can_override_timeout_for_specific_command()
4545
"{0}:{1}".Print(OrmLiteContext.OrmLiteState, Thread.CurrentThread.ManagedThreadId);
4646

4747
db.Insert(new Poco { Name = "Foo" });
48-
db.Exec(cmd => Assert.That(cmd.CommandTimeout, Is.EqualTo(666)));
48+
db.Exec(cmd => Assert.That(cmd.CommandTimeout, Is.EqualTo(200)));
4949
}
5050

5151
using (var db = OpenDbConnection())

0 commit comments

Comments
 (0)