Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Разработка Web-приложений для iPhone

.pdf
Скачиваний:
15
Добавлен:
09.04.2015
Размер:
5.2 Mб
Скачать

+'*$'", 2-26. G"3 #C01&)-4

E2%':#0.H*$3'. * ?%2#H 0%"";@. 6%H7 dbSQLStore.js

H&.00 ,)-%"3-+#4 $"3, 3.4 %7,".101-4 302#+%-2 # *&(&8- 3&117> (L-#+-1? 2-27).

//!"#$ dbSQLStore.js

var systemDB="not activated"; var status="";

var bookIndex=0;

function initDB(){ //M1-C-&.-(&C-- UH try {

if (!window.openDatabase) {

alert("%"&' ("))'* )+ ,-((+./01"2345" ); document.open();

document.write(":"9 7."A&+. )+ ,-((+./01"+3 7"&' ("))'*<br><input type='button' value='&"8.'3@' onclick='window.cl ose()'/>");

document.close(); } else {

var shortName = 'MyTrainingDataBase'; var version = '1.0';

var displayName = 'MyTrainingDataBase'; var maxSize = 2*1024*1024; // in bytes

var myDB = openDatabase(shortName, version, displayName, maxSize);

}

} catch(e) {

alert("Unknown error: "+e+"."); // 67."7-38" -907-8

if (e == INVALID_STATE_ERR) { alert("Invalid database version."+e);

}else {

alert("Unknown error: "+e+".");

}

return;

}

reportStatus("%"&" ("))'* "83010.-1")"." ); createTables(myDB);

systemDB = myDB;

}

function reportStatus(s){ //'0?-#+)&C-4 302#+%-2 # *&("2 status+="<br/>"+s;

document.getElementById('status').innerHTML= status;

}

//////////

function createTables(db)

41

{

/* A"(3&1-0 +&*.-C */

db.transaction(

function (transaction) {

transaction.executeSql(

'CREATE TABLE IF NOT EXISTS Books (ISBN TEXT PRIMARY KEY,Title TEXT,Price REAL,Authors TEXT);',

[], nullDataHandler, killTransaction); //D-?")( SQL ?-/+3 7'3@ )+48-$@8-

transaction.executeSql(

'CREATE TABLE IF NOT EXISTS TextBook (ISBN TEXT PRIMARY KEY,HTMLText BLOB);',

[], successHandler, errorHandler);

}

);

}

function selectCount(db)

{

/* A:-+&0+ :-#." $1-? */

db.transaction(

function (transaction) {

//C(+4@ ?-/)- ,04"3@ Javascript 8-( transaction.executeSql(

'SELECT count() as "total" FROM Books', [], processSelectCount, killTransaction);

}

);

}

function processSelectCount(transaction,results){ //S*)&*&+7%&0+ :-#." $1-?

var total=results.rows.item(0)['total']; initPage(total);

}

//

function selectBookByISBN(db,isbn)

{

/* <7*") $1-?- ," ISBN */

db.transaction(

function (transaction) {

//C(+4@ ?-/)- ,04"3@ Javascript 8-( transaction.executeSql(

'SELECT Books.ISBN as "ISBN",Title,Price,Authors,HTMLText FROM

42

Books,TextBook where Books.ISBN=TextBook.ISBN AND Books.ISBN=?', [isbn], processBookByISBN, killTransaction);

}

);

}

//

function processBookByISBN(transaction,results) { //S*)&*"+$& $1-?-

document.getElementById("formTitle").value=results.rows.item(0)['Title']; document.getElementById("formAuthors").value=

results.rows.item(0)['Authors']; document.getElementById("formPrice").value=results.rows.item(0)['Price']; document.getElementById("formBody").value=results.rows.item(0)['HTMLText']; document.getElementById("formISBN").value=results.rows.item(0)['ISBN'];

reportStatus("K-$5 !-.?' A43")-1$+)'" );

}

//

function selectISBNs(db)

