例如:自定义与 Outrigger 数据库通信的代码
此代码样本使用一个自定义方法 IDORuntime.Context.CreateOutriggerApplicationDB 提供对 outrigger 数据库的直接访问。数据库必须先根据“将 Oracle 数据库的数据包含在 Mongoose 应用程序中”的说明链接到 Mongoose 应用程序。
public int IdoLinkOtherDbColPopulateSp( string linkedDatabase, string tableName, string optimisticColumnName, byte databaseType, string profileName, string infobar )
{
int result = 0;
if ( databaseType == 1 ) // SQL Server
{
if ( !DoSqlServerColumnsSp( linkedDatabase, tableName, infobar ) )
return 16;
else
return 0;
}
if (!DeletePreviousColumns( linkedDatabase, tableName, infobar ) )
return 16;
using ( ApplicationDB db = IDORuntime.Context.CreateOutriggerApplicationDB( profileName ) )
{
IDbCommand cmd = db.Connection.CreateCommand();
IDbDataParameter parm;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"
SELECT
cols.COLUMN_NAME
, cols.COLUMN_NAME As ViewColumnName
, CASE WHEN DATA_TYPE IN ('VARCHAR', 'NVARCHAR', 'VARCHAR2', 'NVARCHAR2') THEN 1 ELSE 0 END AS IsCharacterColumn
, CASE WHEN xx.TABLE_NAME IS NULL THEN 0 ELSE 1 END AS IsKeyColumn
, cols.DATA_TYPE
, CASE WHEN cols.DATA_PRECISION IS NULL THEN cols.DATA_LENGTH ELSE DATA_PRECISION END
, cols.DATA_SCALE
FROM user_tab_cols cols
LEFT OUTER JOIN (
select ucc.table_name, ucc.column_name
from user_constraints uc
inner join user_cons_columns ucc on
ucc.table_name = uc.table_name
and ucc.constraint_name = uc.constraint_name
and uc.constraint_type = 'P'
) xx ON
xx.TABLE_NAME = cols.TABLE_NAME
AND xx.COLUMN_NAME = cols.COLUMN_NAME
WHERE cols.TABLE_NAME = :ptable
";
parm = cmd.CreateParameter();
parm.ParameterName = "ptable";
parm.Value = tableName.ToUpper();
cmd.Parameters.Add( parm );
cmd.CommandType = CommandType.Text;
cmd.Connection = db.Connection;
IDataReader colReader = cmd.ExecuteReader();
while (colReader.Read() )
{
string colName = colReader.GetString(0);
string viewColName = colReader.GetString(1);
byte isCharacter = colReader.GetByte(2);
byte isKey = colReader.GetByte(3);
byte isOptimisticLock = 0;
string propertyDataType = colReader.GetString(4);
int propertyLength = colReader.GetInt32(5);
int? propertyScale = colReader.GetInt32(6);
if ( colReader.IsDBNull(6) )
propertyScale = null;
if ( optimisticColumnName == colName )
isOptimisticLock = 1;
if (!InsertOneColumn( linkedDatabase, tableName, colName, viewColName, isCharacter, isKey, isOptimisticLock, propertyDataType, propertyLength, propertyScale, infobar ) )
{
break;
}
}
}
return result;
}
相关主题