DBGetProp(), DBSetProp()
These functions let you check and change properties of a database and its contents.
Usage |
uPropertyValue = DBGETPROP( cItem, cItemType, cProperty ) lSuccess = DBSETPROP( cItem, cItemType, cProperty, uNewValue ) |
Parameter |
Value |
Meaning |
cItem |
Character |
The name of the database element whose property is being inspected or modified. |
cItemType |
Character |
The type of database element. Legal values are "CONNECTION", "DATABASE", "FIELD", "TABLE", and "VIEW." |
cProperty |
Character |
The name of the property to inspect or change. |
uNewValue |
Character, Numeric or Logical |
The new value for cProperty. Must be the appropriate type. |
uPropertyValue |
Character, Numeric or Logical |
The current value of cProperty. |
lSuccess |
.T. |
The change was made. If the change fails, FoxPro generates an error. |
? DBGetProp("Customer.LastName", "Field", "Caption")Unlike the other SetProp() functions, you can't omit the new value to reset these properties to their defaults. Since that feature doesn't always work as expected in the other cases, maybe it's just as well.We've worked out the logic of why some properties are read-write while others are read-only: If there's another command in the language that lets you set a property, it's read-only here. For example, the field property DefaultValue is read-only because you set it with CREATE TABLE or ALTER TABLE. On the other hand, the Comment property of each object, which can only be set through menu choices, is read-write.The Help file contains a complete list of each type of property.
In all versions of VFP before VFP 6 (that is, through 5.0a), you can't successfully clear the value of field properties of views using DBSetProp(). To get rid of the values there, you have to set them to a single blank. But, when you do so, opening the view gives you an error message, although you can proceed. |
The database has to be current to apply these functions, even for the database-level properties (which include the database name in the function call). Having the database open, but not current, isn't enough! To use DBSetProp() in VFP 3, you need exclusive access to the database; that restriction has been removed from later versions. |
Example |
OPEN DATA TasTrade ? DBGETPROP("customer", "table", "comment") * Returns "Customer Information" ? DBGETPROP("customer.discount", "field", "defaultvalue") * Returns 0 |