isopen
(Not recommended) Determine if database cursor is open
The isopen function is not recommended. There is no replacement for
      this functionality. To import data, use the fetch function. For details, see Version History.
Syntax
Description
Examples
Connect to a Microsoft® SQL Server® database and verify the database cursor. Then, import data from the database into MATLAB®. Determine the highest unit cost among the retrieved products in the table. Close the database cursor and database connection.
Create an ODBC database connection to a Microsoft
            SQL Server database with Windows® authentication. Specify a blank user name and password. The database
            contains the table productTable.
datasource = 'MS SQL Server Auth'; conn = database(datasource,'','');
Check the database connection. If the Message property is empty,
            the connection is successful.
conn.Message
ans =
     []
Create a cursor object by executing an SQL query in the database.
            Select all the data from the table productTable by using the
              connection object, and then sort the data by the product
            number.
sqlquery = 'SELECT * FROM productTable ORDER BY productNumber';
curs = exec(conn,sqlquery);Determine if the database cursor is open. The isopen function
            returns the numeric scalar 1, which means the database cursor is
            open.
i = isopen(curs)
i =
     1Import data from the executed SQL query and display the first three rows.
curs = fetch(curs); curs.Data(1:3,:)
ans =
  3×5 table
    productNumber    stockNumber    supplierNumber    unitCost    productDescription
    _____________    ___________    ______________    ________    __________________
    1                4.0035e+05     1001              14          'Building Blocks' 
    2                4.0031e+05     1002               9          'Painting Set'    
    3                  4.01e+05     1009              17          'Slinky'          
Determine the highest unit cost in the table.
data = curs.Data; max(data.unitCost)
ans =
    24After you finish working with the cursor object, close it.
close(curs)
Determine if the database cursor is closed. The isopen function
            returns the numeric scalar 0, which means the database cursor is
            closed. If the cursor object is invalid, the
              isopen function returns the same result.
i = isopen(curs)
i =
     0
Close the database connection.
close(conn)
Input Arguments
Version History
Introduced in R2015bThe isopen function is not recommended. Use the fetch function to import data. Some differences between the workflows might
        require updates to your code.
There are no plans to remove the isopen function at this
        time.
Use the fetch function with the connection
          object to import data from a database in one step.
In prior releases, you wrote multiple lines of code to create the cursor object, determine if the cursor object is open, and
          import data. For example:
curs = exec(conn,sqlquery); i = isopen(curs); curs = fetch(curs); results = curs.Data; close(curs)
Now you can import data in one step using the fetch
          function.
results = fetch(conn,sqlquery);
There is no replacement functionality for the isopen
          function.
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)