Esempio n. 1
0
 public TableType(String qualifiedName, String catalogName, String schemaName, String tableName, 
     DataSourceInfo dataSource, RowType tableRowType, bool smart)
 {
     QualifiedName = qualifiedName;
     CatalogName = catalogName;
     SchemaName = schemaName;
     TableName = tableName;
     DataSource = dataSource;
     TableRowType = tableRowType;
     Smart = smart;
 }
Esempio n. 2
0
 private TableType GetDataSetTableType(DataSourceInfo dsi, String tableName)
 {
     DataSet ds = (DataSet)dsi.DataContext;
     if (ds.Tables.Contains(tableName))
         return GetDataTableType(dsi, ds.Tables[tableName]);
     else
         return null;
 }
Esempio n. 3
0
 private TableType GetDataTableType(DataSourceInfo dsi, DataTable dt)
 {
     DataTableReader reader = dt.CreateDataReader();
     DataTable schemaTable = reader.GetSchemaTable();
     reader.Close();
     return new TableType(dt.TableName, null, null, 
         dt.TableName, dsi, new RowType(schemaTable), false);
 }
Esempio n. 4
0
        private TableType GetDataProviderTableType(DataSourceInfo dsi, String identifier)
        {           
            DataProviderHelper helper = new DataProviderHelper(dsi.ProviderInvariantName, dsi.ConnectionString);                       
            using (DbConnection connection = dsi.CreateConnection())
            {                
                DbCommand command = connection.CreateCommand();                
                
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT * FROM ");
                sb.Append(identifier);
                if (helper.OrderByColumnsInSelect)
                    sb.Append(" ORDER BY 1");
                command.CommandText = sb.ToString();                
                
                try
                {
                    DbDataReader reader;                    
                    connection.Open();
                    bool hasKeyInfo = false;                    
                    try
                    {
                        reader = command.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
                        hasKeyInfo = true;
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceWarning("GetDataProviderTableType.ExecuteReader: {0}", ex.Message);                        
                        reader = command.ExecuteReader(CommandBehavior.SchemaOnly);                        
                    }

                    DataTable dt_src = reader.GetSchemaTable();
                    DataTable dt = RowType.CreateSchemaTable();
                    int n = 0;
                    foreach (DataRow r in dt_src.Rows)
                    {
                        DataRow r1 = dt.NewRow();
                        foreach (DataColumn col in dt_src.Columns)
                        {
                            DataColumn dest = dt.Columns[col.ColumnName];
                            if (dt.Columns.IndexOf(col.ColumnName) != -1 && col.ColumnName != "ColumnName")
                                r1[dest] = r[col];
                        }
                        r1["ColumnOrdinal"] = n++;
                        string columnName = (string)r["ColumnName"];
                        r1["ColumnName"] = helper.NativeFormatIdentifier(columnName);
                        r1["ProviderColumnName"] = columnName;
                        r1["IsCaseSensitive"] = 
                            helper.IdentifierCase == IdentifierCase.Sensitive;
                        dt.Rows.Add(r1);
                    }

                    reader.Close();
                    
                    RowType rtype = new RowType(dt);
                    if (hasKeyInfo && rtype.Fields[0].BaseTableName != null)
                        return new TableType(identifier, rtype.Fields[0].BaseCatalogName,
                            rtype.Fields[0].BaseSchemaName, rtype.Fields[0].BaseTableName, dsi, rtype, helper.Smart);
                    else
                    {
                        string schema = null;
                        string catalog = null;
                        string tableName = null;
                        
                        string[] identifierPart = helper.SplitIdentifier(identifier);                        
                        int length = identifierPart.Length;

                        if (length == 3)
                            catalog = identifierPart[identifierPart.Length - length--];

                        if (length == 2)
                            schema = identifierPart[identifierPart.Length - length--];

                        if (length == 1)
                            tableName = identifierPart[identifierPart.Length - length];
                        
                        return new TableType(identifier, catalog, schema, tableName, dsi, rtype, helper.Smart);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("GetDataProviderTableType: {0}", ex.Message);
                    return null;
                }
            }
        }
Esempio n. 5
0
 protected virtual String GetProviderTableName(DataSourceInfo dsi, String[] identifierPart)
 {
     StringBuilder sb = new StringBuilder();
     DataProviderHelper helper = new DataProviderHelper(dsi.ProviderInvariantName, dsi.ConnectionString);
     string[] formattedIdentifiers = new String[identifierPart.Length];
     for (int k = 0; k < identifierPart.Length; k++)
         formattedIdentifiers[k] = helper.FormatIdentifier(identifierPart[k]);
     if (dsi.FormatIdentifier != null)
         formattedIdentifiers = dsi.FormatIdentifier(this, formattedIdentifiers);
     for (int k = 0; k < formattedIdentifiers.Length; k++)
     {
         if (k > 0)
             sb.Append(helper.Qualifer);
         sb.Append(formattedIdentifiers[k]);
     }
     return sb.ToString();
 }
Esempio n. 6
0
 public DatabaseDictionary()
 {
     SearchPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     _catalogCache = new Dictionary<string, TableTypeItem>();
     _rdsi = new List<DataSourceInfo>();
     _xmldsi = new DataSourceInfo(null, false, AcessorType.XMLFile, null, null, null);            
 }
Esempio n. 7
0
 public TableType(String qualifiedName, String tableName, DataSourceInfo dataSource, RowType tableRowType)
 {
     QualifiedName = qualifiedName;
     TableName = tableName;
     DataSource = dataSource;
     TableRowType = tableRowType;
 }
Esempio n. 8
0
 public DataProviderQueryAccessor(DataSourceInfo dataSourceInfo, Notation notation, Symbol squery)
     : base()
 {
     _rowType = null;
     _connectionString = dataSourceInfo.ConnectionString;
     _providerInvariantName = dataSourceInfo.ProviderInvariantName;
     _helper = new DataProviderHelper(_providerInvariantName, _connectionString);
     SqlQueryWriter writer = new SqlQueryWriter(notation);
     writer.ProviderHelper = _helper;
     if (squery.Tag == Tag.Stmt)
         writer.WriteStmt(squery);
     else
         writer.WriteQueryExp(squery);
     _commandText = writer.ToString();
     _parameterBindings = writer.Bindings.ToArray();
 }