dmd
Construct database metadata object
Syntax
dbmeta = dmd(conn)
Description
dbmeta = dmd(conn) constructs a database metadata object for the database connection conn. Use get and supports to obtain properties of dbmeta. Use dmd and get(dbmeta) to obtain information you need about a database, such as table names required to retrieve data.
For a list of functions that operate on database metadata objects, enter:
help dmd/Contents
Examples
dbmeta = dmd(conn) creates a database metadata object dbmeta for the database connection conn.
v = get(dbmeta) lists properties of the database metadata object.
=================================
supports
Detect whether property is supported by database metadata object
Syntax
a = supports(dbmeta)
a = supports(dbmeta, 'property')
a.property
Description
a = supports(dbmeta) returns a structure that contains the properties of dbmeta and its property values, 1 or 0. A value of 1 indicates that the property is supported, and 0 indicates that the property is not supported.
a = supports(dbmeta, 'property') returns 1 or 0 for the property field of dbmeta. A value of 1 indicates that the property is supported, and 0 indicates that the property is not supported.
a.property returns the value of property after you have created a using the supports function.
Examples
Check if dbmeta supports group-by clauses.
a = supports(dbmeta, 'GroupBy')
a =
1
View the value of all properties of dbmeta.
a = supports(dbmeta)
The returned result is a list of properties and their values.
See the value of the GroupBy property by running:
a.GroupBy
a =
1
===============================
tables
Return database table names
Syntax
t = tables(dbmeta, 'cata')
t = tables(dbmeta, 'cata', 'sch')
Description
t = tables(dbmeta, 'cata') returns a list of tables and table types in the catalog cata, for the database whose database metadata object is dbmeta.
t = tables(dbmeta, 'cata', 'sch') returns a list of tables and table types in:
The schema sch
Of the catalog cata
For the database whose database metadata object is dbmeta
Tip For command-line help on tables, use the overloaded method:
help dmd/tables
Examples
Get the table names and types for the schema SCOTT in the catalog orcl, for the database metadata object dbmeta.
t = tables(dbmeta,'orcl', 'SCOTT')
t =
'BONUS' 'TABLE'
'DEPT' 'TABLE'
'EMP' 'TABLE'
'SALGRADE' 'TABLE'
'TRIAL' 'TABLE'
上机 操作
>> myconn=database('students','mytest','deepfuture','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/students')
myconn =
Instance: 'students'
UserName: 'mytest'
Driver: 'com.mysql.jdbc.Driver'
URL: 'jdbc:mysql://localhost:3306/students'
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: []
Handle: [1x1 com.mysql.jdbc.JDBC4Connection]
TimeOut: 0
AutoCommit: 'on'
Type: 'Database Object'
>> mydbmetaa=dmd(myconn)
mydbmetaa =
DMDHandle: [1x1 com.mysql.jdbc.JDBC4DatabaseMetaData]
>> myv=get(mydbmetaa)
myv =
AllProceduresAreCallable: 0
AllTablesAreSelectable: 0
DataDefinitionCausesTransactionCommit: 1
DataDefinitionIgnoredInTransactions: 0
DoesMaxRowSizeIncludeBlobs: 1
Catalogs: {3x1 cell}
CatalogSeparator: '.'
CatalogTerm: 'database'
DatabaseProductName: 'MySQL'
DatabaseProductVersion: '5.5.25a'
DefaultTransactionIsolation: 2
DriverMajorVersion: 5
DriverMinorVersion: 1
DriverName: 'MySQL-AB JDBC Driver'
DriverVersion: [1x60 char]
ExtraNameCharacters: '#@'
IdentifierQuoteString: '`'
IsCatalogAtStart: 1
MaxBinaryLiteralLength: 16777208
MaxCatalogNameLength: 32
MaxCharLiteralLength: 16777208
MaxColumnNameLength: 64
MaxColumnsInGroupBy: 64
MaxColumnsInIndex: 16
MaxColumnsInOrderBy: 64
MaxColumnsInSelect: 256
MaxColumnsInTable: 512
MaxConnections: 0
MaxCursorNameLength: 64
MaxIndexLength: 256
MaxProcedureNameLength: 0
MaxRowSize: 2.1475e+009
MaxSchemaNameLength: 0
MaxStatementLength: 65531
MaxStatements: 0
MaxTableNameLength: 64
MaxTablesInSelect: 256
MaxUserNameLength: 16
NumericFunctions: [1x144 char]
ProcedureTerm: 'PROCEDURE'
Schemas: {}
SchemaTerm: ''
SearchStringEscape: '\'
SQLKeywords: [1x1116 char]
StringFunctions: [1x374 char]
StoresLowerCaseIdentifiers: 1
StoresLowerCaseQuotedIdentifiers: 1
StoresMixedCaseIdentifiers: 0
StoresMixedCaseQuotedIdentifiers: 0
StoresUpperCaseIdentifiers: 0
StoresUpperCaseQuotedIdentifiers: 1
SystemFunctions: [1x78 char]
TableTypes: {3x1 cell}
TimeDateFunctions: [1x289 char]
TypeInfo: {40x1 cell}
URL: [1x36 char]
UserName: 'mytest@localhost'
NullPlusNonNullIsNull: 1
NullsAreSortedAtEnd: 0
NullsAreSortedAtStart: 0
NullsAreSortedHigh: 0
NullsAreSortedLow: 1
UsesLocalFilePerTable: 0
UsesLocalFiles: 0
数据库项目(包含的数据库)
>> myv.Catalogs
ans =
'information_schema'
'students'
'test'
>>
元数据对象支持和不支持的属性
>> mys=supports(mydbmetaa)
mys =
AlterTableWithAddColumn: 1
AlterTableWithDropColumn: 1
ANSI92EntryLevelSQL: 1
ANSI92FullSQL: 0
ANSI92IntermediateSQL: 0
CatalogsInDataManipulation: 1
CatalogsInIndexDefinitions: 1
CatalogsInPrivilegeDefinitions: 1
CatalogsInProcedureCalls: 1
CatalogsInTableDefinitions: 1
ColumnAliasing: 1
Convert: 0
CoreSQLGrammar: 1
CorrelatedSubqueries: 1
DataDefinitionAndDataManipulationTransactions: 0
DataManipulationTransactionsOnly: 0
DifferentTableCorrelationNames: 1
ExpressionsInOrderBy: 1
ExtendedSQLGrammar: 0
FullOuterJoins: 0
GroupBy: 1
GroupByBeyondSelect: 1
GroupByUnrelated: 1
IntegrityEnhancementFacility: 0
LikeEscapeClause: 1
LimitedOuterJoins: 1
MinimumSQLGrammar: 1
MixedCaseIdentifiers: 0
MixedCaseQuotedIdentifiers: 0
MultipleResultSets: 1
MultipleTransactions: 1
NonNullableColumns: 1
OpenCursorsAcrossCommit: 0
OpenCursorsAcrossRollback: 0
OpenStatementsAcrossCommit: 0
OpenStatementsAcrossRollback: 0
OrderByUnrelated: 0
OuterJoins: 1
PositionedDelete: 0
PositionedUpdate: 0
SchemasInDataManipulation: 0
SchemasInIndexDefinitions: 0
SchemasInPrivilegeDefinitions: 0
SchemasInProcedureCalls: 0
SchemasInTableDefinitions: 0
SelectForUpdate: 1
StoredProcedures: 1
SubqueriesInComparisons: 1
SubqueriesInExists: 1
SubqueriesInIns: 1
SubqueriesInQuantifieds: 1
TableCorrelationNames: 1
Transactions: 1
Union: 1
UnionAll: 1
某个数据库包含的表
>> tables(mydbmetaa,'students')
ans =
'student' 'TABLE'
>>