This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

hasdata

Determine if data in DatabaseDatastore is available to read

Syntax

tf = hasdata(dbds)

Description

example

tf = hasdata(dbds) returns logical 1 (true) if there is data available to read from the DatabaseDatastore object dbds. Otherwise, it returns logical 0 (false).

Note

If there is no more data to read from the query, hasdata returns logical 0.

Examples

collapse all

Using a JDBC driver, create a database connection to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password. The code assumes that you are connecting to database toy_store, database server dbtb04, and port number 54317.

conn = database('toy_store','','','Vendor','Microsoft SQL Server', ...
    'Server','dbtb04','PortNumber',54317,'AuthType','Windows');

Create a DatabaseDatastore object using the database connection and SQL query. This SQL query reads the first 30 rows of data from the table.

sqlquery = 'select top 30 * from airlinesmall';

dbds = databaseDatastore(conn,sqlquery);

Read the first 10 rows.

dbds.ReadSize = 10;
read(dbds)
ans = 

    Year    Month    DayofMonth    DayOfWeek    DepTime    CRSDepTime    ArrTime    CRSArrTime    UniqueCarrier    FlightNum    TailNum    ActualElapsedTime    CRSElapsedTime    AirTime    ArrDelay    DepDelay    Origin    Dest     Distance    TaxiIn    TaxiOut    Cancelled    CancellationCode    Diverted    CarrierDelay    WeatherDelay    NASDelay    SecurityDelay    LateAircraftDelay
    ____    _____    __________    _________    _______    __________    _______    __________    _____________    _________    _______    _________________    ______________    _______    ________    ________    ______    _____    ________    ______    _______    _________    ________________    ________    ____________    ____________    ________    _____________    _________________

    1990    9         4            2            1228       1230          1350       1349          'AA'             201          'NA'        82                   79               'NA'         1          -2         'ONT'     'SMF'     389        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        12            3            1125       1125          1231       1231          'AA'             180          'NA'        66                   66               'NA'         0           0         'RST'     'ORD'     268        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        23            7            1721       1719          2201       2202          'AA'             154          'NA'       220                  223               'NA'        -1           2         'DFW'     'BOS'    1562        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        27            4             645        645           802        816          'AA'             133          'NA'        77                   91               'NA'       -14           0         'MSP'     'ORD'     334        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         3            1             710        711           837        847          'AA'             101          'NA'       147                  156               'NA'       -10          -1         'DTW'     'DFW'     987        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        20            4            1338       1335          1853       1907          'AA'              62          'NA'       255                  272               'NA'       -14           3         'ORD'     'SJU'    2072        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        22            6             900        900          1241       1222          'AA'              11          'NA'       401                  382               'NA'        19           0         'BOS'     'LAX'    2611        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         3            1             925        755          1258       1144          'NW'             350          'NA'       153                  169               'NA'        74          90         'MSP'     'BOS'    1124        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        29            6            1434       1435          1615       1630          'NW'             305          'NA'       221                  235               'NA'       -15          -1         'MSP'     'LAX'    1536        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         2            7             NaN       1805           NaN       1900          'NW'             284          'NA'       NaN                   55               'NA'       NaN         NaN         'JAN'     'MEM'     189        'NA'      'NA'       1            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             

Determine if the DatabaseDatastore object has additional data.

hasdata(dbds)
ans =

  logical

   1

When more data is available in dbds, hasdata returns 1.

Read the rest of the data in dbds 10 rows at a time.

while(hasdata(dbds))
     read(dbds)
