Ejemplo n.º 1
0
        /// <summary>
        /// Gets the table column information.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <returns></returns>
        public override List<ColumnInfo> GetTableInfo(string tableName)
        {
            var colList = new List<ColumnInfo>();
            lock (_persistentConnectionSyncLock)
            {
                using (DbCommand command = Provider.CreateCommand("PRAGMA table_info(" + tableName + ");"))
                {
                    DbConnection conn = OpenConnection();
                    command.Connection = conn;

                    try
                    {
                        using (var reader = command.ExecuteReader())
                        {
                            int nameOrd = reader.GetOrdinal("name");
                            int dbTypeOrd = reader.GetOrdinal("type");
                            int pkOrd = reader.GetOrdinal("pk");
                            int notNullOrd = reader.GetOrdinal("notnull");
                            int defaultValOrd = reader.GetOrdinal("dflt_value");
                            while (reader.Read())
                            {
                                var colInfo = new ColumnInfo()
                                {
                                    Name = reader.GetString(nameOrd),
                                    DBType = reader.GetString(dbTypeOrd),
                                    IsPK = reader.GetBoolean(pkOrd),
                                    IsRequired = reader.GetBoolean(notNullOrd),
                                    Default = (!reader.IsDBNull(defaultValOrd)) ? reader.GetString(defaultValOrd) : null
                                };
                                colList.Add(colInfo);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        throw this.ThrowExceptionHelper(conn, command, e);
                    }
                    finally
                    {
                        ReleaseConnection();
                    }
                }
                return colList;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds field to table.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="fieldDef">The field definition.</param>
 public void AddField(string tableName, ColumnInfo fieldDef)
 {
     var command = string.Format("ALTER TABLE {0} ADD COLUMN {1};", tableName, fieldDef.GetColumnDef(true));
     Execute(command);
 }