Beispiel #1
0
 internal void AppendSchemaTable(DataTable tbl)
 {
     SQLiteKeyReader.KeyQuery keyQuery = null;
     for (int i = 0; i < (int)this._keyInfo.Length; i++)
     {
         if (this._keyInfo[i].query == null || this._keyInfo[i].query != keyQuery)
         {
             keyQuery = this._keyInfo[i].query;
             if (keyQuery != null)
             {
                 keyQuery.Sync((long)0);
                 using (DataTable schemaTable = keyQuery._reader.GetSchemaTable())
                 {
                     foreach (DataRow row in schemaTable.Rows)
                     {
                         object[] itemArray = row.ItemArray;
                         DataRow  count     = tbl.Rows.Add(itemArray);
                         count[SchemaTableOptionalColumn.IsHidden] = true;
                         count[SchemaTableColumn.ColumnOrdinal]    = tbl.Rows.Count - 1;
                     }
                 }
             }
             else
             {
                 DataRow dataRow = tbl.NewRow();
                 dataRow[SchemaTableColumn.ColumnName]           = this._keyInfo[i].columnName;
                 dataRow[SchemaTableColumn.ColumnOrdinal]        = tbl.Rows.Count;
                 dataRow[SchemaTableColumn.ColumnSize]           = 8;
                 dataRow[SchemaTableColumn.NumericPrecision]     = 255;
                 dataRow[SchemaTableColumn.NumericScale]         = 255;
                 dataRow[SchemaTableColumn.ProviderType]         = DbType.Int64;
                 dataRow[SchemaTableColumn.IsLong]               = false;
                 dataRow[SchemaTableColumn.AllowDBNull]          = false;
                 dataRow[SchemaTableOptionalColumn.IsReadOnly]   = false;
                 dataRow[SchemaTableOptionalColumn.IsRowVersion] = false;
                 dataRow[SchemaTableColumn.IsUnique]             = false;
                 dataRow[SchemaTableColumn.IsKey]                   = true;
                 dataRow[SchemaTableColumn.DataType]                = typeof(long);
                 dataRow[SchemaTableOptionalColumn.IsHidden]        = true;
                 dataRow[SchemaTableColumn.BaseColumnName]          = this._keyInfo[i].columnName;
                 dataRow[SchemaTableColumn.IsExpression]            = false;
                 dataRow[SchemaTableColumn.IsAliased]               = false;
                 dataRow[SchemaTableColumn.BaseTableName]           = this._keyInfo[i].tableName;
                 dataRow[SchemaTableOptionalColumn.BaseCatalogName] = this._keyInfo[i].databaseName;
                 dataRow[SchemaTableOptionalColumn.IsAutoIncrement] = true;
                 dataRow["DataTypeName"] = "integer";
                 tbl.Rows.Add(dataRow);
             }
         }
     }
 }
Beispiel #2
0
 private void Sync()
 {
     if (this._isValid)
     {
         return;
     }
     SQLiteKeyReader.KeyQuery keyQuery = null;
     for (int i = 0; i < (int)this._keyInfo.Length; i++)
     {
         if (this._keyInfo[i].query == null || this._keyInfo[i].query != keyQuery)
         {
             keyQuery = this._keyInfo[i].query;
             if (keyQuery != null)
             {
                 keyQuery.Sync(this._stmt._sql.GetRowIdForCursor(this._stmt, this._keyInfo[i].cursor));
             }
         }
     }
     this._isValid = true;
 }
