數(shù)據(jù)庫系統(tǒng)基礎(chǔ)教程第一版數(shù)據(jù)庫習(xí)題答案ch9_第1頁
數(shù)據(jù)庫系統(tǒng)基礎(chǔ)教程第一版數(shù)據(jù)庫習(xí)題答案ch9_第2頁
數(shù)據(jù)庫系統(tǒng)基礎(chǔ)教程第一版數(shù)據(jù)庫習(xí)題答案ch9_第3頁
數(shù)據(jù)庫系統(tǒng)基礎(chǔ)教程第一版數(shù)據(jù)庫習(xí)題答案ch9_第4頁
數(shù)據(jù)庫系統(tǒng)基礎(chǔ)教程第一版數(shù)據(jù)庫習(xí)題答案ch9_第5頁
已閱讀5頁,還剩63頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

9.3.1

Inthefollowing,weusemacroNOT_FOUNDasdefinedinthesection.

voidclosestMatchPC(){

EXECSQLBEGINDECLARESECTION;

charmanfzSQLSTATE[6];

inttargetPriceA/*holdspricegivenbyuser*/

floattempSpeed,speedOfClosest;

chartempModel[4],modelOfClosest[4];

inttempPrice,priceOfClosest;

/*fortuplejustreadfromPC&closestpricefoundsofar*/

EXECSQLENDDECLARESECTION;

EXECSQLDECLAREpcCursorCURSORFOR

SELECTmodel,price,speedFROMPC;

EXECSQLOPENpcCursor;

/*askuserfortargetpriceandreadtheanswerintovariable

targetPrice★/

/★Initially^thefirstPCistheclosesttothetargetprice.

IfPCisempty,wecannotanswerthequestion,andsoabort.*/

EXECSQLFETCHFROMpcCursorINTO:modelOfClosestz:priceOfClosest/

:speedOfClosest;

if(NOT_FOUND)/★printmessageandexit*/;

while(1){

EXECSQLFETCHpcCursorINTO:tempModel,:tempprice,

:tempSpeed;

if(NOTFOUND)break;

if(/*tempPriceclosertotargetPricethanispriceOfClosest*/)

modelOfClosest=tempModel;

priceOfClosest=tempPrice;

speedOfClosest=tempSpeed;

}

)

/*Now,modelOfClosestisthemodelwhosepriceisclosestto

target.Wemustgetitsmanufacturerwithasingle-rowselect*

EXECSQLSELECTmaker

INTO:manf

FROMProduct

WHEREmodel=:modelOfClosest;

,,H

printf(manf=%s/model=%d,speed=%d\nr

manf,modelOfClosestzspeedOfClosest);

EXECSQLCLOSECURSORpcCursor;

}

b)

voidacceptableLaptop(){

EXECSQLBEGINDECLARESECTION;

intminRam,minHd,minScreen;/*givenbyuser*/

floatminSpeed;

charmodel[4]zmaker,

floatspeed;

intram,hdzscreen,price;

EXECSQLENDDECLARESECTION;

EXECSQLPREPAREquerylFROM

'SELECTmodel,speed,ram,hd,screen,price,maker

FROMLaptop1,Productp

WHEREspeed>=?AND

ram>=?AND

hd>=?AND

screen>=?AND

1.model=p.modelz

EXECSQLDECLAREcursorlCURSORFORqueryl;

/*askuserforminimumspeed,ram,hdsize,andscreensize*/

EXECSQLOPENcursorlUSING:minSpeed,:minRam,:minHd,:minScreen;

while(!NOT_FOUND){

EXECSQLFETCHcursorlINTO

:model,:speed,:ram,:hd,:screen,:price,:maker;

if(FOUND)

(

printf("maker:%s,model:%dz\n

H

speed:%.2fzram:%dzhd:%dzscreen:%d,price:%d\nz

maker,model,speed,ram,hd,screen,price);

)

)