{

/* <7*")$& %#0> $1-? */ db.transaction(

function (transaction) {

//C(+4@ ?-/)- ,04"3@ Javascript 8-( transaction.executeSql(

'SELECT ISBN,Title FROM Books', [], processSelectISBNs, killTransaction);

}

);

}

function processSelectISBNs(transaction,results){ //9#+&1"%$& #0.0$+")& $1-?

var len=results.rows.length;

var slctr=document.getElementById('bookISBNSelect'); slctr.length=len;

for(var i=0;i<len;i++){ slctr.options[i].value=results.rows.item(i)["ISBN"]; slctr.options[i].text=results.rows.item(i)['Title'];

}

reportStatus("B+$+83-.' 8)0I A43")-1$+)'" ); setBookInfo(bookIndex);

}

//////////////

function initPage(total){ // S*1"%.01-0 %-3& #+)&1-C7

reportStatus(":4+I- 8)0I:"+total);

43

if(total==0){ insertFirstBook(); bookIndex=0; return;

}

selectISBNs(systemDB);

}

function insertFirstBook(){ //F0)%&4 $1-?& % B")8&+0 ," @8".:&1-=

document.getElementById("formTitle").value="F"&1")0+"; document.getElementById("formAuthors").value="G13-.'"; document.getElementById("formPrice").value=10.5; document.getElementById("formBody").value="H+843"; document.getElementById("formISBN").value="ISBN"; addBook(systemDB);

}

function deleteBook(db)

{

/* 93&.01-0 $1-?- -( *&(7 */

db.transaction(

function (transaction) {

transaction.executeSql(

'DELETE FROM Books WHERE ISBN=?;', [document.getElementById("formISBN").value], nullDataHandler,

killTransaction);

transaction.executeSql(

'DELETE FROM TextBook WHERE ISBN=?;', [document.getElementById("formISBN").value], processDeleteBook,

killTransaction);

}

);

}

function updateBook(db)

{

/* S*1"%.01-0 $1-?- */

db.transaction(

function (transaction) {

//C(+4@ ?-/)- ,04"3@ Javascript 8-( transaction.executeSql(

'DELETE FROM Books WHERE ISBN=?;', [document.getElementById("formISBN").value], nullDataHandler,

killTransaction);

transaction.executeSql(

44

'DELETE FROM TextBook WHERE ISBN=?;', [document.getElementById("formISBN").value], nullDataHandler, killTransaction); transaction.executeSql(

'INSERT INTO Books (ISBN,Title,Price,Authors) values

(?,?,?,?);', [document.getElementById("formISBN").value,

document.getElementById("formTitle").value, document.getElementById("formPrice").value, document.getElementById("formAuthors").value ], nullDataHandler, killTransaction);

//

transaction.executeSql(

'INSERT INTO TextBook (ISBN,HTMLText) values (?,?);', [document.getElementById("formISBN").value,

document.getElementById("formBody").value ], processUpdateBook, errorHandler);

}

);

}

function addBook(db)

{

/* H"*&%.01-0 $1-?- */ db.transaction(

function (transaction) {

//

transaction.executeSql(

'INSERT INTO Books (ISBN,Title,Price,Authors) values

(?,?,?,?);', [document.getElementById("formISBN").value,

document.getElementById("formTitle").value, document.getElementById("formPrice").value, document.getElementById("formAuthors").value ], nullDataHandler, processFatalErrorAddBook);

//

transaction.executeSql(

'INSERT INTO TextBook (ISBN,HTMLText) values (?,?);', [document.getElementById("formISBN").value,

document.getElementById("formBody").value

], processAddBook, processFatalErrorAddBook);

}

);

}

function processDeleteBook(transaction,results){ //93&.01-0 $1-?- ,)"E." @#,0E1" reportStatus("D)0I" A("$+)"" ); selectISBNs(systemDB);

45

}

function processUpdateBook(transaction,results){ //S*1"%.01-0 $1-?- (&%0)E01"

reportStatus("D)0I" -7)-1$+)""); selectISBNs(systemDB);

}