Beispiel #3
0
        internal SQLiteKeyReader(SQLiteConnection cnn, SQLiteDataReader reader, SQLiteStatement stmt)
        {
            List <string>                       item;
            Dictionary <string, int>            strs       = new Dictionary <string, int>();
            Dictionary <string, List <string> > strs1      = new Dictionary <string, List <string> >();
            List <SQLiteKeyReader.KeyInfo>      keyInfos   = new List <SQLiteKeyReader.KeyInfo>();
            List <SQLiteKeyReader.RowIdInfo>    rowIdInfos = new List <SQLiteKeyReader.RowIdInfo>();

            this._stmt = stmt;
            using (DataTable schema = cnn.GetSchema("Catalogs"))
            {
                foreach (DataRow row in schema.Rows)
                {
                    strs.Add((string)row["CATALOG_NAME"], Convert.ToInt32(row["ID"], CultureInfo.InvariantCulture));
                }
            }
            using (DataTable schemaTable = reader.GetSchemaTable(false, false))
            {
                foreach (DataRow dataRow in schemaTable.Rows)
                {
                    if (dataRow[SchemaTableOptionalColumn.BaseCatalogName] == DBNull.Value)
                    {
                        continue;
                    }
                    string str   = (string)dataRow[SchemaTableOptionalColumn.BaseCatalogName];
                    string item1 = (string)dataRow[SchemaTableColumn.BaseTableName];
                    if (strs1.ContainsKey(str))
                    {
                        item = strs1[str];
                    }
                    else
                    {
                        item = new List <string>();
                        strs1.Add(str, item);
                    }
                    if (item.Contains(item1))
                    {
                        continue;
                    }
                    item.Add(item1);
                }
                foreach (KeyValuePair <string, List <string> > keyValuePair in strs1)
                {
                    for (int i = 0; i < keyValuePair.Value.Count; i++)
                    {
                        string   str1     = keyValuePair.Value[i];
                        DataRow  dataRow1 = null;
                        string[] key      = new string[] { keyValuePair.Key, null, str1 };
                        using (DataTable dataTable = cnn.GetSchema("Indexes", key))
                        {
                            for (int j = 0; j < 2 && dataRow1 == null; j++)
                            {
                                foreach (DataRow row1 in dataTable.Rows)
                                {
                                    if (j != 0 || !(bool)row1["PRIMARY_KEY"])
                                    {
                                        if (j != 1 || !(bool)row1["UNIQUE"])
                                        {
                                            continue;
                                        }
                                        dataRow1 = row1;
                                        break;
                                    }
                                    else
                                    {
                                        dataRow1 = row1;
                                        break;
                                    }
                                }
                            }
                            if (dataRow1 != null)
                            {
                                string[] strArrays = new string[] { keyValuePair.Key, null, str1 };
                                using (DataTable schema1 = cnn.GetSchema("Tables", strArrays))
                                {
                                    int      num            = strs[keyValuePair.Key];
                                    int      num1           = Convert.ToInt32(schema1.Rows[0]["TABLE_ROOTPAGE"], CultureInfo.InvariantCulture);
                                    int      cursorForTable = stmt._sql.GetCursorForTable(stmt, num, num1);
                                    string[] key1           = new string[] { keyValuePair.Key, null, str1, (string)dataRow1["INDEX_NAME"] };
                                    using (DataTable dataTable1 = cnn.GetSchema("IndexColumns", key1))
                                    {
                                        bool flag = (string)dataRow1["INDEX_NAME"] == string.Concat("sqlite_master_PK_", str1);
                                        SQLiteKeyReader.KeyQuery keyQuery = null;
                                        List <string>            strs2    = new List <string>();
                                        for (int k = 0; k < dataTable1.Rows.Count; k++)
                                        {
                                            string stringOrNull = SQLiteConvert.GetStringOrNull(dataTable1.Rows[k]["COLUMN_NAME"]);
                                            bool   flag1        = true;
                                            foreach (DataRow row2 in schemaTable.Rows)
                                            {
                                                if (row2.IsNull(SchemaTableColumn.BaseColumnName) || !((string)row2[SchemaTableColumn.BaseColumnName] == stringOrNull) || !((string)row2[SchemaTableColumn.BaseTableName] == str1) || !((string)row2[SchemaTableOptionalColumn.BaseCatalogName] == keyValuePair.Key))
                                                {
                                                    continue;
                                                }
                                                if (flag)
                                                {
                                                    SQLiteKeyReader.RowIdInfo rowIdInfo = new SQLiteKeyReader.RowIdInfo()
                                                    {
                                                        databaseName = keyValuePair.Key,
                                                        tableName    = str1,
                                                        column       = (int)row2[SchemaTableColumn.ColumnOrdinal]
                                                    };
                                                    rowIdInfos.Add(rowIdInfo);
                                                }
                                                dataTable1.Rows.RemoveAt(k);
                                                k--;
                                                flag1 = false;
                                                break;
                                            }
                                            if (flag1)
                                            {
                                                strs2.Add(stringOrNull);
                                            }
                                        }
                                        if (!flag && strs2.Count > 0)
                                        {
                                            string[] strArrays1 = new string[strs2.Count];
                                            strs2.CopyTo(strArrays1);
                                            keyQuery = new SQLiteKeyReader.KeyQuery(cnn, keyValuePair.Key, str1, strArrays1);
                                        }
                                        for (int l = 0; l < dataTable1.Rows.Count; l++)
                                        {
                                            string stringOrNull1            = SQLiteConvert.GetStringOrNull(dataTable1.Rows[l]["COLUMN_NAME"]);
                                            SQLiteKeyReader.KeyInfo keyInfo = new SQLiteKeyReader.KeyInfo()
                                            {
                                                rootPage     = num1,
                                                cursor       = cursorForTable,
                                                database     = num,
                                                databaseName = keyValuePair.Key,
                                                tableName    = str1,
                                                columnName   = stringOrNull1,
                                                query        = keyQuery,
                                                column       = l
                                            };
                                            keyInfos.Add(keyInfo);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                keyValuePair.Value.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
            }
            this._keyInfo = new SQLiteKeyReader.KeyInfo[keyInfos.Count];
            keyInfos.CopyTo(this._keyInfo);
            this._rowIdInfo = new SQLiteKeyReader.RowIdInfo[rowIdInfos.Count];
            rowIdInfos.CopyTo(this._rowIdInfo);
        }