EXECSQLCLOSECURSORcursorl;

voidproductsByMaker(){

EXECSQLBEGINDECLARESECTION;

charmaker,model[4],type[10]zcolor[6];

floatspeed;

intram,hdzscreen,price;

EXECSQLENDDECLARESECTION;

EXECSQLPREPAREquerylFROM

'SELECT*FROMPC

WHEREmodelIN(SELECTmodelFROMProduct

WHEREmaker=?AND

type=、pc,);

EXECSQLPREPAREquery2FROM

'SELECT*FROMLaptop

WHEREmodelIN(SELECTmodelFROMProduct

WHEREmaker=?AND

type='laptop*);

EXECSQLPREPAREquery3FROM

'SELECT*FROMPrinter

WHEREmodelIN(SELECTmodelFROMProduct

WHEREmaker=?AND

type='printer');

EXECSQLDECLAREcursorlCURSORFORqueryl;

EXECSQLDECLAREcursor2CURSORFORquery2;

EXECSQLDECLAREcursor3CURSORFORquery3;

*askuserformanufacturer*

,z

Printf(''maker:%s\nzmaker);

/*getPCsmadebythemanufacturer★

EXECSQLOPENcursorlUSING:maker;

Printf(''producttype:PC\n〃);

while(!NOTFOUND){

EXECSQLFETCHcursorlINTO

:model,:speed,:ram,:hd,:price;

if(FOUND)

,,

printf("model:speed:%.2fzram:%d,hd:%d,price:%d\nA

model,speed,ram,hd,price);

)

)

/*getLaptopsmadebythemanufacturer*/

EXECSQLOPENcursor2USING:maker;

Printf(''producttype:Laptop\n,/);

while(!NOT_FOUND){

EXECSQLFETCHcursor2INTO

:model,:speed,:ram,:hdz:screen,:price;

if(FOUND)

(

n

printf(model:%dzspeed:%.2fzram:%dzhd:%d,screen:%dz

price:%d\nn,model,speed,ram,hd,screen,price);

)

)

/*getPrintersmadebythemanufacturer*/

EXECSQLOPENcursor3USING:maker;

Printf(''producttype:Printer\n,/);

while(!NOT_FOUND){

EXECSQLFETCHcursor3INTO

:model,:color,:type,:price;

if(FOUND)

(

printf("model:%d,color:%s,type:%s,price:%d\nn,

model,color,type,price);

)

)

EXECSQLCLOSECURSORcursorl;

EXECSQLCLOSECURSORcursor2;

EXECSQLCLOSECURSORcursor3;

}

d)

voidwithinBudget(){

EXECSQLBEGINDECLARESECTION;

inttotal_budget,rest_budgetzpc_pricezprinter_price;

charpc_model[4]fprinter_model[4]zcolor[6];

floatmin_speed;

EXECSQLENDDECLARESECTION;

EXECSQLPREPAREquerylFROM

'SELECTmodel,priceFROMPC

WHEREspeed>=?ANDprice<=?

ORDERBYprice';

EXECSQLPREPAREquery2FROM

'SELECTmodel,priceFROMPrinter

WHEREprice<=?ANDcolor=?

ORDERBYprice';

EXECSQLDECLAREcursorlCURSORFORqueryl;

EXECSQLDECLAREcursor2CURSORFORquery2;

/*askuserforbudget&theminimumspeedofpc*/

/*getthecheapestPCoftheminimumspeed*/

EXECSQLOPENcursorlUSING:min_speedz:total_budget;

EXECSQLFETCHcursorlINTO:pc_modelf:pc_price;

if(NOT_FOUND)

Printf(''nopcfoundwithinthebudget\n〃);

else

(

,/

Printf(''pcmodel:%s\nrpc_model);

)

/*getPrinterwithinthebudget*/

rest_budget=total_budget-pc_price;

color=''true";

EXECSQLOPENcursor2USING:rest_budgetz:color;

EXECSQLFETCHcursor2INTO:printer_model;

if(NOT_FOUND){

EXECSQLCLOSECURSORcursor2;

color="false”;

EXECSQLOPENcursor2USING:rest_budget,:color;

if(NOT_FOUND)

printf(''noprinterfoundwithinthebudget\n〃);

else{

EXECSQLFETCHcursor2INTO:printer_model;

printf(''printermodel:%s\n〃,printer_model);

)

)

else(

,/

printf(''printermodel:%s\nzprinter_model);

}

EXECSQLCLOSECURSORcursorl;

EXECSQLCLOSECURSORcursor2;

e)