function processAddBook(transaction,results){ //G1-?& 3"*&%.01& @#,0E1"

reportStatus("D)0I" (-7"1$+)"" );

}

function processFatalErrorAddBook(transaction,error){ //F",7+$& 3"*&%-+6 $1-?@ # #@D0#+%@=D-8 ISBN reportStatus("69078", 8)0I" 4 3"80? ISBN 4AJ+431A+3." ); return true;

}

//////////////

//SU';USPG; CG:=LO=FPX D6QGFE B 6OP%DGQP /*! K.+8."J+)0+ (+#4310# */

function killTransaction(transaction, error)

{alert(error.message);

return true; // fatal transaction error

}

//=4$0 1',-$)+)0+ 3.")&"8>00 ?-/)- ,.-(-$/"3@, 3- 1+.)A3@ false function errorHandler(transaction, error)

{

reportStatus('A""*D01-0:'+error.message+' (G"3 "E-*$-:' +error.code+'):'+warning);

//

var we_think_this_error_is_fatal = true;

// if (we_think_this_error_is_fatal) return true; return false;

}

//N4,+9)-+ CG:=LO=FP= D6QGFE

function nullDataHandler(transaction, results)

{

//L+&A$@3"3' 8-?")(' SQL )+ -/0("2345, )0<+I- (+$"3@ )+ )"(-

}

function successHandler(transaction, results)

{

//FA/)- -7."7"3'1"3@ results //P&*.-C7 @#,0E1" #"(3&17 reportStatus("H"7$0>' 4-&(")'" ); selectCount(systemDB);

}

+'*$'", 2-27. Q@1$C--, "*0#,0:-%&=D-0 %(&-8"302#+%-0 # *&("2 3&117>

F)&$+-:0#$- %#4 B@1$C-"1&.61"#+6 I+"2 :+- ,)-."/01-4 *7.& )#8"+)01& %7E0. G"8801+&)-- $ $"3@ ,"4#14=+ -#,".6("%&1-0 +0> B@1$C-2, $"+")70 10 *7.- ,"4#1017 % +0$#+0.

46

!"#$%"&'#() *"+%",(

1)U)&@(0) 8"/0+ 10 ,"330)/-%&+6 )&*"+@ # ."$&.6178- *&(&8- 3&117>. G&$-8 "*)&("8 8"/1" ,)"%0)-+6 #@D0#+%"%&1-0 +&$"2 ,"330)/$-?

2)F)-%03-+0 80+"3 Javascript 3.4 #"(3&1-4 -.- "+$)7+-4 *&(7 3&117>. F"4#1-+0 ,&)&80+)7 80+"3&, ,0)0:-#.-+0 "E-*$-, $"+")70 8"?@+ %"(1-$&+6 ,)- 0?" -#,".101--, ,"$&/-+0 #,"#"* ,0)0>%&+& "E-*"$ ,)"?)&88"2, ,)03."/-+0 #,"#"* "*)&*"+$- "E-*"$.

3)F)-%03-+0 ,)-80) +)&1(&$C-- 3.4 #"(3&1-4 +&*.-C7 customer(id,telephone_nom,name,orderId,totalprice)

F"4#1-+0 -#,".6(@0870 ,&)&80+)7 - ,")43"$ %7,".101-4 302#+%-2.

4)F)-%03-+0 ,)-80) +)&1(&$C-- 3.4 "*1"%.01-4 3&117> % +&*.-C0

User(id,name,login,password)

V&801-+6 (1&:01-4 10"*>"3-8" % ,".4> login - password. F"4#1-+0 -#,".6(@0870 ,&)&80+)7 - ,")43"$ %7,".101-4 302#+%-2. < #.@:&0 10"*>"3-8"#+- 3",-E-+0 10"*>"3-872 $"3. 5)F)-%03-+0 ,)-80) +)&1(&$C-- 3.4 %7*")$- -( +&*.-C

customer(customerId,telephone_nom,name,orderId,totalprice) user(userId,name,login,password)

3&117> ," +0.0B"1&8, ."?-1&8 - ,&)".48. M801& ,0)#"1 % $&/3"2 -( +&*.-C @1-$&.617. F"4#1-+0 -#,".6(@0870 ,&)&80+)7 - ,")43"$ %7,".101-4 302#+%-2. < #.@:&0 10"*>"3-8"#+- 3",-E-+0 10"*>"3-872 $"3.

