SelectAsync() public static method

Asynchonously selects data from the database.
public static SelectAsync ( string statement ) : Task
statement string The statement.
return Task
Esempio n. 1
0
        public static async Task <List <Face> > GetAllFaces()
        {
            var list = new List <Face>();

            using (var result = await DatabaseHandler.SelectAsync("SELECT f.id as id, f.grayframe as grayframe, f.original as original, f.userID as userID, u.username as username, f.width as width, f.height as height FROM faces f, users u WHERE u.id = f.userID"))
            {
                if (result == null)
                {
                    return(list);
                }

                while (result.Read())
                {
                    try
                    {
                        list.Add(new Face
                                 (
                                     (byte[])result["original"],
                                     (byte[])result["grayframe"],
                                     Convert.ToInt32(result["id"]),
                                     (string)result["username"],
                                     Convert.ToInt32(result["userID"]),
                                     Convert.ToInt32(result["width"]),
                                     Convert.ToInt32(result["height"])
                                 ));
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Error reading fae data: " + ex);
                    }
                }
            }

            return(list);
        }
Esempio n. 2
0
        public static async Task <List <User> > GetAllUsers()
        {
            var list = new List <User>();

            using (var result = await DatabaseHandler.SelectAsync("SELECT id, username, firstname, lastname FROM users"))
            {
                if (result == null)
                {
                    return(list);
                }

                while (result.Read())
                {
                    try
                    {
                        list.Add(new User(
                                     Convert.ToInt32(result["id"]),
                                     (string)result["username"],
                                     (string)result["firstname"],
                                     (string)result["lastname"]
                                     ));
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Error reading user data: " + ex);
                    }
                }
            }

            return(list);
        }