voidnewPCproduct(){

EXECSQLBEGINDECLARESECTION;

charpmaker,pmodel[4]zptype[6];

floatpspeed;

intpram,phd,pscreen,pprice;

intpcount;

EXECSQLENDDECLARESECTION;

EXECSQLPREPAREstmtlFROM

'SELECTCOUNT(*)INTO:count

FROMPC

WHEREMODEL=?;

EXECSQLPREPAREStmt2FROM

z

'INSERTINTOProductVALUES(?z?,?);

EXECSQLPREPAREstmt3FROM

z

'INSERTINTOPCVALUES(?z?,?z2,?);

/*askuserformanufacturer/model,speed,RAM,hard-disk,

&priceofanewPC

EXECSQLEXECUTEstmtlUSING:pmodel;

IF(count>0)

Printf(''Warnning:ThePCmodelalreadyexists\n/,);

ELSE

(

EXECSQLEXECUTEstmt2USING:pmaker,:pmodel,:ptype;

EXECSQLEXECUTEstmt3UINGNG:pmodel,:pspeedz:pram,

:phd,:pprice

)

)

9.3.2

a)

voidlargestFirepower(){

EXECSQLBEGINDECLARESECTION;

charcclass[20],maxFirepowerClass[20];

intcnumGuns,chore;

floatfirepower,maxFirepower;

EXECSQLENDDECLARESECTION;

EXECSQLDECLAREcursorlCURSORFOR

SELECTclass,numGuns,boreFROMClasses;

EXECSQLOPENcursorl;

EXECSQLFETCHFROMcursorlINTO:cclass,:cnumGuns,:cbore;

if(NOT_FOUND)/*printmessageandexit*/;

maxFirepower=cnumGuns*(power(chore,3));

strcpy(maxFirepowerClass,cclass);

while(1){

EXECSQLFETCHcursorlINTO:cclassz:cnumGunsf:chore;

if(NOT_FOUND)break;

firepower=cnumGuns*(power(chore,3));

if(firepower>maxFirepower)

maxFirepower=firepower;

strcpy(maxFirepowerClass,cclass);

}

}

printf("Classofmaximumfirepower:%s\nn,maxFirepowerClass);

EXECSQLCLOSECURSORcursorl;

)

b)

voidgetCountry(){

EXECSQLBEGINDECLARESECTION;

charibattle[20]ziresult[10]zocountry[20];

charstmtl[200]rstmt2[200];

EXECSQLENDDECLARESECTION;

strcpy(stmtl,''SELECTCOUNTRYFROMClassesC

WHEREC.ClassIN(

SELECTS.classFROMShipsS

WHERES.nameIN(

SELECTshipFROMOutcomes

WHEREbattle=?))〃);

Strcpy(stm2,''SELECTcountryFROMClasses

WHEREclass=(SELECTMAX(COUNT(class))

FROMShipsstOutcomeso

WHEREo.name=s.shipAND

s?result='?')〃);

EXECSQLPREPAREquerylFROMstmtl;

EXECSQLPREPAREquery2FROMstmt2;

EXECSQLDECLAREcursorlCURSORFORqueryl;

EXECSQLDECLAREcursor2CURSORFORquery2;

/*askuserforbattle*/

/*getcountriesoftheshipsinvolvedinthebattle*/

EXECSQLOPENcursorlUSING:ibattle;

while(!NOT_FOUND){

EXECSQLFETCHcursorlINTO:ocountry;

if(FOUND)

,,

printf("contry:%s\nzocoutry);

)

EXECSQLCLOSECURSORcursorl;

/*getthecountrywiththemostshipssunk*/

strcpy(iresult,''sunk");

EXECSQLOPENcursor2USING:iresult;

/*loopforthecasethere'sthesamemax#ofshipssunk*/

While(!NOT_FOUND){

EXECSQLFETCHcursor2INTOzocountry;

If(FOUND)

Printf(''countrywiththemostshipssunk:%s,ocountry);

)

/*getthecountrywiththemostshipsdamaged★/

strcpy(iresult,''damaged");

EXECSQLOPENcursor2USING:iresult;

/*loopforthecasethere'sthesamemax#ofshipsdamaged*/

While(!NOTFOUND){

EXECSQLFETCHcursor2INTO:ocountry;

If(FOUND)

Printf(''countrywiththemostshipsdamaged:%s,ocountry);

)

}

c)

voidaddShips(){

EXECSQLBEGINDECLARESECTION;

chariclass[20]zitype[3]zicontry[20]ziship[20];

intinumGuns,ibore,idisplacementzilaunched;

charstmtl[100]rstmt2[100];

EXECSQLENDDECLARESECTION;

strcpy(stmtl,''INSERTINTOClassesVALUES(?,?,?,?,?,?)〃);

strcpy(stmt2z''INSERTINTOShipsVALUES(?,?,?)〃);

/*askuserforaclassandotherinfoforClassestable*/

EXECSQLEXECUTEIMMEDATE:stmtl

USING:iclass,:itype,:icontry,

:inumGuns,:ibore,:idisplacement;

/*askuserforashipandlaunched*/

WHILE(there_is_input)

EXECSQLEXECUTEIMMEDATE:stmt2

USING:iship,:iclass,ilaunched;

/*askuserforashipandlaunched*/

}

)

d)

voidfindError(){

EXECSQLBEGINDECLARESECTION;

charbname[20],bdate[8]znewbdate[8];

charsname[20]rlyear[4]znewlyear[4];

charstmtl[100]rstmt2[100];

EXECSQLENDDECLARESECTION;

strcpy(stmtlf''UPDATEBattlesSETdate=?WHEREname=?〃);

strcpy(stmt2,''UPDATEShipsSETlaunched=?WHEREname=?〃);

EXECSQLDECLAREClCURSORFOR

Select,b.date,s.name,s.launched

FROMBattlesb,Outcomeso,Shipss

WHEREb.name=o.battleAND

o.ship=s.nameAND

YEAR(b.date)<s.launched;

EXECSQLOPENCl;

while(!NOT_FOUND){

EXECSQLFETCHClINTO:bname,:bdate,:sname,:lyear;

/*promptuserandaskifachangeisneeded*/

if(change_battle)

/*getanewbattledatetonewbdate*/

EXECSQLEXECUTEIMMEDATE:stmtl

USING:bname,:newbdate;

if(change_ship)

(

/*getanewlaunchedyeartonewlyear*/

EXECSQLEXECUTEIMMEDATE:stmt2

USING:sname,:newlyear;

}

9.4.1

CREATEFUNCTIONPresNetWorth(studioNameCHAR[15])RETURNSINTEGER

DECLAREpresNetWorth工NT;

BEGIN

SELECTnetWorth

INTOpresNetWorth

FROMStudio,MovieExec

WHERES=studioNameANDpresC#=cert#;

RETURN(presNetWorth);

END;

b)

CREATEFUNCTIONstatus(personCHAR(30)zaddrCHAR(255))RETURNSINTEGER

DECLAREisStarINT;

DECLAREisExecINT;

BEGIN

SELECTCOUNT(*)

INTOisStar

FROMMovieStar

WHEREMovieS=personANDMovieStar.address=addr;

SELECTCOUNT(*)

INTOisExec

FROMMovieExec

WHEREMovieE=personANDMovieExec.address=addr;

IFisStar+isExec=0THENRETURN(4)

ELSERETURN(isStar+2*isExec)

ENDIF;

END;

C)