6)F"4#1-+0 80>&1-(8 "*)&*"+$- +)&1(&$C-2. J& ,)-80)0 ,"$&/-+0 ,")43"$ %7,".101-4 +)&1(&$C-2. G&$ ,)"?)&88& 3"./1& )0&?-)"%&+6 1& )&(.-:170 #.@:&- (&%0)E01-4 "*)&*"+$- +)&1(&$C--?

-./.#01 /&1 ,.2",$"1$)&'#"3 +%"%.4"$50

J&,-#&+6 HTML $"3 - Javascript #C01&)-2 3.4 )0E01-4 #.03@=D-> (&3&:

1.< +&*.-C&> order(orderId,customerId,totalPrice)

customer(customerId,name)

,)-%03017 3&1170 " (&$&(&> - (&$&(:-$&>. A"(3&+6 *&(@ 3&117>, #"30)/&D@= ," 2-3 (&,-#- % $&/3"2 +&*.-C0. <7*)&+6 -( *&(7 - ,)-%0#+- 1& WEB #+)&1-C0 3&1170 "* -801- (&$&(:-$& - #@88&)1"2 #@880 (&$&("% 1& 8-1-8&.61@= - 8&$#-8&.61@= #@88@.

2.< +&*.-C&> department(depId,employeId) employee(employeId,name,salary)

,)-%03017 3&1170 "* "+30.&> - #"+)@31-$&>. A"(3&+6 *&(@ 3&117>, #"30)/&D@= ," 10#$".6$" (&,-#02 % $&/3"2 +&*.-C0. <7*)&+6 -( *&(7 - ,)-%0#+- 1& WEB #+)&1-C0 3&1170 "* "+30.0 # 8&$#-8&.61"2 #@88&)1"2 (&),.&+"2 (salary) #"+)@31-$"%.

3.< +&*.-C&> department(depId,employeId,telephoneNom) employee(employeId,name,salary)

,)-%03017 3&1170 "* "+30.&> - #"+)@31-$&>. A"(3&+6 *&(@ 3&117>, #"30)/&D@= ," 10#$".6$" (&,-#02 % $&/3"2 +&*.-C0. <7*)&+6 -( *&(7 - ,)-%0#+- 1& WEB #+)&1-C0 +0.0B"1

--84 #"+)@31-$& # 1&-8016E02 (&),.&+"2.

4.< +&*.-C&> order(orderId,customerId,totalPrice) customer(customerId,name,telephoneNom)

,)-%03017 3&1170 " (&$&(&> - (&$&(:-$&>. A"(3&+6 *&(@ 3&117>, #"30)/&D@= ," 2-3 (&,-#- % $&/3"2 +&*.-C0. <7*)&+6 -( *&(7 - ,)-%0#+- 1& WEB #+)&1-C0 3&1170 "* -801- - +0.0B"10 (&$&(:-$&, #30.&%E0?" (&$&( ,"#.031-8 (F"3#$&($&: orderId *@30+ 8&$#-8&.6178).

5. < +&*.-C&> department(depId,projectId,telephoneNom) project(projectId,title,totalPrice)

,)-%03017 3&1170 " 30,&)+&801+&> - ,)"0$+&>. A"(3&+6 *&(@ 3&117>, #"30)/&D@= ," 2-3 (&,-#- % $&/3"2 +&*.-C0. <7*)&+6 -( *&(7 - ,)-%0#+- 1& WEB #+)&1-C0 3&1170 " 1&(%&1--

47

,)"0$+& - +0.0B"10 "+30.& # 8&$#-8&.61"2 #+"-8"#+6= -#,"101-4. 6. < +&*.-C0

