示例#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);
        }
示例#2
0
		private void CreateColumnInfo()
		{
			int columnCount;
			VistaDBColumn column;
			StringBuilder name;
			StringBuilder caption;
			string nameS;
			string captionS;
			string dataType;
			VistaDBType netDataType;
			bool reservedWord;
			StringBuilder seed;
			string seedS;
			double step = 0;
			bool packed, hidden, encrypted, unicode;

			columns = new Hashtable();
			columnsInfo = new ArrayList();

			columnCount = VistaDBAPI.ivdb_ColumnCount();

			for(int i = 0; i < columnCount; i++)
			{
				name = new StringBuilder(VistaDBAPI.MAX_STRING_SIZE);
				VistaDBAPI.ivdb_ColumnNameManaged((ushort)(i + 1), name, VistaDBAPI.MAX_STRING_SIZE);
				nameS = VistaDBAPI.CutString(name);

				caption = new StringBuilder(VistaDBAPI.MAX_STRING_SIZE);
				VistaDBAPI.ivdb_GetColumnCaptionManaged(nameS, caption, VistaDBAPI.MAX_STRING_SIZE);
				captionS = VistaDBAPI.CutString(caption);

				dataType = "";
				dataType += (char)((byte)(VistaDBAPI.ivdb_ColumnTypeManaged(nameS)));
				netDataType = VistaDBAPI.NetDataType(dataType);
				reservedWord = VistaDBAPI.ivsql_IsReservedWord(nameS);

				seed = new StringBuilder(VistaDBAPI.MAX_STRING_SIZE);
				VistaDBAPI.ivdb_GetIdentityManaged(nameS, ref step, seed, VistaDBAPI.MAX_STRING_SIZE);
				seedS = VistaDBAPI.CutString(seed);

				packed = VistaDBAPI.ivdb_ColumnCompressed(nameS);
				hidden = VistaDBAPI.ivdb_ColumnHidden(nameS);
				encrypted = VistaDBAPI.ivdb_ColumnEncrypted(nameS);
				unicode = VistaDBAPI.ivdb_ColumnUnicode(nameS);

				column = new VistaDBColumn(nameS, netDataType, VistaDBAPI.ivdb_ColumnWidth(nameS),
					(short)VistaDBAPI.ivdb_ColumnWidth(nameS), (short)VistaDBAPI.ivdb_ColumnDecimals(nameS), 
					!VistaDBAPI.ivdb_ColumnRequired(nameS), VistaDBAPI.ivdb_ColumnReadOnly(nameS), 
					VistaDBAPI.ivdb_ColumnIndexed(nameS, true), 
					VistaDBAPI.ivdb_ColumnIndexed(nameS, true), seedS.Length > 0,
					step, seedS, captionS, VistaDBAPI.ivdb_GetColumnDescription(nameS), reservedWord,
					packed, hidden, encrypted, unicode);

				columns.Add(column.Name.ToUpper(), i);
				columnsInfo.Add(column);
			}
		}