CREATEPROCEDUREtwoLongest(

INstudioCHAR(15),

OUTlongestVARCHAR(255),

OUTsecondVARCHAR(255)

)

DECLAREtVARCHAR(255);

DECLAREiINT;

DECLARENot_FoundCONDITIONFORSQLSTATE='02000,;

DECLAREMovieCursorCURSORFOR

SELECTtitleFROMMoviesWHEREstudioName=studio

ORDERBYlengthDESC;

BEGIN

SETlongest=NULL;

SETsecond=NULL;

OPENMovieCursor;

SETi=0;

mainLoop:WHILE(i<2)DO

FETCHMovieCursorINTOt;

IFNot_FoundTHENLEAVEmainLoopENDIF;

SETi=i+1;

ENDWHILE;

CLOSEMovieCursor;

END;

d)

CREATEPROCEDUREearliestl20mMovie(

INstarCHAR(30),

OUTearliestYearINT

)

DECLARENot_FoundCONDITIONFORSQLSTATE='020001;

DECLAREMovieCursorCURSORFOR

SELECTMIN(year)FROMMovies

WHERElength>120AND

titleIN(SELECTmovieTitleFROMStarsln

WHEREstarName=star);

BEGIN

SETearliestYear=0;

OPENMovieCursor;

FETCHMovieCursorINTOearliestYear;

CLOSEMovieCursor;

END;

CREATEPROCEDUREuniqueStar(

INaddrCHAR(255),

OUTstarCHAR(30)

)

BEGIN

SETstar=NULL;

IF1=(SELECTCOUNT(*)FROMMovieStarWHEREaddress=addr)

THEN

SELECTnameINTOstarFROMMovieStarWHEREaddress=addr;

END;

f)

CREATEPROCEDUREremoveStar(

INstarCHAR(30)

)

BEGIN

DELETEFROMMoviesWHEREtitleIN

(SELECTmovieTitleFROMStarslnWHEREstarName=star);

DELETEFROMStarslnWHEREstarName=star;

DELETEFROMMovieStarWHEREname=star;

END;

9.4.2

a)

CREATEFUNCTIONclosestMatchPC(targetPriceINT)RETURNSCHAR

DECLAREclosestModelCHAR(4);

DECLAREdiffSqINT;

DECLAREcurrSqINT;

DECLAREmCHAR(4);

DECLAREpINT;

DECLARENot_FoundCONDITIONFORSQLSTATE'020001;

DECLAREPCCursorCURSORFOR

SELECTmodel,priceFROMPC;

BEGIN

SETclosestModel=NULL;

SETdiffSq=-1;

OPENPCCursor;

mainLoop:LOOP

FETCHPCCursorINTOm,p;

IFNot_FoundTHENLEAVEmainLoopENDIF;

SETcurrSq=(p-targetPrice)*(p-targetPrice);

IFdiffSq=-1ORdiffSq>currSq

THENBEGIN

SETclosestModel=m;

SETdiffSq=currSq;

ENDIF;

ENDLOOP;

CLOSEPDCursor;

RETURN(closestModel);

END;

b)

CREATEFUNCTIONgetPrice(imakerCHAR(l),imodelCHAR(4))

RETURNSINTEGER

DECLAREptypeVARCHAR(IO);

DECLAREppriceINT;

DECLARENotFoundCONDITIONFORSQLSTATE'02000,;

BEGIN

SELECTtypeINTOptypeFROMProduct

WHEREmaker=imakerANDmodelimodel;

IFptypePCTHEN

SELECTpriceINTOppriceFROMPC

WHEREmodel=imodel;

ELSEIFptype='laptop'THEN

SELECTpriceINTOppriceFROMLaptop

WHEREmodel=imodel;

ELSEIFptype='printer'THEN

SELECTpriceINTOppriceFROMPrinter

WHEREmodel=imodel;

ELSE

pprice=NULL;

ENDIF;

RETURN(pprice);

END;

C)

CREATEPROCEDUREaddPC(

INimodel工NT,

INispeedDECIMAL(3Z2),

INiram工NT,

INihd工NT,

INipriceINT

DECLAREAlready_ExistCONDITIONFORSQLSTATE,02300,

BEGIN

INSERTINTOPCVALUES(imodel,ispeed,iramzihd,iprice);

WHILE(Already_Exist)DO

SETimodel=imodel+1;

INSERTINTOPCVALUES(imodelzispeed,iramzihd,iprice);

ENDWHILE;

END;

d)

CREATEPROCEDUREgetNumOfHigherPrice(

INiprice工NT,

OUTNumOfPCsINT,

OUTNumOfLaptops工NT,

OUTNumOfPrintersINT

)

BEGIN

SETNumOfPCs=0;

SETNumOfLaptops=0;

SETNumOfPrinters=0;

SELECTCOUNT(*)INTONumOfPCsFROMPC

WHEREprice>iprice;

SELECTCOUNT(*)INTONumOfLaptopsFROMLaptop

WHEREprice>iprice;

SELECTCOUNT(*)INTONumOfPrintersFROMPrinter

WHEREprice>iprice;

END;

9.4.3

a)

CREATEFUNCTIONgetFirepower(iclassVARCHAR(IO))RETURNSINTEGER

DECLAREfirepower工NT;

DECLAREngunsINT;

DECLAREnbore工NT;

BEGIN

SELECTnumGuns,boreINTOnguns,nboreFROMClasses

WHEREclass=iclass;

SETfirepower=nguns*(nbore*nbore*nbore);

RETURN(firepower);

END;

b)

CREATEPROCEDUREtwoCountriesInBattle(

INibattleVARCHAR(20)z

OUTfirstCountryVARCHAR(20),

OUTsecondCountryVARCHAR(20)

)

DECLAREiINT;

DECLAREocountryVARCHAR(20);

DECLAREclassCursorCURSORFOR

SELECTcountryFROMClasses

WHEREclassIN(SELECTclassFROMShips

WHEREnameIN(

SELECTshipFROMOutcomes

WHEREbattle=ibattle

)

);

BEGIN

SETfirstCountry=NULL;

SETsecondCountry=NULL;

SETi=0;

IF2=(SELECTCOUNT(*)countFROMClasses

WHEREclassIN(SELECTclassFROMShips

WHEREnameIN(

SELECTshipFROMOutcomes

WHEREbattle=ibattle

)

)

)

THEN

OPENclassCursor;

WHILE(i<2)DO

FETCHclassCursorINTOocountry;

IF(i=0)THEN

SETfirstCountry=ocountry;

ELSE

SETsecoundCountry=ocountry;

ENDIF;

ENDWHILE;

ENDIF;

CLOSEcalssCursor;

END;

CREATEPROCEDUREaddClass(

INishipVARCHAR(20)f

INiclassVARCHAR(20),

INitypeCHAR(2)z

INicountryVARCHAR(20),

INinumGuns工NT,

INibore工NT,

INidisplacementINT

BEGIN

INSERTINTOClassesVALUES(iclasszitype,icountry,

inumGuns,ibore,idisplacement);

INSERTINTOShipsVALUES(ishipziclass,NULL);

END;

d)

CREATEPROCEDUREcheckLaunched(

INshipVARCHAR(20)

)

DECLAREbnameVARCHAR(20);

BEGIN

IFEXIST(SELECTb.nameINTObname

FROMBattlesb,OutcomesozShipss

WHEREb.name=o.battleAND

o.ship=s.nameAND

YEAR(b.date)<s.launched)

THEN

UPDATEShipsSETlaunced=0WHEREname=iship;

UPDATEBattlesSETdate=0WHEREname=bname;

ENDIF;

END

9.4.4

n?

[£(川—T)2]/n=1/n[工宙-2Eg+N)]

=1/n[£娉-£2也+£n]

=1/n[£工;—2元£石+無2£I]

=1/n[52-2x(nx)+x2(n)]

n

=1/n[-nx2],sincei=£(q)/n

S=1

n.、

=(Hj)2]/n-[(£

tZi?=1

9.5.1

a)

#includesqlcli.h

SQLHENVmyEnv;

SQLHDBCmycon;

SQLHSTMTexecStat;

SQLRETURNerrCodelAerrCode2,errCode3;

SQLCHARmanfztempModel[4];

SQLFLOATtempSpeed;

SQLINTEGERtempPrice;

SQLINTEGERcollnfo;

InttargetPrice;

charmodelOfClosest[4];

floatspeedOfClosest;

intpriceOfClosest;

/*askuserfortargetpriceandreadtheanswerintovariable

targetPrice*/

errCodel=SQLAllocHandle(SQL_HANDLE_ENVZSQL_NULL_HANDLE,SmyEnv);

if(errCodel){

printf(z,ErrorforSQL_HANDLE_ENV.\n〃);

exit(1);

)

errCode2=SQLAllocHandle(SQL_HANDLE_DBC,myEnv,&myCon);

if(errCode2){

printf("ErrorforSQL_HANDLE_DBC.\n〃);

exit(1);

)

errCode3=SQLAllocHandle(SQL_HANDLE_STMT,myCon,&execStat);

if(errCode3){

printf(z,ErrorforSQL_HANDLE_STMT.\n〃);

exit(1);

)

SQLExecDirect(execStat,''SELECTmodel,price,speedFROMPC〃,SQL_NTS);

SQLBindCol(execStat,1,SQL_CHARZtempModel,

sizeof(tempModel),Scollnfo);

SQLBindCol(execStat,2,SQL_工NTEGER,tempPrice,

sizeof(tempPrice),Scollnfo);

SQLBindCol(execStat,3,SQL_FLOATZtempSpeed,

sizeof(tempSpeed),&collnfo);

priceOfClosest=NULL;

while(SQLFetch(execStat)!=SQL_NO_DATA){

if(/*the1stfetchortempPriceclosertotargetPrice*/

modelOfClosest=tempModel;

priceOfClosest=tempPrice;

speedOfClosest=tempSpeed;

)

)

/*Now,modelOfClosestisthemodelwhosepriceisclosestto

target.Wemustgetitsmanufacturerwithasingle-rowselect

*/

if(priceOfClosest==NULL)/*nodatafetched*/

/*printerrormessageandexit*/

SQLPrepare(execStat,

''SELECTmakerFROMProductWHEREmodel=?〃,SQL_NTS);

SQLBindParameter(execStat,1,...zmodelOfClosest,...);

SQLExecute(execStat);

SQLBindCol(execStat,1,SQLCHAR,Smanfzsizeof(manf)t&collnfo);

/*printmanf*/

b)

#includesqlcli.h

SQLHENVmyEnv;

SQLHDBCmycon;

SQLHSTMTexecStat;

SQLRETURNerrCodel,errCode2,errCode3;

SQLCHARmodel[4]zmaker;

SQLFLOATminSpeed;

SQLINTEGERminRam,minHd,minScreen;

SQLFLOATspeed;

SQLINTEGERram,hd,screen;

SQLINTEGERcollnfo;

/*askuserforminimumspeed,ram,hds

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論