projects(id,title,totalPrice)

,)-%03017 3&1170 ,)"0$+&>. A"(3&+6 *&(@ 3&117>, #"30)/&D@= 10#$".6$" (&,-#02 % +&*.-C0. F"8014+6 80#+&8- (1&:01-4 totalPrice % (&,-#4> # 8&$#-8&.61"2 - 8-1-8&.61"2 #+"-8"#+6=. '0(@.6+&+7 ,"$&(&+6 1& WEB #+)&1-C0

-.5&67)#0)

= E&"8 )&(30.0 *7.- )#8"+)017 -#$.=:-+0.61" %&/170 %",)"#7 -#,".6("%&1-4 $.-01+#$-> *&( 3&117> 3.4 #">)&101-4 -1B")8&C-- 1& ."$&.61"2 8&E-10. < )#8"+)0117> ,)-80)&> ,"$&(&17 %#0 "#1"%170 ,)-087 )&*"+7 # *&(&8- 3&117>. '#8"+)-+0 %1-8&+0.61" ,)-80)7, "+%0+6+0 1& %",)"#7 - ,)")0E&2+0 ,)03."/01170 (&3&:-.

48

3. XML HTTP 7&4"0-,

< I+"2 :+- ,"#"*-4 )#8&+)-%&=+#4 80+"37 %(&-8"302#+%-4 WEB ,)-."/01-4 # #0)%0)"8

# -#,".6("%&1-08 XML HTTP (&,)"#"%. K+" "31& -( %&/102E-> +0>1"."?-2, "*0#,0:-%&=D&4 %(&-8"302#+%-0 # #0)%0)"8 %" %)084 -#,".101-4 $.-01+#$"?" ,)-."/01-4.

3.1. !"#$% &'()*+#+,- XML HTTP .%(/)0%

V&,)"#7 $ XML 3"$@801+&8 %#+)&-%&=+#4 % #C01&)--, -#,".140870 1& $.-01+#$"2 #+")"10. S1- -#,".14=+#4 -1>)"1" - ,"(%".4=+ #C01&)-= 3-1&8-:0#$- -(8014+6 #+)&1-C@ -.- 00 B)&?801+7, 10 %7,".144 ,0)0(&?)@($@ #+)&1-C7 ,".1"#+6=. A>08& %7,".101-4 (&,)"#& ,)-%0301& 1-/0 ('-#. 3-1).

)'*. 3-1. 9,)"D011&4 %7,".101-4 XML HTTP (&,)"#&

A"*#+%011" %(&-8"302#+%-0 $.-01+#$"?" ,)-."/01-4 # #0)%0)"8 %7,".140+#4 $&$ ,"#.03"%&+0.61"#+6 10#$".6$-> +-,"%7> 302#+%-2.

1.F)- %7,".101-- #C01&)-4 1& WEB #+)&1-C0 %#+)0:&0+#4 (&,)"# $ XML 3"$@801+@, ),"."/011"8@ 1& #0)%0)0.

2.V&,)"# 1&,)&%.40+#4 $ WEB-#0)%0)@, #+)&1-C& 1& $.-01+#$"2 #+")"10 ,)"3"./&0+ 1&>"3-+6#4 ,"3 @,)&%.01-08 #+)&1-:1"?" #C01&)-4. WEB #0)%0) ,)-1-8&0+ (&,)"# - "*)&*&+7%&0+ 0?" #&8"#+"4+0.61" -.- ,0)03&0+ $ #0)%0)1"2 :+- ,)-."/01-4

3.A0)%0)1&4 :+6 ,)-."/01-4 -.- ?010)-)@0+ (6), -.-

4.A0)%0)1&4 :+6 c:-+7%&0+ "3-1 -.- 10#$".6$" B&2."%

5.F".@:01170 3&1170 "*)&*&+7%&=+#4, -( 1-> $"8,"1@0+#4 03-172 3"$@801+

6.H"$@801+ %"(%)&D&0+#4 WEB #0)%0)@

49

