public Result Execute(int maxrows, int fetchsize, bool updatable) { Result rResult = null; Result r = Result.NewExecuteDirectRequest(); try { r.SetPrepareOrExecuteProperties(this._sqlStatement, maxrows, fetchsize, this.statementReturnType, this.queryTimeout, ResultProperties.DefaultPropsValue, this._command.FetchGeneratedResults ? 1 : 2, null, null); if (updatable) { r.SetDataResultProperties(maxrows, fetchsize, 0x3eb, 0x3f0, 1); } rResult = this._command.Connection.InnerConnection.SessionProxy.Execute(r); } catch (CoreException exception1) { throw UtlException.GetException(exception1); } finally { this.PerformPostExecute(rResult); r.ClearLobResults(); } if (rResult.IsError()) { UtlException.ThrowError(rResult); } return(rResult); }
private void CheckValidRow() { if (this._readingState != 0) { throw UtlException.GetException(Error.GetError(0xe11)); } }
private object GetColumnInType(object value, SqlType sourceType, SqlType targetType) { if (value == null) { return(DBNull.Value); } if (targetType.TypeCode == 0x6b) { return(new MonthSpan((int)((IntervalMonthData)value).Units)); } if (targetType.TypeCode == 110) { IntervalSecondData data = (IntervalSecondData)value; return(new TimeSpan((data.Units * 0x989680L) + (data.Nanos / 100))); } if (sourceType.TypeCode != targetType.TypeCode) { try { value = targetType.ConvertToTypeAdo(this._command.Connection.InnerConnection.SessionProxy, value, sourceType); } catch (CoreException) { string str = value + "instance of " + value.GetType().Name; string[] textArray1 = new string[] { "from SQL type ", sourceType.GetNameString(), " to ", targetType.GetCSharpClassName(), ", value: ", str }; string add = string.Concat(textArray1); throw UtlException.GetException(Error.GetError(0x15b9, add)); } } return(value); }
public DataTable GetIndexes(string catalog, string schema, string table, string index, string unique) { if (table == null) { throw UtlException.GetException(0x1a7); } StringBuilder builder = new StringBuilder(); builder.Append("SELECT DISTINCT TABLE_CAT,TABLE_SCHEM,TABLE_NAME,NON_UNIQUE, INDEX_QUALIFIER,INDEX_NAME,UNIQUE_INDEX as \"UNIQUE\",PRIMARY_INDEX as\"PRIMARY_KEY\" FROM INFORMATION_SCHEMA.SYSTEM_INDEXINFO "); StringBuilder builder2 = null; if (!string.IsNullOrEmpty(unique)) { bool?val = Convert.ToBoolean(unique, CultureInfo.CurrentCulture) ? ((bool?)false) : null; builder2 = builder.Append(" WHERE 1=1").Append(And("TABLE_CAT", "LIKE", catalog)).Append(And("TABLE_SCHEM", "LIKE", schema)).Append(And("TABLE_NAME", "LIKE", table)).Append(And("INDEX_NAME", "LIKE", index)).Append(And("NON_UNIQUE", "=", val)); } else { builder2 = builder.Append(" WHERE 1=1").Append(And("TABLE_CAT", "LIKE", catalog)).Append(And("TABLE_SCHEM", "LIKE", schema)).Append(And("TABLE_NAME", "LIKE", table)).Append(And("INDEX_NAME", "LIKE", index)); } DbDataReader reader = this.Execute(builder2.ToString()); DataTable t = new DataTable("Indexes"); try { PopulateDataTable(t, reader); } catch (Exception) { t.Dispose(); throw; } return(t); }
public void Open() { LibCoreProperties props = this.CreateDbProperties(); if (this.ConnectionOptions.ContextConnection) { this.SessionProxy = UtlContext.session; this._isClrSpConnection = true; } else { if (this.ConnectionOptions.SlOob) { props.SetProperty("url_sl_oob", this.ConnectionOptions.SlOob); } props.SetProperty("shutdown", this.ConnectionOptions.AutoShutdown); if (!string.IsNullOrEmpty(this.ConnectionOptions.CryptoType)) { props.SetProperty("crypt_type", this.ConnectionOptions.CryptoType); props.SetProperty("crypt_key", this.ConnectionOptions.CryptoKey); props.SetProperty("crypt_iv", this.ConnectionOptions.CryptoIv); } try { if (!DatabaseUrl.IsInProcessDatabaseType(this.ConnectionOptions.ConnectionType)) { throw UtlException.GetException(0x1a7, this.ConnectionOptions.ConnectionType); } this.SessionProxy = DatabaseManager.NewSession(this.ConnectionOptions.ConnectionType, this.ConnectionOptions.Database, this.ConnectionOptions.User, this.ConnectionOptions.Password, props, "", 0); if (!this.ConnectionOptions.AutoCommit) { this.SessionProxy.SetAutoCommit(this.ConnectionOptions.AutoCommit); } if (this.ConnectionOptions.Readonly) { this.SessionProxy.SetReadOnlyDefault(this.ConnectionOptions.Readonly); } if (this.ConnectionOptions.IsolationLevel != System.Data.IsolationLevel.ReadCommitted) { this.SessionProxy.SetIsolationDefault((int)this.ConnectionOptions.IsolationLevel); } } catch (CoreException exception1) { throw UtlException.GetException(exception1); } } }
public override string GetName(int columnIndex) { string nameString; try { nameString = this._rResult.MetaData.ColumnLabels[columnIndex]; if (string.IsNullOrEmpty(nameString)) { nameString = this._rResult.MetaData.columns[columnIndex].GetNameString(); } } catch (IndexOutOfRangeException) { throw UtlException.GetException(0x1a5, columnIndex.ToString()); } return(nameString); }
public Result Execute(UtlParameterCollection parameters, int maxrows, int fetchsize, bool updatable) { Result resultIn = null; this.BindParameters(this._command.Parameters, this._isNamedParameters); this.PerformPreExecute(); try { this._resultOut.ParameterMetaData = this._pmdDescriptor; if (this._command.CommandType == CommandType.StoredProcedure) { this._resultOut.SetPreparedResultUpdateProperties(this._parameterValues); } else { this._resultOut.SetPreparedExecuteProperties(this._parameterValues, maxrows, fetchsize, ResultProperties.DefaultPropsValue); } if (updatable) { this._resultOut.SetDataResultProperties(maxrows, fetchsize, 0x3eb, 0x3f0, 1); } resultIn = this._command.Connection.InnerConnection.SessionProxy.Execute(this._resultOut); if (resultIn.GetResultType() == 0x2b) { this.SetOutParameterValues(resultIn); } this.SetReturnParameterValue(resultIn); } catch (CoreException exception1) { throw UtlException.GetException(exception1); } finally { this.PerformPostExecute(resultIn); this._resultOut.ClearLobResults(); } if (resultIn.IsError()) { UtlException.ThrowError(resultIn); } return(resultIn); }
public UtlTransaction BeginTransaction(System.Data.IsolationLevel level, bool readOnly) { lock (this) { if (this.TransactionActive) { throw new InvalidOperationException("Transaction is already active."); } try { this.Transaction = new UtlTransaction(this.Owner, level, readOnly); } catch (CoreException exception1) { throw UtlException.GetException(exception1); } } return(this.Transaction); }
public Result ExecuteDirect(string sql) { Result result2; Result r = Result.NewExecuteDirectRequest(); r.SetMainString(sql); try { result2 = this.SessionProxy.Execute(r); if (result2.IsError()) { throw result2.GetException(); } } catch (CoreException exception1) { throw UtlException.GetException(exception1); } return(result2); }
public override DataTable GetSchemaTable() { this.CheckClosed(); if ((this._rResult == null) || (!this._rResult.IsData() && ((this._commandBehavior & CommandBehavior.SchemaOnly) == CommandBehavior.Default))) { throw UtlException.GetException(0x1ca); } DataTable table = new DataTable("SchemaTable"); ResultMetaData metaData = this._rResult.MetaData; table.Locale = CultureInfo.InvariantCulture; table.Columns.Add(SchemaTableColumn.ColumnName, typeof(string)); table.Columns.Add(SchemaTableColumn.ColumnOrdinal, typeof(int)); table.Columns.Add(SchemaTableColumn.ColumnSize, typeof(long)); table.Columns.Add(SchemaTableColumn.NumericPrecision, typeof(long)); table.Columns.Add(SchemaTableColumn.NumericScale, typeof(short)); table.Columns.Add(SchemaTableColumn.IsUnique, typeof(bool)); table.Columns.Add(SchemaTableColumn.IsKey, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.BaseServerName, typeof(string)); table.Columns.Add(SchemaTableOptionalColumn.BaseCatalogName, typeof(string)); table.Columns.Add(SchemaTableColumn.BaseColumnName, typeof(string)); table.Columns.Add(SchemaTableColumn.BaseSchemaName, typeof(string)); table.Columns.Add(SchemaTableColumn.BaseTableName, typeof(string)); table.Columns.Add(SchemaTableColumn.DataType, typeof(Type)); table.Columns.Add(SchemaTableColumn.AllowDBNull, typeof(bool)); table.Columns.Add(SchemaTableColumn.ProviderType, typeof(int)); table.Columns.Add(SchemaTableColumn.IsAliased, typeof(bool)); table.Columns.Add(SchemaTableColumn.IsExpression, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsAutoIncrement, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsRowVersion, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsHidden, typeof(bool)); table.Columns.Add(SchemaTableColumn.IsLong, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsReadOnly, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.ProviderSpecificDataType, typeof(Type)); table.Columns.Add(SchemaTableOptionalColumn.DefaultValue, typeof(string)); DataTable schema = null; DataTable table3 = null; if ((this._commandBehavior & CommandBehavior.KeyInfo) != CommandBehavior.Default) { string[] restrictionValues = new string[6]; restrictionValues[1] = metaData.columns[0].GetSchemaNameString(); restrictionValues[2] = metaData.columns[0].GetTableNameString(); restrictionValues[5] = "true"; schema = this._command.Connection.GetSchema("INDEXCOLUMNS", restrictionValues); string[] textArray2 = new string[3]; textArray2[1] = metaData.columns[0].GetSchemaNameString(); textArray2[2] = metaData.columns[0].GetTableNameString(); table3 = this._command.Connection.GetSchema("COLUMNS", textArray2); } table.BeginLoadData(); for (int i = 0; i < metaData.GetColumnCount(); i++) { DataRow row = table.NewRow(); if ((metaData.ColumnLabels[i] == null) && string.IsNullOrEmpty(metaData.columns[i].GetNameString())) { row[SchemaTableColumn.ColumnName] = DBNull.Value; } else { row[SchemaTableColumn.ColumnName] = metaData.ColumnLabels[i] ?? metaData.columns[i].GetNameString(); } row[SchemaTableColumn.ColumnOrdinal] = i; row[SchemaTableColumn.ColumnSize] = metaData.ColumnTypes[i].GetAdoPrecision(); row[SchemaTableColumn.ProviderType] = metaData.ColumnTypes[i].GetAdoTypeCode(); SqlType type = metaData.ColumnTypes[i]; if (type.IsNumberType()) { if (type.AcceptsPrecision()) { row[SchemaTableColumn.NumericPrecision] = ((NumberType)metaData.ColumnTypes[i]).GetNumericPrecisionInRadix(); } else { row[SchemaTableColumn.NumericPrecision] = DBNull.Value; } if (type.AcceptsScale()) { row[SchemaTableColumn.NumericScale] = type.GetAdoScale(); } else { row[SchemaTableColumn.NumericScale] = DBNull.Value; } } row[SchemaTableColumn.IsLong] = type.IsLobType(); row[SchemaTableColumn.AllowDBNull] = metaData.columns[i].GetNullability() > 0; row[SchemaTableOptionalColumn.IsReadOnly] = !metaData.columns[i].IsWriteable(); row[SchemaTableOptionalColumn.IsAutoIncrement] = metaData.columns[i].IsIdentity(); row[SchemaTableOptionalColumn.IsHidden] = false; row[SchemaTableOptionalColumn.IsRowVersion] = false; row[SchemaTableColumn.IsUnique] = false; row[SchemaTableColumn.IsKey] = false; row[SchemaTableColumn.DataType] = this.GetFieldType(i); if (string.IsNullOrEmpty(metaData.columns[i].GetNameString())) { row[SchemaTableColumn.BaseColumnName] = DBNull.Value; } else { row[SchemaTableColumn.BaseColumnName] = metaData.columns[i].GetNameString(); } row[SchemaTableColumn.IsExpression] = string.IsNullOrEmpty(metaData.columns[i].GetNameString()); row[SchemaTableColumn.IsAliased] = string.Compare(metaData.columns[i].GetNameString(), metaData.ColumnLabels[i], StringComparison.OrdinalIgnoreCase) > 0; if (string.IsNullOrEmpty(metaData.columns[i].GetTableNameString())) { row[SchemaTableColumn.BaseTableName] = DBNull.Value; } else { row[SchemaTableColumn.BaseTableName] = metaData.columns[i].GetTableNameString(); } if (string.IsNullOrEmpty(metaData.columns[i].GetCatalogNameString())) { row[SchemaTableOptionalColumn.BaseCatalogName] = "PUBLIC"; } else { row[SchemaTableOptionalColumn.BaseCatalogName] = metaData.columns[i].GetCatalogNameString(); } if (string.IsNullOrEmpty(metaData.columns[i].GetSchemaNameString())) { row[SchemaTableColumn.BaseSchemaName] = DBNull.Value; } else { row[SchemaTableColumn.BaseSchemaName] = metaData.columns[i].GetSchemaNameString(); } if ((this._commandBehavior & CommandBehavior.KeyInfo) != CommandBehavior.Default) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); for (int j = 0; j < schema.Rows.Count; j++) { string key = (string)schema.Rows[j]["INDEX_NAME"]; if (!dictionary.ContainsKey(key)) { dictionary.Add(key, (string)schema.Rows[j]["COLUMN_NAME"]); } else { dictionary[key] = string.Empty; } } foreach (string str2 in dictionary.Keys) { if (!string.IsNullOrEmpty(dictionary[str2]) && (string.Compare(metaData.columns[i].GetNameString(), dictionary[str2], StringComparison.OrdinalIgnoreCase) == 0)) { row[SchemaTableColumn.IsUnique] = true; } } for (int k = 0; k < table3.Rows.Count; k++) { if (string.Compare(metaData.columns[i].GetNameString(), (string)table3.Rows[k]["COLUMN_NAME"], StringComparison.OrdinalIgnoreCase) == 0) { row[SchemaTableOptionalColumn.DefaultValue] = table3.Rows[k]["COLUMN_DEF"]; row[SchemaTableColumn.IsKey] = table3.Rows[k]["IS_PRIMARY_KEY"]; } } } table.Rows.Add(row); } table.AcceptChanges(); table.EndLoadData(); return(table); }