Esempio n. 1
0
 public void Generate(Table table,string inputDir, string outputDir)
 {
     var directoryInfo = new DirectoryInfo(inputDir);
     var client = new Client();
     //var originalSd = client.StartDelimiter;
     //var originalEd = client.EndingDelimiter;
     if(_CustomValue != null)
     {
         client.CustomValues = _CustomValue;
     }
     foreach(var fileInfo in directoryInfo.GetFiles())
     {
         client.StartDelimiter = "{";//originalSd;
         client.EndingDelimiter = "}";//originalEd;
         var sr = File.OpenText(fileInfo.FullName);
         var fileContent = sr.ReadToEnd();
         sr.Close();
         var codeGenerated = client.Parse(table,fileContent);
         client.StartDelimiter = String.Empty;
         client.EndingDelimiter = String.Empty;
         var filename = client.Parse(table,fileInfo.Name);
         try
         {
             var sw = new StreamWriter(outputDir + Path.DirectorySeparatorChar + filename);
             sw.Write(codeGenerated);
             sw.Flush();
             sw.Close();
         }
         catch (Exception e)
         {
             Debug.WriteLine(e);
         }
     }
     CompleteNotifier(new EventArgs());
 }
		public ColumnCollection GetColumns(Table table)
		{
			if(_connection.State == ConnectionState.Closed)
			{
				_connection.Open();
			}
			
			if (Server.ProviderType != DataProviderType.Oracle)
			{
			_connection.ChangeDatabase(table.ParentDatabase.Name);
			}

			DataSet ds = ColumnSchema(table,_dataAccessProvider,_connection);
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				Column column = CreateColumn(row);
				column.SetParentTable(table);
				foreach(Key key in table.Keys)
				{
					if(key.IsPrimary)
					{
						if(key.ColumnName == column.Name)
						{
							column.IsPrimaryKey = true;
							continue;
						}
					}
				}
				_Columns.Add(column);
				
			}
			_connection.Close();
			return _Columns;
		}
 protected override Table CreateTable(Database database, DataRow row)
 {
     Table table = new Table();
     table.ParentDatabase = database;
     table.Name = row["tablename"].ToString();
     return table;
 }
Esempio n. 4
0
		public string Parse(Table table,string inputString)
		{
			_Table = table;
			_Context.Input = inputString;
			string s = Intrepret();
			CompleteNotifier(new EventArgs());
			return s;
		}
		protected override Table CreateTable(Database database, DataRow row)
		{
			var table = new Table();
			table.ParentDatabase = database;
			table.Name = row["tablename"].ToString();
		    table.Schema = string.Empty;
			return table;
		}
		protected override Table CreateTable(Database database, DataRow row)
		{
			var table = new Table {
                ParentDatabase = database, 
                Schema = row["SCHEMA"].ToString(), 
                Name = row["NAME"].ToString()
            };
		    return table;
		}
 protected override DataSet KeySchema(Table table, DataAccessProviderFactory dataAccessProvider, IDbConnection connection)
 {
     DataSet ds = new DataSet();
     IDbCommand sqlSp = dataAccessProvider.CreateCommand("show index from "+ table.Name,connection);
     sqlSp.CommandType = CommandType.Text;
     IDbDataAdapter da = dataAccessProvider.CreateDataAdapter();
     da.SelectCommand = sqlSp;
     da.Fill(ds);
     return ds;
 }
 protected override DataSet ColumnSchema(Table table, DataAccessProviderFactory dataAccessProvider, IDbConnection connection)
 {
     DataSet ds = new DataSet();
     IDbCommand sqlString = dataAccessProvider.CreateCommand("desc "+table.Name,connection);
     sqlString.CommandType = CommandType.Text;
     IDbDataAdapter da = dataAccessProvider.CreateDataAdapter();
     da.SelectCommand = sqlString;
     da.Fill(ds);
     return ds;
 }
 protected override DataSet KeySchema(Table table, DataAccessProviderFactory dataProvider, IDbConnection connection)
 {
     DataSet ds = new DataSet();
     IDbCommand sqlCommand = dataProvider.CreateCommand("SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)" +
         "FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i " +
         "WHERE c.oid = '" + GetTableId(table.Name, dataProvider, connection) + "' AND c.oid = i.indrelid AND i.indexrelid = c2.oid " +
         "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",connection);
     sqlCommand.CommandType = CommandType.Text;
     IDbDataAdapter da = dataProvider.CreateDataAdapter();
     da.SelectCommand = sqlCommand;
     da.Fill(ds);
     return ds;
 }
Esempio n. 10
0
        public void Generate(Table table,string inputDir, string outputDir)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(inputDir);
            Client client = new Client();
            //string originalSD = client.StartDelimiter;
            //string originalED = client.EndingDelimiter;
            if(_CustomValue != null)
            {
                client.CustomValues = _CustomValue;
            }
            foreach(FileInfo fileInfo in directoryInfo.GetFiles())
            {
                //client.StartDelimiter = originalSD;
                //client.EndingDelimiter = originalED;
                StreamReader sr = File.OpenText(fileInfo.FullName);
                string fileContent = sr.ReadToEnd();
                sr.Close();
                string codeGenerated = client.Parse(table,fileContent);

                //client.StartDelimiter = String.Empty;
                //client.EndingDelimiter = String.Empty;
                string dirname = client.Parse(table, directoryInfo.Name);
                string filename = client.Parse(table,fileInfo.Name);
                //change back Delimiters immediately (subsequent calls to Generate() fail if you don't do so)
                //client.StartDelimiter = originalSD;
                //client.EndingDelimiter = originalED;

                String fullDir = outputDir + Path.DirectorySeparatorChar + dirname;

                try
                {
                    //StreamWriter sw = new StreamWriter(outputDir + Path.DirectorySeparatorChar + filename);

                    if (Directory.Exists(fullDir) == false)
                    {
                        Directory.CreateDirectory(fullDir);
                    }

                    StreamWriter sw = new StreamWriter(fullDir + Path.DirectorySeparatorChar + filename);
                    sw.Write(codeGenerated);
                    sw.Flush();
                    sw.Close();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
            //CompleteNotifier(new EventArgs());
        }
 protected override DataSet ColumnSchema(Table table, DataAccessProviderFactory dataAccessProvider, IDbConnection connection)
 {
     DataSet ds = new DataSet();
     IDbCommand sqlSp = dataAccessProvider.CreateCommand("sp_columns",connection);
     sqlSp.CommandType = CommandType.StoredProcedure;
     IDbDataParameter param = dataAccessProvider.CreateParameter();
     param.Direction = ParameterDirection.Input;
     param.DbType = DbType.String;
     param.ParameterName = "@table_name";
     param.Value = table.Name;
     sqlSp.Parameters.Add(param);
     IDbDataAdapter da = dataAccessProvider.CreateDataAdapter();
     da.SelectCommand = sqlSp;
     da.Fill(ds);
     return ds;
 }
 protected override DataSet ColumnSchema(Table table, DataAccessProviderFactory dataProvider, IDbConnection connection)
 {
     DataSet ds = new DataSet();
     int tableId = GetTableId(table.Name,dataProvider, connection);
     IDbCommand sqlCommand = dataProvider.CreateCommand("SELECT a.attname,t.typname as atttype, " +
         "(SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d " +
         "WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)as attdef, a.attlen, a.atttypmod,a.attnotnull, a.attnum " +
         "FROM pg_catalog.pg_attribute a, pg_catalog.pg_type t " +
         "WHERE a.attrelid = '" + tableId + "' AND a.attnum > 0 AND NOT a.attisdropped " +
         "AND t.oid = a.atttypid " +
         "ORDER BY a.attnum",connection);
     sqlCommand.CommandType = CommandType.Text;
     IDbDataAdapter da = dataProvider.CreateDataAdapter();
     da.SelectCommand = sqlCommand;
     da.Fill(ds);
     return ds;
 }
		protected override DataSet KeySchema(Table table, DataAccessProviderFactory dataAccessProvider, IDbConnection connection)
		{
			DataSet dsPkeys = new DataSet();
			IDbCommand sqlSp = dataAccessProvider.CreateCommand("sp_pkeys",connection);
			sqlSp.CommandType = CommandType.StoredProcedure;			
			IDbDataParameter param = dataAccessProvider.CreateParameter();			
			param.Direction = ParameterDirection.Input;
			param.DbType = DbType.String;
			param.ParameterName = "@table_name";
			param.Value = table.Name;
			sqlSp.Parameters.Add(param);
            IDbDataParameter schemaParameter = dataAccessProvider.CreateParameter();			
			schemaParameter.Direction = ParameterDirection.Input;
			schemaParameter.DbType = DbType.String;
			schemaParameter.ParameterName = "@table_owner";
			schemaParameter.Value = table.Schema;
			sqlSp.Parameters.Add(schemaParameter);
			IDbDataAdapter da = dataAccessProvider.CreateDataAdapter();
			da.SelectCommand = sqlSp;
			da.Fill(dsPkeys);
			foreach(DataRow row in dsPkeys.Tables[0].Rows)
			{
				Key key = new Key();
				key.Name = row["PK_NAME"].ToString();
				key.ColumnName = row["COLUMN_NAME"].ToString();
				key.IsPrimary = true;
				_Keys.Add(key);				
			}
	
			DataSet ds = new DataSet();			
			sqlSp = dataAccessProvider.CreateCommand("sp_fkeys",connection);
			sqlSp.CommandType = CommandType.StoredProcedure;			
			param = dataAccessProvider.CreateParameter();			
			param.Direction = ParameterDirection.Input;
			param.DbType = DbType.String;
			param.ParameterName = "@pktable_name";
			param.Value = table.Name;
			sqlSp.Parameters.Add(param);
			da = dataAccessProvider.CreateDataAdapter();
			da.SelectCommand = sqlSp;
			da.Fill(ds);
			ds.Merge(dsPkeys);
			return ds;
		}
Esempio n. 14
0
		public KeyCollection GetKeys(Table table)
		{
			if(_connection.State == ConnectionState.Closed)
			{
				_connection.Open();
			}
			if (Server.ProviderType != DataProviderType.Oracle)
			{
			_connection.ChangeDatabase(table.ParentDatabase.Name);
			}
			DataSet ds = KeySchema(table,_dataAccessProvider,_connection);
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				Key key = CreateKey(row);
				_Keys.Add(key);				
			}
			_connection.Close();
			return _Keys;	
		}
 protected override DataSet KeySchema(Table table, DataAccessProviderFactory dataProvider, IDbConnection connection)
 {
     DataSet ds = new DataSet();
     String schemaQuery = "SELECT acc.COLUMN_NAME, " +
     "ac.CONSTRAINT_NAME, " +
     "ac.CONSTRAINT_TYPE " +
     "FROM ALL_CONS_COLUMNS acc " +
     "JOIN ALL_CONSTRAINTS ac " +
     "ON ac.OWNER = acc.OWNER " +
     "AND ac.TABLE_NAME = acc.TABLE_NAME " +
     "AND ac.CONSTRAINT_NAME = acc.CONSTRAINT_NAME " +
     "where acc.owner = '" + table.ParentDatabase.Name + "' " +
     "and acc.Table_NAME = '" + table.Name + "'";
     IDbCommand sqlCommand = dataProvider.CreateCommand(schemaQuery,connection);
     sqlCommand.CommandType = CommandType.Text;
     IDbDataAdapter da = dataProvider.CreateDataAdapter();
     da.SelectCommand = sqlCommand;
     da.Fill(ds);
     return ds;
 }
        protected override DataSet ColumnSchema(Table table, DataAccessProviderFactory dataProvider, IDbConnection connection)
        {
            DataSet ds = new DataSet();
            String schemaQuery = "SELECT atc.OWNER, " +
                "atc.TABLE_NAME, " +
                "atc.COLUMN_NAME, " +
                "atc.DATA_TYPE, " +
                "atc.DATA_LENGTH, " +
                "atc.DATA_PRECISION, " +
                "atc.DATA_SCALE, " +
                "atc.NULLABLE, " +
                "atc.COLUMN_ID, " +
                "acc.CONSTRAINT_NAME, " +
                "ac.CONSTRAINT_TYPE, " +
                "ac.R_CONSTRAINT_NAME, " +
                "ac.INDEX_NAME " +
                "FROM ALL_TAB_COLUMNS atc " +
                "LEFT OUTER JOIN ALL_CONS_COLUMNS acc " +
                "ON acc.OWNER = atc.OWNER " +
                "AND acc.TABLE_NAME = atc.TABLE_NAME " +
                "AND acc.COLUMN_NAME = atc.COLUMN_NAME " +
                "LEFT OUTER JOIN ALL_CONSTRAINTS ac " +
                "ON ac.OWNER = acc.OWNER " +
                "AND ac.CONSTRAINT_NAME = acc.CONSTRAINT_NAME " +
                "WHERE atc.OWNER = '" + table.ParentDatabase.Name + "' " +
                "AND atc.TABLE_NAME = '" + table.Name + "' " +
                "ORDER BY TABLE_NAME asc";

            IDbCommand sqlCommand = dataProvider.CreateCommand(schemaQuery,connection);

            sqlCommand.CommandType = CommandType.Text;
            IDbDataAdapter da = dataProvider.CreateDataAdapter();
            da.SelectCommand = sqlCommand;
            da.Fill(ds);
            return ds;
        }
Esempio n. 17
0
		public TableEventArgs(Table table)
		{
			_table = table;
		}
Esempio n. 18
0
		public Parser(Table table)
		{			
			_table = table;
		}
Esempio n. 19
0
 public TablesEventArgs(Table[] tables)
 {
     _tables = tables;
 }
        private static string RemovePrefixLowerFirstUpperReplacement(Table column)
        {
            //MD_AC_SOMETEXT -> Sometext
            string[] split = column.Name.Split('_');
            string name = split[split.Length - 1];
            name = name.Substring(0, 1).ToUpper() + name.Substring(1, name.Length - 1).ToLower();

            return name;
        }
Esempio n. 21
0
        private void DnfColumnSelected(object sender, ColumnEventArgs args)
        {
			_selectedTable = args.Column.ParentTable;
			_pf.SelectedObject = args.Column;
        }
Esempio n. 22
0
		public bool Contains(Table table)
		{
			return List.Contains(table);
		}
        private static string RemovePrefixUpperReplacement(Table column)
        {
            //MD_AC_Sometext -> SOMETEXT
            string[] split = column.Name.Split('_');
            string name = split[split.Length - 1].ToUpper();

            return name;
        }
Esempio n. 24
0
		public int IndexOf(Table table)
		{
			return List.IndexOf(table);
		}
Esempio n. 25
0
		public void Remove(Table table)
		{
			List.Remove(table);
		}
Esempio n. 26
0
		public void Add(Table table)
		{
			List.Add(table);
		}
Esempio n. 27
0
		protected abstract DataSet KeySchema(Table table, DataAccessProviderFactory dataAccessProvider, IDbConnection connection);
Esempio n. 28
0
        private void DnfTableSelected(object sender, TableEventArgs args)
        {
			_selectedTable = args.Table;
			_pf.SelectedObject = args.Table;
        }
 private static string UpperReplacement(Table column)
 {
     string replacement;
     replacement = column.Name.ToUpper();
     return replacement;
 }
 private static string CamelReplacement(Table column)
 {
     string replacement;
     replacement = column.Name.Replace("_", String.Empty);
     replacement = replacement.Substring(0, 1).ToLower() + replacement.Substring(1);
     return replacement;
 }