Exemplo n.º 1
0
        public DataTable LoadColumns(string cn, string tableName)
        {
            DataTable metaData = new DataTable();

            metaData.Columns.Add("TABLE_NAME", Type.GetType("System.String"));
            metaData.Columns.Add("COLUMN_NAME", Type.GetType("System.String"));
            metaData.Columns.Add("ORDINAL_POSITION", Type.GetType("System.Int32"));
            metaData.Columns.Add("IS_NULLABLE", Type.GetType("System.Boolean"));
            metaData.Columns.Add("COLUMN_HASDEFAULT", Type.GetType("System.Boolean"));
            metaData.Columns.Add("COLUMN_DEFAULT", Type.GetType("System.String"));
            metaData.Columns.Add("IS_AUTO_KEY", Type.GetType("System.Boolean"));
            metaData.Columns.Add("AUTO_KEY_SEED", Type.GetType("System.Int32"));
            metaData.Columns.Add("AUTO_KEY_INCREMENT", Type.GetType("System.Int32"));
            metaData.Columns.Add("DATA_TYPE_NAME", Type.GetType("System.String"));
            metaData.Columns.Add("NUMERIC_PRECISION", Type.GetType("System.Int32"));
            metaData.Columns.Add("NUMERIC_SCALE", Type.GetType("System.Int32"));
            metaData.Columns.Add("CHARACTER_MAXIMUM_LENGTH", Type.GetType("System.Int32"));
            metaData.Columns.Add("CHARACTER_OCTET_LENGTH", Type.GetType("System.Int32"));
            metaData.Columns.Add("DESCRIPTION", Type.GetType("System.String"));
            metaData.Columns.Add("IS_PRIMARY_KEY", Type.GetType("System.Boolean"));

            try
            {
                Provider.VistaDB.VistaDBDatabase db = OpenDatabase(cn);
                db.Connect();

                Provider.VistaDB.VistaDBTable table = new Provider.VistaDB.VistaDBTable(db, tableName);
                table.Open();

                for (int ordinal = 0; ordinal < table.ColumnCount(); ordinal++)
                {
                    Provider.VistaDB.VistaDBColumn c = table.Columns[ordinal];

                    bool   b       = false;
                    string colName = c.Name;

                    string def       = table.GetDefaultValue(colName, out b);
                    int    width     = c.ColumnWidth;
                    int    dec       = c.ColumnDecimals;
                    int    length    = 0;
                    int    octLength = width;

                    if (c.Identity)
                    {
                        // While I'll see their point this is not typically how it is done
                        def = "";
                    }

                    string type = c.VistaDBType.ToString();

                    switch (type)
                    {
                    case "Character":
                    case "Varchar":
                        length = width;
                        width  = 0;
                        dec    = 0;
                        break;

                    case "Currency":
                    case "Double":
                        break;

                    default:
                        width = 0;
                        dec   = 0;
                        break;
                    }

                    metaData.Rows.Add(new object[]
                    {
                        table.TableName,
                        c.Name,
                        ordinal,
                        c.AllowNull,
                        def == string.Empty ? false : true,
                        def,
                        c.Identity,
                        1,
                        (int)c.IdentityStep,
                        c.VistaDBType.ToString(),
                        width,
                        dec,
                        length,
                        octLength,
                        c.ColumnDescription,
                        c.PrimaryKey
                    });
                }

                table.Close();
                db.Close();
            }
            catch {}

            return(metaData);
        }
Exemplo n.º 2
0
		public DataTable LoadColumns(string cn, string tableName)
		{
			DataTable metaData = new DataTable();
			metaData.Columns.Add("TABLE_NAME", Type.GetType("System.String"));
			metaData.Columns.Add("COLUMN_NAME", Type.GetType("System.String"));
			metaData.Columns.Add("ORDINAL_POSITION", Type.GetType("System.Int32"));
			metaData.Columns.Add("IS_NULLABLE", Type.GetType("System.Boolean"));
			metaData.Columns.Add("COLUMN_HASDEFAULT", Type.GetType("System.Boolean"));
			metaData.Columns.Add("COLUMN_DEFAULT", Type.GetType("System.String"));
			metaData.Columns.Add("IS_AUTO_KEY", Type.GetType("System.Boolean"));
			metaData.Columns.Add("AUTO_KEY_SEED", Type.GetType("System.Int32"));
			metaData.Columns.Add("AUTO_KEY_INCREMENT", Type.GetType("System.Int32"));
			metaData.Columns.Add("DATA_TYPE_NAME", Type.GetType("System.String"));
			metaData.Columns.Add("NUMERIC_PRECISION", Type.GetType("System.Int32"));
			metaData.Columns.Add("NUMERIC_SCALE", Type.GetType("System.Int32"));
			metaData.Columns.Add("CHARACTER_MAXIMUM_LENGTH", Type.GetType("System.Int32"));
			metaData.Columns.Add("CHARACTER_OCTET_LENGTH", Type.GetType("System.Int32"));
			metaData.Columns.Add("DESCRIPTION", Type.GetType("System.String"));
			metaData.Columns.Add("IS_PRIMARY_KEY", Type.GetType("System.Boolean"));

			try
			{
				Provider.VistaDB.VistaDBDatabase db = OpenDatabase(cn);
				db.Connect();

				Provider.VistaDB.VistaDBTable table = new Provider.VistaDB.VistaDBTable(db, tableName);
				table.Open();

				for(int ordinal = 0; ordinal < table.ColumnCount(); ordinal++)
				{
					Provider.VistaDB.VistaDBColumn c = table.Columns[ordinal];

					bool b = false;
					string colName = c.Name;

					string def		= table.GetDefaultValue(colName, out b);
					int width		= c.ColumnWidth;
					int dec			= c.ColumnDecimals;
					int length      = 0;
					int octLength   = width;

					if(c.Identity)
					{
						// While I'll see their point this is not typically how it is done
						def = "";
					}

					string type = c.VistaDBType.ToString();

					switch(type)
					{
						case "Character":
						case "Varchar":
							length    = width;
							width     = 0;
							dec       = 0;
							break;

						case "Currency":
						case "Double":
							break;

						default:
							width = 0;
							dec   = 0;
							break;
					}

					metaData.Rows.Add(new object[] 
					{ 
						table.TableName, 
						c.Name,
						ordinal,
						c.AllowNull,
						def == string.Empty ? false : true,
						def,
						c.Identity,
						1,
						(int)c.IdentityStep,
						c.VistaDBType.ToString(),
						width,
						dec,
						length,
						octLength,
						c.ColumnDescription,
						c.PrimaryKey
					} );
				}

				table.Close();
				db.Close();
			}
			catch {}

			return metaData;
		}