end
ans = 

    Year    Month    DayofMonth    DayOfWeek    DepTime    CRSDepTime    ArrTime    CRSArrTime    UniqueCarrier    FlightNum    TailNum    ActualElapsedTime    CRSElapsedTime    AirTime    ArrDelay    DepDelay    Origin    Dest     Distance    TaxiIn    TaxiOut    Cancelled    CancellationCode    Diverted    CarrierDelay    WeatherDelay    NASDelay    SecurityDelay    LateAircraftDelay
    ____    _____    __________    _________    _______    __________    _______    __________    _____________    _________    _______    _________________    ______________    _______    ________    ________    ______    _____    ________    ______    _______    _________    ________________    ________    ____________    ____________    ________    _____________    _________________

    1990    9         4            2            1228       1230          1350       1349          'AA'             201          'NA'        82                   79               'NA'         1          -2         'ONT'     'SMF'     389        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        12            3            1125       1125          1231       1231          'AA'             180          'NA'        66                   66               'NA'         0           0         'RST'     'ORD'     268        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        23            7            1721       1719          2201       2202          'AA'             154          'NA'       220                  223               'NA'        -1           2         'DFW'     'BOS'    1562        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        27            4             645        645           802        816          'AA'             133          'NA'        77                   91               'NA'       -14           0         'MSP'     'ORD'     334        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         3            1             710        711           837        847          'AA'             101          'NA'       147                  156               'NA'       -10          -1         'DTW'     'DFW'     987        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        20            4            1338       1335          1853       1907          'AA'              62          'NA'       255                  272               'NA'       -14           3         'ORD'     'SJU'    2072        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        22            6             900        900          1241       1222          'AA'              11          'NA'       401                  382               'NA'        19           0         'BOS'     'LAX'    2611        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         3            1             925        755          1258       1144          'NW'             350          'NA'       153                  169               'NA'        74          90         'MSP'     'BOS'    1124        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        29            6            1434       1435          1615       1630          'NW'             305          'NA'       221                  235               'NA'       -15          -1         'MSP'     'LAX'    1536        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         2            7             NaN       1805           NaN       1900          'NW'             284          'NA'       NaN                   55               'NA'       NaN         NaN         'JAN'     'MEM'     189        'NA'      'NA'       1            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             


ans = 

    Year    Month    DayofMonth    DayOfWeek    DepTime    CRSDepTime    ArrTime    CRSArrTime    UniqueCarrier    FlightNum    TailNum    ActualElapsedTime    CRSElapsedTime    AirTime    ArrDelay    DepDelay    Origin    Dest     Distance    TaxiIn    TaxiOut    Cancelled    CancellationCode    Diverted    CarrierDelay    WeatherDelay    NASDelay    SecurityDelay    LateAircraftDelay
    ____    _____    __________    _________    _______    __________    _______    __________    _____________    _________    _______    _________________    ______________    _______    ________    ________    ______    _____    ________    ______    _______    _________    ________________    ________    ____________    ____________    ________    _____________    _________________

    1990    9        23            7            1721       1719          2201       2202          'AA'             154          'NA'       220                  223               'NA'        -1           2         'DFW'     'BOS'    1562        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        27            4             645        645           802        816          'AA'             133          'NA'        77                   91               'NA'       -14           0         'MSP'     'ORD'     334        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         3            1             710        711           837        847          'AA'             101          'NA'       147                  156               'NA'       -10          -1         'DTW'     'DFW'     987        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        20            4            1338       1335          1853       1907          'AA'              62          'NA'       255                  272               'NA'       -14           3         'ORD'     'SJU'    2072        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        22            6             900        900          1241       1222          'AA'              11          'NA'       401                  382               'NA'        19           0         'BOS'     'LAX'    2611        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         3            1             925        755          1258       1144          'NW'             350          'NA'       153                  169               'NA'        74          90         'MSP'     'BOS'    1124        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        29            6            1434       1435          1615       1630          'NW'             305          'NA'       221                  235               'NA'       -15          -1         'MSP'     'LAX'    1536        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9         2            7             NaN       1805           NaN       1900          'NW'             284          'NA'       NaN                   55               'NA'       NaN         NaN         'JAN'     'MEM'     189        'NA'      'NA'       1            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        11            2             908        910          1613       1554          'NW'             248          'NA'       245                  224               'NA'        19          -2         'PHX'     'DTW'    1671        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1990    9        22            6            1801       1750          2005       1938          'NW'             209          'NA'       124                  108               'NA'        27          11         'PHL'     'DTW'     453        'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             

When no more data remains in dbds, hasdata returns logical 0 and the while loop stops.

Close the DatabaseDatastore object and database connection.

close(dbds)

Input Arguments

collapse all

Datastore containing data in a database, specified as a DatabaseDatastore object created using the databaseDatastore function.

Introduced in R2014b