BÀI 9: Xử lý các đối tượng lưu trữ thông tin với số lượng lớn

Embed Size (px)

DESCRIPTION

Binary Large Objects và Character Large Objects là gì? Quá trình đọc Large Objects từ Database Quá trình ghi Large Objects xuống Database

Text of BÀI 9: Xử lý các đối tượng lưu trữ thông tin với số lượng lớn

  • 1. 11 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM
  • 2. 22 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM X l cc i tng lu tr thng tin vi s lng ln 1. Binary Large Objects v Character Large Objects l g? 2. Qu trnh c Large Objects t Database 3. Qu trnh ghi Large Objects xung Database
  • 3. 33 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM 1. Binary Large Objects v Character Large Objects l g? Binary Large Objects (BLOBs) Character Large Objects (CLOBs) Kiu d liu Large Value
  • 4. 44 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Binary Large ObjectsBinary Large Objects BLOBs l cc i tng ln di dng nh phn, c th c lu tr trong CSDL BLOBs c th cha hnh nh, bng tnh, video clips v cc tp tin thi hnh Trong SQL Server 2000, kiu image c s dng lu tr BLOB.
  • 5. 55 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Character Large Objects CLOBs l cc i tng ln di dng k t, c th c lu tr trong CSDL CLOBs c th cha gi tr dng vn bn nh : thng tin c th trong vn bn c phn bit bng du phy, hoc ti liu XML SQL Server 2000 dng kiu text v ntext lu tr CLOB.
  • 6. 66 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Kiu d liu Large Value Large Value Data Types (LVDT) l kiu c th lu tr gi tr trn 8000bytes (8k) L khi nim mi trong SQL Server 2005, thay th kiu LOB Cc kiu tng ng vi SQL Server 2000: image = varbinary(MAX) text = varchar(MAX) ntext = nvarchar(MAX)
  • 7. 77 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Minh ha kiuMinh ha kiu Large Value Xem kiu d liu ca field LargePhoto trong table Production.ProductPhoto CSDL AdventureWorks
  • 8. 88 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM 2. Qu trnh c Large Objects t Database c tun t LOB Value t Database c LOB hoc LDT Value trong SQL Server 2005
  • 9. 99 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM c tun t LOB Value t Database Cc bc thc hin: To i tng Command To i tng DataReader bng cch s dng phng thc ExecuteReader v xc nh tham s l CommandBehavior.SequentialAccess S dng phng thc GetBytes c d liu BLOB Hoc Phng thc GetChars c d liu CLOB
  • 10. 1010 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Minh ha c tun t LOB Value tMinh ha c tun t LOB Value t DatabaseDatabase S dng bng Production.ProductPhoto, c field LargePhoto To Command v lu ni dung vo DataReader Dng GetBytes c d liu ct LargePhoto Xut ni dung ca ct ny ra mn hnh
  • 11. 1111 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM c LOB hoc LDT Value trong SQL Server 2005 S dng phng thc GetSqlBytes c d liu BLOB hoc varbinary(MAX) Phng thc GetSqlChars c d liu CLOB hoc varchar(MAX)
  • 12. 1212 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Minh ha c LOB Value -Minh ha c LOB Value - GetSqlBytesGetSqlBytes Khai bo mng byte tr gi tr c c ca field LargePhoto To Connection v Command, lu ni dung vo DataReader Dng GetSqlBytes c d liu ct LargePhoto Xut ni dung ca ct ny ra tp tin hnh nh
  • 13. 1313 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM 3. Qu trnh ghi Large Objects vo Database Ghi Large Objects vo Database
  • 14. 1414 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Ghi Large Objects vo Database Cc bc thc hin To Command vi cu lnh thch hp (Insert/Update) Truyn tham s c kiu BLOB/CLOB Tnh ton gi tr cho tham s c kiu BLOB/CLOB Thi hnh cu lnh ca Command
  • 15. 1515 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Minh ha ghi Large Objects voMinh ha ghi Large Objects vo DatabaseDatabase Cp nht field LargePhoto trong bng Production.ProductPhoto, gi tr l mt tp tin hnh nh c sn To Command, c cu lnh Update cha 1 tham s, tham s c kiu l VarBinary M tp tin hnh nh, c gi tr vo mng byte Thi hnh Command vi gi tr ca tham s l mng byte
  • 16. 1616 HC LP TRNH WEB T C BN N NNG CAO HocLapTrinhWeb.COM Bi thc hnh c BLOB v ghi ra tp tin dng hnh nh