Beispiel #1
0
        /// <summary>
        /// Отобразить содержимое локальной БД
        /// </summary>
        /// <returns></returns>
        public ChannelsSetsList GetDataFromDB()
        {
            ChannelsSetsList setsList = new ChannelsSetsList();
            SQLiteDatabase   db;

            try
            {
                db = ReadableDatabase;
            } catch (Exception)
            {
                ClearDatabase();

                return(setsList);
            }

            // Работа с сетами
            ICursor allSets = db.RawQuery("SELECT * FROM " + SETS_TABLE_NAME, null);

            if (allSets.MoveToFirst())
            {
                String[] columnNames = allSets.GetColumnNames();
                do
                {
                    // Проходимся по каждому сету в таблице сетов и создаем новый объект сета
                    var a = allSets.GetString(allSets.GetColumnIndex(columnNames[0]));
                    setsList.AddSet(new ChannelsSet(allSets.GetString(allSets.GetColumnIndex(columnNames[1]))));
                } while (allSets.MoveToNext());
            }

            // Работа с каналами
            ICursor allChannels = db.RawQuery("SELECT * FROM " + CHANNELS_TABLE_NAME, null);

            if (allChannels.MoveToFirst())
            {
                String[] columnNames = allChannels.GetColumnNames();
                do
                {
                    // Проходимся по каждому каналу в таблице каналов
                    var     channelName     = allChannels.GetString(allChannels.GetColumnIndex(columnNames[1]));
                    var     channelPlatform = allChannels.GetString(allChannels.GetColumnIndex(columnNames[2]));
                    var     channelSetIndex = allChannels.GetString(allChannels.GetColumnIndex(columnNames[3]));
                    Channel channel         = new Channel(channelName, (DATA.Platforms)Int32.Parse(channelPlatform));
                    setsList.AddChannel(channel, Int32.Parse(channelSetIndex) - 1);
                } while (allChannels.MoveToNext());
            }

            return(setsList);
        }
Beispiel #2
0
 /// <summary>
 /// Returns the value of the requested column as a boolean.
 /// </summary>
 /// <returns>The boolean.</returns>
 /// <param name="cursor">Cursor.</param>
 /// <param name="column">Column name.</param>
 public static bool GetBoolean(this ICursor cursor, string column, bool bDefault = false)
 {
     try
     {
         return(cursor.GetInt(column) != 0); // cursor.GetColumnIndex(
     }
     catch (Exception ex)
     {
         string cAll = "";
         foreach (var c in cursor.GetColumnNames())
         {
             cAll += c + ", ";
         }
         sys.LogException(ex, "columnname: " + column + ", all: " + cAll);
         return(bDefault);
     }
 }
Beispiel #3
0
        public String GetTableAsString(String tableName)
        {
            SQLiteDatabase db          = ReadableDatabase;
            String         tableString = string.Format("Table {0}\n", tableName);
            ICursor        allRows     = db.RawQuery("SELECT * FROM " + tableName, null);

            if (allRows.MoveToFirst())
            {
                String[] columnNames = allRows.GetColumnNames();
                do
                {
                    foreach (String name in columnNames)
                    {
                        tableString += string.Format("{0}: {1}\n", name,
                                                     allRows.GetString(allRows.GetColumnIndex(name)));
                    }
                    tableString += "\n";
                } while (allRows.MoveToNext());
            }

            return(tableString);
        }
Beispiel #4
0
        public void OnLoadFinished(Loader loader, Java.Lang.Object data)
        {
            ICursor cursor = (ICursor)data;

            TextView tv = ((Activity)mContext).FindViewById <TextView> (Resource.Id.sample_output);

            // Reset text in case of a previous query
            tv.Text = mContext.GetText(Resource.String.intro_message) + "\n\n";

            if (cursor.Count == 0)
            {
                return;
            }

            // Pulling the relevant value from the cursor requires knowing the column index to pull
            // it from.

            int phoneColumnIndex  = cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Phone.Number);
            int emailColumnIndex  = cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Email.Address);
            int nameColumnIndex   = cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Contactables.InterfaceConsts.DisplayName);
            int lookupColumnIndex = cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Contactables.InterfaceConsts.LookupKey);
            int typeColumnIndex   = cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Contactables.InterfaceConsts.Mimetype);


            cursor.MoveToFirst();
            // Lookup key is the easiest way to verify a row of data is for the same
            // contact as the previous row.
            String lookupKey = "";

            do
            {
                String currentLookupKey = cursor.GetString(lookupColumnIndex);
                if (!lookupKey.Equals(currentLookupKey))
                {
                    String displayName = cursor.GetString(nameColumnIndex);
                    tv.Append(displayName + "\n");
                    lookupKey = currentLookupKey;
                }


                // The data type can be determined using the mime type column.
                String mimeType = cursor.GetString(typeColumnIndex);
                if (mimeType.Equals(ContactsContract.CommonDataKinds.Phone.ContentItemType))
                {
                    tv.Append("\tPhone Number: " + cursor.GetString(phoneColumnIndex) + "\n");
                }
                else if (mimeType.Equals(ContactsContract.CommonDataKinds.Email.ContentItemType))
                {
                    tv.Append("\tEmail Address: " + cursor.GetString(emailColumnIndex) + "\n");
                }


                // Look at DDMS to see all the columns returned by a query to Contactables.
                // Behold, the firehose!
                foreach (String column in cursor.GetColumnNames())
                {
                    Log.Debug(TAG, column + column + ": " +
                              cursor.GetString(cursor.GetColumnIndex(column)) + "\n");
                }
            } while (cursor.MoveToNext());
        }