You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
protected void AddIndex(ConcreteProperty property)
{
string sql = string.Empty;
string indexName = string.Empty;
var entityType = property.Owner;
var meta = Rafy.MetaModel.CommonModel.Entities.Find(entityType);
var tableName = meta.TableMeta.TableName;
var columnMeta = meta.Property(property.Property).ColumnMeta;
var columnName = columnMeta.ColumnName ?? property.Name;
indexName = string.Format(@"IDX_{0}_{1}", tableName.ToUpper(), columnName.ToUpper());
indexName = indexName.Length > 30 ? indexName.Substring(0, 30) : indexName;
var dbSetting = Rafy.Data.DbSetting.FindOrCreate(this.DbSetting);
if (Rafy.Data.DbSetting.IsOracleProvider(dbSetting))
{
sql = string.Format(
@"DECLARE indexCount NUMBER(10):=0;createStr VARCHAR2(512);
BEGIN
SELECT COUNT(*) INTO indexCount
FROM USER_INDEXES
WHERE TABLE_NAME='{1}'
AND INDEX_NAME ='{0}';
IF indexCount=0 THEN
createStr:='CREATE INDEX {0} ON {1}({2})';
EXECUTE IMMEDIATE createStr;
END IF;
END;", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
else
{
sql = string.Format(
@"IF NOT EXISTS
(
SELECT *
FROM SYSINDEXES
WHERE ID=OBJECT_ID('{1}')
AND NAME='{0}'
)
CREATE INDEX {0} ON {1}({2})", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
this.RunSql(sql);
}
protected void AddIndexExt(Type owner,string colume)
{
string sql = string.Empty;
string indexName = string.Empty;
var entityType = owner;
var meta = Rafy.MetaModel.CommonModel.Entities.Find(entityType);
var tableName = meta.TableMeta.TableName;
var columnName = colume;
indexName = string.Format(@"IDX_{0}_{1}", tableName.ToUpper(), columnName.ToUpper());
indexName = indexName.Length > 30 ? indexName.Substring(0, 30) : indexName;
var dbSetting = Rafy.Data.DbSetting.FindOrCreate(this.DbSetting);
if (Rafy.Data.DbSetting.IsOracleProvider(dbSetting))
{
sql = string.Format(
@"DECLARE indexCount NUMBER(10):=0;createStr VARCHAR2(512);
BEGIN
SELECT COUNT(*) INTO indexCount
FROM USER_INDEXES
WHERE TABLE_NAME='{1}'
AND INDEX_NAME ='{0}';
IF indexCount=0 THEN
createStr:='CREATE INDEX {0} ON {1}({2})';
EXECUTE IMMEDIATE createStr;
END IF;
END;", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
else
{
sql = string.Format(
@"IF NOT EXISTS
(
SELECT name FROM sys.indexes
WHERE name = N'{0}'
)
CREATE INDEX {0} ON {1}({2})", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
this.RunSql(sql);
}
The text was updated successfully, but these errors were encountered:
建议在Rafy中加入以下创建索引的功能支持
@"DECLARE indexCount NUMBER(10):=0;createStr VARCHAR2(512);
BEGIN
SELECT COUNT(*) INTO indexCount
FROM USER_INDEXES
WHERE TABLE_NAME='{1}'
AND INDEX_NAME ='{0}';
IF indexCount=0 THEN
createStr:='CREATE INDEX {0} ON {1}({2})';
EXECUTE IMMEDIATE createStr;
END IF;
END;", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
else
{
sql = string.Format(
@"IF NOT EXISTS
(
SELECT *
FROM SYSINDEXES
WHERE ID=OBJECT_ID('{1}')
AND NAME='{0}'
)
CREATE INDEX {0} ON {1}({2})", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
@"DECLARE indexCount NUMBER(10):=0;createStr VARCHAR2(512);
BEGIN
SELECT COUNT(*) INTO indexCount
FROM USER_INDEXES
WHERE TABLE_NAME='{1}'
AND INDEX_NAME ='{0}';
IF indexCount=0 THEN
createStr:='CREATE INDEX {0} ON {1}({2})';
EXECUTE IMMEDIATE createStr;
END IF;
END;", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
else
{
sql = string.Format(
@"IF NOT EXISTS
(
SELECT name FROM sys.indexes
WHERE name = N'{0}'
)
CREATE INDEX {0} ON {1}({2})", indexName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
}
The text was updated successfully, but these errors were encountered: