Ejemplo n.º 1
0
		private IndexDefinition()
		{
			this._fieldNames = null;
			this._name       = null;
			this._table      = null;
			this._isUnique   = false;
		}
Ejemplo n.º 2
0
		public static void ModifyTableDefinitionAddOptionField(
			TableDefinition tableDefinition,
			string          optFieldName,
			SqlDbType       sqlType,
			bool            addFieldIndex
		)
		{
			tableDefinition.AddField(
				new FieldDefinition(
					optFieldName,
					sqlType,
					false,
					false
				)
			);

			if (addFieldIndex)
			{
				tableDefinition.Indexes.Add(
					new IndexDefinition(
						tableDefinition,
						optFieldName + "_indx",
						false,
						optFieldName
					)
				);
			}
		}
        protected QueryParameterDirectoryBase(
			CurrentStorage   storage,
			TableDefinition  tableDefinition
		)
            : base(storage, tableDefinition)
        {
        }
Ejemplo n.º 4
0
		protected TableBase(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : this()
		{
			this.TableDefinition = tableDefinition;
			this.Connection      = connection;
		}
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="tableDefinition"></param>
        /// <param name="readOnly">Is table read-only?</param>
        /// <param name="tableName">Table name</param>
        protected TableDirectory(
			CurrentStorage   storage,
			TableDefinition  tableDefinition
		)
            : base(storage,
				tableDefinition)
        {
        }
		public CreateTableCommand(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : base(
				connection,
				tableDefinition
			)
		{
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="connection"></param>
		/// <param name="tableDefinition">Table definition</param>
		public Table(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : base(
				connection,
				tableDefinition
			)
		{
		}
 public SelectTableCommand(
     SQLiteConnection connection,
     TableDefinition tableDefinition,
     string query,
     IEnumerable<SQLiteParameter> parameters)
     : base(connection, tableDefinition)
 {
     this._query      = query;
     this._parameters = parameters;
 }
		protected AutoincrementTableRow(TableDefinition tableDefinition)
			: base(tableDefinition)
		{
			PrimaryKeyDefinition keyDef = tableDefinition.PrimaryKey;

			if (!keyDef.IsAutoincrement)
			{
				throw new ArgumentException("AutoincrementTableRow should have numeric autoincrement primary key.");
			}
		}
Ejemplo n.º 10
0
		public ReplaceCommand(
			SQLiteConnection  connection,
			TableDefinition   tableDefinition,
			SQLiteTransaction transaction = null
		) : base(
				connection,
				tableDefinition
			)
		{
			this._rows        = new List<ITableRow>();
			this._transaction = transaction;
		}
Ejemplo n.º 11
0
		public IndexDefinition(
			TableDefinition table,
			string          name,
			bool            isUnique,
			params string[] fieldNames
		) : this()
		{
			this._fieldNames = fieldNames.ToArray();
			this._table      = table;
			this._name       = name;
			this._isUnique   = isUnique;
		}
Ejemplo n.º 12
0
		public RowDeleteCommand(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : base(
				connection,
				tableDefinition
			)
		{
			this._clause      = null;
			this._parameters  = null;
			this._transaction = null;
		}
Ejemplo n.º 13
0
		public RowUpdateCommand(
			SQLiteConnection connection,
			TableDefinition  tableDefinition,
			string           identityField
		) : base(
				connection,
				tableDefinition
			)
		{
			this._rows          = new List<ITableRow>();
			this._identityField = identityField;
		}
		public RowUpdateByHashCommand(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : base(
				connection,
				tableDefinition
			)
		{
			this._clause      = null;
			this._setString   = null;
			this._updateTable = false;
			this._parameters  = null;
			this._row         = null;
			this._transaction = null;
		}
Ejemplo n.º 15
0
		public PreserveTrigger(
			TableDefinition tableDefinition,
			string          column,
			string          triggerAssociatedColumn = "rowid"
		) : base(
				string.Format(
					"preserve_{0}_{1}",
					tableDefinition.Name,
					column
				),
				tableDefinition,
				string.Format(
					"UPDATE {0} SET {1} = old.{1} WHERE [{2}] = old.[{2}] AND {1} != old.{1};",
					tableDefinition.Name.AsDbName(),
					column, 
					triggerAssociatedColumn
				),
				column
			)
		{
		}
		public SetNewValueAtUpdateTrigger(
			TableDefinition tableDefinition,
			string          targetColumn,
			string          identityColumn,
			string          newValue
		) : base(
				string.Format(
					"update_{0}_{1}",
					tableDefinition.Name,
					targetColumn
				),
				tableDefinition,
				string.Format(
					"UPDATE {0} SET {2} = {3} WHERE [{1}] = old.[{1}] AND ({2} IS NULL OR {2} != {3});",
					tableDefinition.Name.AsDbName(),
					identityColumn,
					targetColumn,
					newValue
				),
				null
			)
		{
		}
Ejemplo n.º 17
0
		public static void ModifyTableDefinition(TableDefinition tableDefinition)
		{
			tableDefinition
				.AddBigIntField(QueryDirectory.TableName.AsFk(),    false, true)
				.AddBigIntField(MetaResultTable.SessionIdFieldName, false, true)
				.AddNVarCharField(RowHashFieldName,                 false, true)
				.AddBigIntField(RowOrderFieldName,                  false, false)
				.AddDateCreateField()                                            // datetime the record is created
				.AddDateUpdatedField()                                           // datetime the record is updated
				.SetCompoundPrimaryKey(new List<string>
				{
					QueryDirectory.TableName.AsFk(),
					MetaResultTable.SessionIdFieldName,
					RowHashFieldName
				});

			// _tableDefinition.Indexes.Add(new IndexDefinition(
			//    _tableDefinition,
			//    "idx_" + _tableDefinition.Name + "_Query_Session",
			//    false,
			//    QueryDirectory.TableName.AsFk(),
			//    MetaResultTable.SessionIdFieldName
			// ));
		}
Ejemplo n.º 18
0
		internal TableDefinition GetTableDefinition()
		{
			TableDefinition tableDefinition = new TableDefinition(TableName);

			foreach (NormalizeFieldInfo field in Fields)
			{
				tableDefinition.AddField(new FieldDefinition(field.Name, field.Type, field.IsUnique, field.IsNotNull));
			}

			foreach (NormalizeInfo childDirectory in ChildDirectories)
			{
				tableDefinition.AddField(new FieldDefinition(childDirectory.GetAsFk(), SqlDbType.BigInt, true, false));
			}

			if (!string.IsNullOrEmpty(this._tableIndexFields))
			{
				string[] tableIndexFieldsList = this._tableIndexFields.Split(',')
					.Select(x => x.Trim())
					.Where(x => !string.IsNullOrWhiteSpace(x))
					.ToArray();

				tableDefinition.Indexes.Add(
					new IndexDefinition(
						tableDefinition,
						"idx_" + this.TableName + "_config_fields",
						false,
						tableIndexFieldsList
					)
				);
			}

			return tableDefinition;
		}
Ejemplo n.º 19
0
		public CopyTableCommand(SQLiteConnection connection, TableDefinition fromTable, TableDefinition toTable)
			: base(connection, fromTable)
		{
			this.toTable = toTable;
		}
Ejemplo n.º 20
0
		public RowInsertCommand(SQLiteConnection connection, TableDefinition tableDefinition)
			: base(connection, tableDefinition)
		{
			this._rows = new List<ITableRow>();
		}
Ejemplo n.º 21
0
 protected TableCommandBase(SQLiteConnection connection, TableDefinition tableDefinition)
     : base (connection)
 {
     this.TableDefinition = tableDefinition;
 }
		protected override long InternalExecute()
		{
			this.TableDefinition = new TableDefinition(this.tableName);

			HashSet<string> unique = new HashSet<string>();

			string sql = string.Format(
				@"PRAGMA index_info('{0}')",
				this.TableDefinition.GetIndexName()
			);

			// Log.DebugFormat(
			//    "Table:'{0}',Index:'{1}',Query:'{2}'",
			//    this.tableName,
			//    this.TableDefinition.GetIndexName(),
			//    sql
			// );

			this.ExecuteQuery(
				sql,
				reader => unique.Add((string)reader["name"])
			);

			if (this.tableName != null)
			{
				sql = string.Format(
					@"PRAGMA table_info({0})",
					this.tableName.AsDbName()
				);

				// Log.DebugFormat("Table:'{0}',Query:'{1}'",
				//    this.tableName,
				//    sql
				// );

				List<string> primaryKeyFields = new List<string>();
				this.ExecuteQuery(
					sql,
					reader =>
						{
							string fieldName = (string) reader["name"];
							SQLiteFieldType fieldType = SQLiteTypeHelper.Parse(reader["type"].ToString());
							this.TableDefinition.AddField(
								new FieldDefinition(
									fieldName,
									fieldType.ToSqlDbType(),
									unique.Contains(fieldName),
									(reader["notnull"] != DBNull.Value) && (long) reader["notnull"] == 1L,
									(reader["dflt_value"] == DBNull.Value)
										? null
										: reader["dflt_value"]
									)
								);

							object pk = reader["pk"];

							if (pk != DBNull.Value && (long) pk > 0L)
							{
								primaryKeyFields.Add(fieldName);
							}
						}
					);

				if (this.TableDefinition.Fields.Count == 0)
				{
					this.TableDefinition = null;
				}
				else
				{
					if (primaryKeyFields.Count == 1)
					{
						string keyField = primaryKeyFields[0];

						TableDefinition.SetSimplePrimaryKey(
							keyField,
							TableDefinition.Fields[keyField].SqlType == SqlDbType.BigInt
						);
					}
					else
					{
						TableDefinition.SetCompoundPrimaryKey(
							primaryKeyFields
						);
					}
				}
			}

			return 0L;
		}
Ejemplo n.º 23
0
		protected EncryptedTableRow(TableDefinition tableDefinition)
			: base(tableDefinition)
		{
		}
		public TableRenameCommand(SQLiteConnection connection, TableDefinition tableDefinition, string newTableName)
			: base(connection, tableDefinition)
		{
			this._newTableName = newTableName;
		}
		protected CurrentStorageTable(CurrentStorage storage, TableDefinition tableDefinition)
			: base(storage.Connection, tableDefinition)
		{
			Storage = storage;
		}
Ejemplo n.º 26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Trigger name</param>
 /// <param name="tableDefinition">Table definition for the trigger</param>
 /// <param name="sql">SQLite SQL code for trigger</param>
 protected Trigger(string name, TableDefinition tableDefinition, string sql)
 {
     this.name = name;
     this.tableDefinition = tableDefinition;
     this.sql = sql;
 }
Ejemplo n.º 27
0
		/// <summary>
		/// Adding a FK to table
		/// </summary>
		/// <param name="tableDefinition">Definition of connected table</param>
		public void AddFk(
			TableDefinition tableDefinition,
			SqlDbType       sqlType,
			bool            unique,
			bool            isNotNull,
			object          defaultValue,
			int?            forcedIndex
		)
		{
			this.Fields.Add(
				tableDefinition.GetAsFk(),
				new FieldDefinition(
					tableDefinition.GetAsFk(),
					sqlType,
					unique,
					isNotNull,
					defaultValue,
					forcedIndex
				)
			);
		}
Ejemplo n.º 28
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Trigger name</param>
 /// <param name="tableDefinition">Table definition</param>
 /// <param name="sql">SQL code</param>
 /// <param name="column">Column name to update</param>
 public UpdateTrigger(string name, TableDefinition tableDefinition, string sql, string column)
     : base(name, tableDefinition, sql)
 {
     this.column = column;
 }