Esempio n. 1
0
    def getAllContacts(self):
        contactList = list([Contact])
        # List<Contact> contactList = new ArrayList<>()
        
        # db = SQLiteDatabase.getReadableDatabase() 

        # Select all contacts from the database table
        selectAll = "SELECT * FROM " + Util.TABLE_NAME 
        Cursor cursor = self.database.rawQuery(selectAll,None)

        # loop through the data
        if cursor.moveToFirst():
            ' Was originally a java do{ while { } } loop ' 
            # do:
            while cursor.moveToNext():
                contact = Contact() 
                contact.setId(Integer.parseInt(cursor.getString(0))) 
                contact.setName(cursor.getString(1)) 
                contact.setPhoneNumber(cursor.getString(2))
                
                # add contact objects to our list
                contactList.add(contact)
            # while cursor.moveToNext():
            
        cursor.close() 
        return contactList
Esempio n. 2
0
    def getContact(self,Contact):
        
        contact = Contact.getContact(uid)
        db = SQLiteDatabase.getReadableDatabase()
        
        cursor = SQLiteDatabase.cursor()
        
        # cursor is used to iterate through db table elements
        cursor = db.query(Util.TABLE_NAME,list((Util.KEY_ID,Util.KEY_NAME, Util.KEY_PHONE_NUMBER)),Util.KEY_ID +"=?", list(String.valueOf(id)),None,None,None) 

        if cursor != None:
            cursor.moveToFirst() 

        contact = Contact() 
        contact.setId(Integer.parseInt(cursor.getString(0))) 
        contact.setName(cursor.getString(1)) 
        contact.setPhoneNumber(cursor.getString(2)) 

        cursor.close() 

        return contact