7.WEB #0)%0) %"(%)&D&0+ 3"$@801+ #+)&1-:1"8@ #C01&)-=

8.Q@1$C-4-"*)&*"+:-$ (&%0)E01-4 (&,)"#& ,".@:&0+ )0(@.6+&+7 -, % #""+%0+#+%-- #

."?-$"2 "*1"%.01-4, -(80140+ 3&1170 #C01&)-4 -, 0#.- 10"*>"3-8", "+"*)&/&0+ 3&1170 1& #+)&1-C0.

S#"*011"#+6 3&11"?" %-3& %(&-8"302#+%-4 #"#+"-+ % +"8, :+" #+)&1-C&, %7,".14=D&4 (&,)"# 10 ,0)0(&?)@/&0+#4, 00 -(80101-0 ,)"-#>"3-+ +".6$" % #""+%0+#+%-- # ."?-$"2 #C01&)-4, #,"#"* -(80101-4 %7*-)&0+#4, & %#0 +)0*@0870 302#+%-4 %7,".14=+#4 1& $.-01+#$"2 #+")"10.

3.2. 1)23$#+4' XML

5+" XML 3"$@801+7 3&=+ *".00 ?-*$@= - @3"*1@= #>08@ ,)03#+&%.01-4 #+)@$+@)-)"%&117> 3&117>, :08 )0.4C-"1170 A9UH. H"$@801+7 XML ,)03#+&%.4=+#4 % ,)"#+"2, 3"#+@,1"2 3.4 :+01-4 :0."%0$"8, B")80. L-#+-1? 3-1 ,"$&(7%&0+ ,)"#+"2 XML 3"$@801+, #"30)/&D-2 -1B")8&C-= " 10$"+")"2 ")?&1-(&C--.

//Q&2. Departments.XML

<?xml version="1.0" encoding="utf-8" ?> <organization name="myOrg">

6,04")0+ -.I")0&">00 myOrg

<department title="department1" telno="123-45-67">

B-43-03 0& 4-3.A()08-1

<employee name="P1")-1" salary="111"/> <employee name="K+3.-1" salary="112"/>

</department>

<department title="department2" telno="123-45-67">

B-43-03 0& 4-3.A()08-1 department2 <employee name="B0(-.-1" salary="121"/> <employee name="=.+?0)" salary="72"/> <employee name="P$@0)" salary="12"/>

</department>

</organization>

+'*$'", 3-1. S,-#&1-0 #+)@$+@)7 ")?&1-(&C-- # -#,".6("%&1-08 XML

H"$@801+ #"30)/-+ (&?"."%"$ +0$#+7 - )&(80+$@, (&3&%&08@= ,)"#+78- (unary) - #"#+&%178- (binary) +0?&8-.

V&?"."%"$ -800+ #.03@=D@= ,)"#+@= B")8@

<?xml version="1.0" encoding="utf-8" ?>

S1 #"30)/-+ #%0301-4 " %0)#-- XML - ,)-14+"2 3.4 >)&101-4 3"$@801+& $"3-)"%$0. M1B")8&C-4, #"30)/&D&4#4 % 3"$@801+0 )&(80:&0+#4 #,0C-&.6178- +0?&8-, @$&(7%&=D-8- 1& #+)@$+@)1@= ,"3:-1011"#+6 I.0801+"% 3"$@801+&, ,&)&80+)7, "+1"#4D-0#4 $ I.0801+@, -, #"*#+%011", 3&1170, #"30)/&D-0#4 % ",)030.011"8 )&(30.0 3"$@801+&.

P0?- *7%&=+ ,)"#+70 - #"#+&%170.

F)"#+"2 +0? 10 #"30)/-+ 3)@?-> %."/0117> I.0801+"%. F)-80) ,)"#+"?" +0?& ,)-%"3-+#4 1-/0.

<employee name="B0(-.-1" salary="121"/>

F)"#+"2 +0?, ,"$&(&1172 %7E0, (&3&0+ -84 1&14+"?" )&*"+1-$& (employee) # ,"8"D6=

50

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]