示例#1
0
        public CDeviceListItem[] CSQL_GetDeviceList()
        {
            string sql = "SELECT devices.device_id " +
                         "FROM devices;";

            string sql_count = "SELECT devices.device_id, count(*) as TotalDevices " +
                               "FROM devices;";

            SqliteCommand    dbhCmd    = null;
            SqliteDataReader dbhReader = null;

            CDeviceListItem[] _device_list = null;
            int device_count = 0;
            int count        = 0;

            if (CSQL_Connected())
            {
                dbhCmd    = new SqliteCommand(sql_count, dbh);
                dbhReader = dbhCmd.ExecuteReader();

                /**
                 * Get the number of devices for the array size.
                 */
                if (dbhReader.HasRows)
                {
                    dbhReader.Read();
                    device_count = dbhReader.GetInt32(1);

                    if (device_count == 0)
                    {
                        cleanup();
                        return(null);
                    }
                }
                else
                {
                    cleanup();
                    return(null);
                }
            }

            _device_list = new CDeviceListItem[device_count];

            dbhCmd    = new SqliteCommand(sql, dbh);
            dbhReader = dbhCmd.ExecuteReader();

            if (dbhReader.HasRows)
            {
                while (dbhReader.Read())
                {
                    _device_list [count++] = new CDeviceListItem(dbhReader.GetString(0));
                }

                cleanup();
                return(_device_list);
            }
            else
            {
                cleanup();
                return(null);
            }

            cleanup();
            return(null);
        }
示例#2
0
        public CDeviceListItem[] CSQL_GetDeviceList()
        {
            string sql = "SELECT devices.device_id " +
                         "FROM devices;";

            string sql_count = "SELECT devices.device_id, count(*) as TotalDevices " +
                               "FROM devices;";

            SqliteCommand dbhCmd = null;
            SqliteDataReader dbhReader = null;
            CDeviceListItem[] _device_list = null;
            int device_count = 0;
            int count = 0;

            if (CSQL_Connected ()) {

                dbhCmd = new SqliteCommand (sql_count, dbh);
                dbhReader = dbhCmd.ExecuteReader ();

                /**
                 * Get the number of devices for the array size.
                 */
                if (dbhReader.HasRows) {
                    dbhReader.Read ();
                    device_count = dbhReader.GetInt32 (1);

                    if (device_count == 0) {
                        cleanup ();
                        return null;
                    }

                } else {
                    cleanup ();
                    return null;
                }
            }

            _device_list = new CDeviceListItem[device_count];

            dbhCmd = new SqliteCommand (sql, dbh);
            dbhReader = dbhCmd.ExecuteReader ();

            if (dbhReader.HasRows) {
                while (dbhReader.Read ()) {
                    _device_list [count++] = new CDeviceListItem (dbhReader.GetString (0));
                }

                cleanup ();
                return _device_list;
            } else {
                cleanup ();
                return null;
            }

            cleanup ();
            return null;
        }