setoptions
Set PostgreSQL native interface connection options
Description
sets connection options using the opts = setoptions(opts,Option1,OptionValue1,...,OptionN,OptionValueN)SQLConnectionOptions object opts.
Examples
Create, configure, test, and save a PostgreSQL native interface data source for a PostgreSQL database.
Create a PostgreSQL native interface data source for a PostgreSQL native interface database connection.
vendor = "PostgreSQL"; opts = databaseConnectionOptions("native",vendor)
opts =
SQLConnectionOptions with properties:
DataSourceName: ""
Vendor: "PostgreSQL"
DatabaseName: ""
Server: "localhost"
PortNumber: 5432
opts is an SQLConnectionOptions object with these properties:
DataSourceName— Name of the data sourceVendor— Database vendor nameDatabaseName— Name of the databaseServer— Name of the database serverPortNumber— Port number
Configure the data source by setting the database connection options for the data source PostgreSQLDataSource, database name toystore_doc, database server dbtb00, and port number 5432.
opts = setoptions(opts, ... 'DataSourceName',"PostgreSQLDataSource", ... 'DatabaseName',"toystore_doc",'Server',"dbtb00", ... 'PortNumber',5432)
opts =
SQLConnectionOptions with properties:
DataSourceName: "PostgreSQLDataSource"
Vendor: "PostgreSQL"
DatabaseName: "toystore_doc"
Server: "dbtb00"
PortNumber: 5432
The setoptions function sets the DataSourceName, DatabaseName, Server, and PortNumber properties in the SQLConnectionOptions object.
Test the database connection with a user name and password. The testConnection function returns the logical 1, which indicates the database connection is successful.
username = "dbdev"; password = "matlab"; status = testConnection(opts,username,password)
status = logical
1
Save the configured data source.
saveAsDataSource(opts)
You can connect to the new data source using the postgresql function or the Database Explorer app.
Edit an existing PostgreSQL native interface data source for a PostgreSQL database. Set an additional driver-specific option and save the data source.
Retrieve the existing PostgreSQL data source PostgreSQLDataSource.
datasource = "PostgreSQLDataSource";
opts = databaseConnectionOptions(datasource)opts =
SQLConnectionOptions with properties:
DataSourceName: "PostgreSQLDataSource"
Vendor: "PostgreSQL"
DatabaseName: "toystore_doc"
Server: "dbtb00"
PortNumber: 5432
opts is an SQLConnectionOptions object with these properties:
DataSourceName— Name of the data sourceVendor— Database vendor nameDatabaseName— Name of the databaseServer— Name of the database serverPortNumber— Port number
Add a driver-specific connection option by using a name-value pair argument. The option specifies a timeout value for establishing the database connection. opts contains a new section of properties for the additional connection option.
opts = setoptions(opts,"connect_timeout",20)opts =
SQLConnectionOptions with properties:
DataSourceName: "PostgreSQLDataSource"
Vendor: "PostgreSQL"
DatabaseName: "toystore_doc"
Server: "dbtb00"
PortNumber: 5432
Additional Connection Options:
connect_timeout: 20
Test the database connection with a user name and password. The testConnection function returns the logical 1, which indicates the database connection is successful.
username = "dbdev"; password = "matlab"; status = testConnection(opts,username,password)
status = logical
1
Save the updated data source.
saveAsDataSource(opts)
Input Arguments
Database connection options, specified as an SQLConnectionOptions object.
PostgreSQL native interface connection options, specified as one or more name-value
pair arguments. Option is a character vector or string scalar that
specifies the name of a PostgreSQL native interface connection option.
OptionValue specifies the value of the option.
OptionValue can be a character vector, string scalar, logical
scalar, or numeric scalar. You can specify any PostgreSQL native interface connection
option that is a property of the SQLConnectionOptions object.
Example: 'DataSourceName',"myDataSource",'Server',"localhost",'PortNumber',5432
configures a PostgreSQL native interface data source named
myDataSource that is located on the local server with the port
number 5432.
Output Arguments
Database connection options, returned as an SQLConnectionOptions object.
Version History
Introduced in R2020b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)