@@ -71,7 +71,7 @@ public OracleOrmLiteDialectProvider()
71
71
{
72
72
}
73
73
74
- public OracleOrmLiteDialectProvider ( bool compactGuid , bool quoteNames , string clientProvider = OdpProvider )
74
+ public OracleOrmLiteDialectProvider ( bool compactGuid , bool quoteNames , string clientProvider = ManagedProvider )
75
75
{
76
76
// Make managed provider work with CaptureSqlFilter, safe since Oracle providers don't support async
77
77
OrmLiteContext . UseThreadStatic = true ;
@@ -1192,11 +1192,37 @@ public override IDbDataParameter CreateParam()
1192
1192
return _factory . CreateParameter ( ) ;
1193
1193
}
1194
1194
1195
+ public override string ToAddColumnStatement ( Type modelType , FieldDefinition fieldDef )
1196
+ {
1197
+ var command = base . ToAddColumnStatement ( modelType , fieldDef ) ;
1198
+
1199
+ command = RemoveTerminatingSemicolon ( command ) ;
1200
+
1201
+ return command . Replace ( "ADD COLUMN" , "ADD" ) ;
1202
+ }
1203
+
1204
+ private static string RemoveTerminatingSemicolon ( string command )
1205
+ {
1206
+ command = command . Trim ( ) ;
1207
+
1208
+ if ( command [ command . Length - 1 ] == ';' ) command = command . Substring ( 0 , command . Length - 1 ) ;
1209
+
1210
+ return command ;
1211
+ }
1212
+
1213
+ protected override string ToDropColumnStatement ( Type modelType , string columnName , IOrmLiteDialectProvider provider )
1214
+ {
1215
+ var command = base . ToDropColumnStatement ( modelType , columnName , provider ) ;
1216
+
1217
+ return RemoveTerminatingSemicolon ( command ) ;
1218
+ }
1219
+
1195
1220
public override bool DoesTableExist ( IDbCommand dbCmd , string tableName , string schema = null )
1196
1221
{
1197
1222
if ( ! WillQuote ( tableName ) ) tableName = tableName . ToUpper ( ) ;
1198
1223
1199
- var sql = "SELECT count(*) FROM USER_TABLES WHERE TABLE_NAME = {0}" . SqlFmt ( tableName ) ;
1224
+ tableName = RemoveSchemaName ( tableName ) ;
1225
+ var sql = "SELECT count(*) FROM ALL_TABLES WHERE TABLE_NAME = {0}" . SqlFmt ( tableName ) ;
1200
1226
1201
1227
if ( schema != null )
1202
1228
sql += " AND OWNER = {0}" . SqlFmt ( schema ) ;
@@ -1207,17 +1233,25 @@ public override bool DoesTableExist(IDbCommand dbCmd, string tableName, string s
1207
1233
return result > 0 ;
1208
1234
}
1209
1235
1236
+ private static string RemoveSchemaName ( string tableName )
1237
+ {
1238
+ var indexOfPeriod = tableName . IndexOf ( "." , StringComparison . Ordinal ) ;
1239
+ return indexOfPeriod < 0 ? tableName : tableName . Substring ( indexOfPeriod + 1 ) ;
1240
+ }
1241
+
1210
1242
public override bool DoesColumnExist ( IDbConnection db , string columnName , string tableName , string schema = null )
1211
1243
{
1212
1244
if ( ! WillQuote ( tableName ) )
1213
1245
tableName = tableName . ToUpper ( ) ;
1214
1246
1215
- var sql = "SELECT count(*) from user_tab_cols"
1216
- + " WHERE table_name = @tableName"
1217
- + " AND column_name = @columnName" ;
1247
+ columnName = columnName . ToUpper ( ) ;
1248
+ tableName = RemoveSchemaName ( tableName ) ;
1249
+ var sql = "SELECT count(*) from all_tab_cols"
1250
+ + " WHERE table_name = :tableName"
1251
+ + " AND upper(column_name) = :columnName" ;
1218
1252
1219
1253
if ( schema != null )
1220
- sql += " AND OWNER = @ schema" ;
1254
+ sql += " AND OWNER = : schema" ;
1221
1255
1222
1256
var result = db . SqlScalar < long > ( sql , new { tableName , columnName , schema } ) ;
1223
1257
0 commit comments