FIT2081 Lecture Notes - Lecture 8: Sqlite

160 views4 pages
!" #!$%&'%&(")$*+,')-
.(+/01'/'%&2(3(/'453%+2/(6$)(,3&3(253)+%7(8'&9''%(3002
:53)',(+%(&5'(6$)/($6(3%('%&+)'(:;<+&'(,8
=
>11$92(3%(300(&$(0)$*+,'($&5')2(9+&5(344'22(&$(?%,')1@+%7(,3&3A(32(9'11(
32(&5'(38+1+&@(&$(3,,A()'/$*'(3%,(B?')@(&5'(,3&3(#2?8C(&$(0')/+22+$%2-
=
D%&')34&2(9+&5($&5')(3002(&5)$?75(3(!E
=
!1322'2(&53&()'1@($%(!"F
CursorAdapter
AbstractThreadedSyncAdapter
=
G'&5$,2(#;DHI-
query(Uri, String[] projection,
String selection, String[] selectionArgs,
String sortOrder)
projection .(4$1?/%2(9'(93%&(&$(1$$J(6$)
§
sortOrder 311$92(2$)&+%7($6(,3&3(#324K,'24-(344$),+%7(&$(3(
4')&3+%(03)3/'&')A(8?&($6&'%(%$&(?2',L
§
"34J2(3)7?/'%&2(+%&$(3(Bundle
§
!3%(8'(4311',(6)$/(/?1&+01'(&5)'3,2A(95'%(@$?(%'',(&$(
/3&45(373+%2&(3(HEDA(4311(match#H)+-A(0)$*+,+%7(&5'(HE<(@$?(
53*'(8''%(7+*'%
§
!3%(?2'(&5+2()'2?1&(&$(8?+1,(3(B?')@A()'&?)%(3(&@0'A(+%2')&($)(
,'1'&'(3()$9('&4(9+&5$?&(,?01+43&+%7(311($6(&5'(+6M'12'(1$7+4(
@$?(9$?1,($&5')9+2'(%'',
§
E'&?)%2(Cursor $8C
§
insert(Uri, ContentValues)
I$'2%N&()'&?)%(3%@&5+%7
§
update(Uri, ContentValues, String selection,
String[] selectionArgs)
E'&?)%2(3%(+%&'7')(+%,+43&+%7(%?/8')($6()$92(366'4&',
§
delete(Uri, String selection,
String[] selectionArgs)
E'&?)%2(3%(+%&'7')(+%,+43&+%7(%?/8')($6()$92(366'4&',
§
=
E'B?+)',(&$(53*'F
!$%&'%& URI #H%+*')231(E'2$?)4'(D,'%&+6+')-(,'6+%',(8@(!"
.(311$92(3002(&$(20'4+6@(&5'(,3&3(&5'@(93%&(!"(&$($0')3&'($%
UriMatcher
§
.(?&+1+&@(41322(&$(3+,(+%(/3&45+%7(HED2(&$(!"2
addURI(String url/authority, String
PATH_VERSION, int SHAPES)
SHAPES +2(3(static final int ?2',(&$(
45'4J(&381'(4$1?/%(2&)+%7A(0)'M322+7%',(+%(!"(
41322
®
O
"3)2'2(HED(?2+%7(match(Uri)
>2J2(uriMatcher &$(7+*'(+%&'7')(&@0'($6(HED
®
P)+'2(&$(/3&45(+&(&$($%'($6(2'*')31(&'Q&(03&&')%2
®
R32(8''%(4$%6+7?)',(&$()'4$7%+2'(3(03&&')%A(
&5'%()'&?)%(&5'(,'6+%',(%?/')+4(4$,'(6$)(&5'(
03&&')%(+&(/3&45'2(
®
O
CONTENT_AUTHORITY
.(?%+B?'1@(+,'%&+6+'2(!"2
D2(?2?311@(&5'(authority *3)+381'(+%(addURI
§
.(>%,)$+,N2(2@/8$1+4(%3/'(6$)(&5'(!"(
H2'(034J37'(%3/'(8@(4$%*'%&+$%(2$(+&N2(?%+B?'($%(,'*+4'
§
D%20'4&',(8@(2@2&'/(95'%(!E(/3J'2(3()'B?'2&(&$(!"A(&5'%(
0322'2(&5'()'B?'2&(&$(&5'(!"()'7+2&')',(9+&5(&5'(3?&5$)+&@
!"(43%(&5'%(+%&')0)'&(&5'(HED(5$9'*')(+&(93%&2(
#03)2'2(+&-
O
§
=
getType
S$&(3(4311834J
D/01'/'%&(29+&45M432'
switch ((sUriMatcher.match(uri))) {
case SHAPES:
return
SchemeShapes.Shape.CONTENT_TYPE;
case SHAPES_ID:
return SchemeShapes.Shape
.CONTENT_ITEM_TYPE;
default:
throw new IllegalArgumentException
("Unknown URI: " + uri);
}
=
!E #!$%&'%&(E'2$1*')-
.(?2',(&$(344'22(!"
!$//?%+43&'2(9+&5(!"($8C(&$(0')6$)/(&5'()'B?'2&',(&32J($%(8'5316($6(&5'(300=
P$(3,,(&$(300F
T)$/(3(Fragment
ContentResolver resolver =
getActivity().getApplicationContext()
.getContentResolver()
T)$/(3%(>4&+*+&@
ContentResolver resolver = getContext().
getContentResolver();
U8&3+%2(3()'6')'%4'(&$(!E
§
resolver.insert(SchemeShapes.Shape.CONTENT_URI,
contentValues);
?)+(M&5'(3,,)'22($6(&5'(,3&3(&381'(8'+%7(344'22',
§
4$%&'%&V31?'2(M&5'(*31?'2(6$)(&5'()$9(8'+%7(3,,',(+%&$(&5'(,8
§
D%(FragmentA(#update__(eg. Shape) /'&5$,-
resolver.update(String authority, contentValues,
String where, String[] selectionArgs)
§
H0,3&'2()$9#2-(+%(3(4$%&'%&(HED
§
=
notifyChange
<'&2(!E(J%$9(3(453%7'(532($44?))',
S$)/311@(+%2+,'(insert, delete, update
=
CursorLoader(Context,Uri,String[] projection,
String selection,String[] selectionArgs,
String sortOrder)
.(3(1$3,')(&53&(B?')+'2(&5'(!E(3%,()'&?)%2(3(%'9(6?11@M20'4+6+',(
CursorLoader $8C'4&
03)3/W(contextF()'6')'%4'(&$(4?))'%&(>4&+*+&@=
03)3/X(uriF(4$%&'%&(HEDL(")$*+,'2(?)+(#1$43&+$%-($6(,3&3(&$(8'()'&)+'*',L=
03)3/Y(projectionF(3))3@($6(&381'(4$1?/%(%3/'2=
03)3/Z(selectionF(2'1'4&+$%(4)+&')+3L(>4&2(32(3(6+1&')(,'413)+%7(95+45()$92(
&$()'&?)%A(6$)/3&&',(32(3%(:;<([R\E\(413?2'L
=
03)3/](selectionArgsF(2'1'4&+$%(4$%,+&+$%2K3)7?/'%&2L(R$1,2(*31?'2(&$(
8'(8$?%,(+%&$(&5'(2'1'4&+$%(2&)+%7L
=
03)3/^(sortOrderF(2$)&($),')($6()$92A(6$)/3&&',(32(3%(:;<(UEI\E(_`(
413?2'
=
[$)J2(,+)'4&1@(9+&5(>4&+*+&@KFragmentA(&5'%(!E(#95+45(9$)J2(9+&5(!"-=
I3&3832'aXa:&?,'%&
I3&3832'aYa:&?,'%&
:&?,'%&2I3&3832'
Cursor
setNotificationUri(getContext().getContentResolver(),
uri);
E'&?)%2(&5'(HED(3&(95+45(%$&+6+43&+$%2($6(453%7'2(+%(&5+2(!?)2$)N2(
,3&3(9+11(8'(,'1+*')',
=
LoaderManager.LoaderCallbacks
onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
=
onCreateView(LayoutInflater inflater, ViewGroup
container, Bundle savedInstanceState)
b'&2(CustomView 3%,()'&?)%2(+&
getLoaderManager().initLoader(id, args, callback)
!)'3&'2(1$3,')(#+6(+&(,$'2%N&('Q+2&-(3%,(2&3)&2(+&
§
=
onCreateLoader(int i, Bundle bundle)
\22'%&+311@(3(4311(&$(&5'(!"N2(query /'&5$,
!)'3&'2(3(CursorLoader $8C(3%,()'&?)%2(+&
Returns a Loader<Cursor> $8C
=
onLoadFinished(Loader<Cursor> cursorLoader, Cursor
cursor)
\22'%&+311@(&5'(4?)2$)()'&?)%',(8@(!"N2(query /'&5$,
D&')3&'2(&5)$?75(4?)2$)(&$(7'&(,3&3
!311834J(+2(4$,',(&$()'34&(&$(3(6+%+25',(1$3,
!?)2$)<$3,')N2(>"D(4$,'(43112(+&(95'%(1$3,(532(6+%+25',
§
=
onViewCreated(View view, Bundle savedInstanceState)
=
onLoaderReset(Loader<Cursor> cursorLoader) {
simpleCursorAdapter.swapCursor(null);
=
}
Week$8
P?'2,3@A( Xc(G3@(XdWe
WWFdY
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Document Summary

= implements a mechanism for data sharing between apps. Shared in the form of an entire sqlite db. Allows an app to provide others with access to underlying data, as well as the ability to add, remove and query the data (subj to permissions) String sortorder) projection = columns we want to look for sortorder allows sorting of data (asc/desc) according to a certain parameter, but often not used. Can be called from multiple threads, when you need to match against a uri, call match(uri), providing the url you have been given. Can use this result to build a query, return a type, insert or delete a row etc without duplicating all of the if-else logic you would otherwise need. Returns an integer indicating number of rows affected delete(uri, string selection, Returns an integer indicating number of rows affected. Content uri (universal resource identifier) defined by cp. = allows apps to specify the data they want cp to operate on.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers