ɎȿȾȿɊȺɅɖɇɈȿ ȺȽȿɇɌɋɌȼɈ ɉɈ ɈȻɊȺɁɈȼȺɇɂɘ ȽɈɋɍȾȺɊɋɌȼȿɇɇɈȿ ɈȻɊȺɁɈȼȺɌȿɅɖɇɈȿ ɍɑɊȿɀȾȿɇɂȿ ȼɕɋɒȿȽɈ ɉɊɈɎȿɋɋɂɈɇȺɅɖɇɈȽɈ ɈȻɊȺɁɈȼȺɇɂə «ȼɈɊɈɇȿɀɋɄɂɃ ȽɈɋɍȾȺɊɋɌȼȿɇɇɕɃ ɍɇɂȼȿɊɋɂɌȿɌ»
ȼ. Ƚ. Ɋɭɞɚɥɟɜ, ɋ. ɋ. ɉɪɨɧɢɧ ɄɅɂȿɇɌ-ɋȿɊȼȿɊɇɕȿ ɉɊɂɅɈɀȿɇɂə ȻȺɁ ȾȺɇɇɕɏ ɍɱɟɛɧɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ
ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ 2007
ɍɬɜɟɪɠɞɟɧɨ ɧɚɭɱɧɨ-ɦɟɬɨɞɢɱɟɫɤɢɦ ɫɨɜɟɬɨɦ ɮɚɤɭɥɶɬɟɬɚ ɩɪɢɤɥɚɞɧɨɣ ɦɚɬɟɦɚɬɢɤɢ, ɢɧɮɨɪɦɚɬɢɤɢ ɢ ɦɟɯɚɧɢɤɢ 28.02.2007 ɝ., ɩɪɨɬɨɤɨɥ ʋ 6
Ɋɟɰɟɧɡɟɧɬ ɞ-ɪ ɮɢɡ.-ɦɚɬ. ɧɚɭɤ, ɞɨɰɟɧɬ ɤɚɮ. ɬɟɨɪɟɬɢɱɟɫɤɨɣ ɢ ɩɪɢɤɥɚɞɧɨɣ ɦɟɯɚɧɢɤɢ Ⱥ. ȼ. Ʉɨɜɚɥɟɜ
ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɩɨɞɝɨɬɨɜɥɟɧɨ ɧɚ ɤɚɮɟɞɪɟ ɬɟɯɧɢɱɟɫɤɨɣ ɤɢɛɟɪɧɟɬɢɤɢ ɢ ɚɜɬɨɦɚɬɢɱɟɫɤɨɝɨ ɪɟɝɭɥɢɪɨɜɚɧɢɹ ɮɚɤɭɥɶɬɟɬɚ ɩɪɢɤɥɚɞɧɨɣ ɦɚɬɟɦɚɬɢɤɢ, ɢɧɮɨɪɦɚɬɢɤɢ ɢ ɦɟɯɚɧɢɤɢ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. Ɋɟɤɨɦɟɧɞɭɟɬɫɹ ɞɥɹ ɫɬɭɞɟɧɬɨɜ ɮɚɤɭɥɶɬɟɬɚ ɉɆɆ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ ɜɫɟɯ ɮɨɪɦ ɨɛɭɱɟɧɢɹ, ɫɞɚɸɳɢɯ ɷɤɡɚɦɟɧ ɩɨ ɤɭɪɫɭ «Ȼɚɡɵ ɞɚɧɧɵɯ ɢ ɷɤɫɩɟɪɬɧɵɟ ɫɢɫɬɟɦɵ».
Ⱦɥɹ ɫɩɟɰɢɚɥɶɧɨɫɬɢ: 010500 (510200) – ɉɪɢɤɥɚɞɧɚɹ ɦɚɬɟɦɚɬɢɤɚ ɢ ɢɧɮɨɪɦɚɬɢɤɚ 2
ȼɜɟɞɟɧɢɟ ɋɨɡɞɚɧɢɸ ɩɪɢɥɨɠɟɧɢɣ ɛɚɡ ɞɚɧɧɵɯ ɩɨɫɜɹɳɟɧɨ ɞɨɫɬɚɬɨɱɧɨ ɦɧɨɝɨ ɭɱɟɛɧɵɯ ɩɨɫɨɛɢɣ. ɇɚɩɪɢɦɟɪ, ɩɨɱɬɢ ɜɫɟ ɤɧɢɝɢ ɩɨ ɫɨɜɪɟɦɟɧɧɵɦ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɵɦ ɫɪɟɞɚɦ ɪɚɡɪɚɛɨɬɤɢ (ɧɚɩɪɢɦɟɪ, ɩɨ Delphi) ɫɨɞɟɪɠɚɬ ɨɛɲɢɪɧɵɟ ɪɚɡɞɟɥɵ ɫ ɨɩɢɫɚɧɢɟɦ ɤɥɚɫɫɨɜ ɢ ɤɨɦɩɨɧɟɧɬɨɜ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ. ɂɡɥɨɠɟɧɧɚɹ ɜ ɷɬɢɯ ɤɧɢɝɚɯ ɢɧɮɨɪɦɚɰɢɹ ɜɩɨɥɧɟ ɩɪɢɝɨɞɧɚ ɞɥɹ ɧɚɩɢɫɚɧɢɹ ɧɟɫɥɨɠɧɵɯ ɩɪɨɝɪɚɦɦ ɞɥɹ ɩɟɪɫɨɧɚɥɶɧɵɯ ɛɚɡ ɞɚɧɧɵɯ, ɧɨ ɫɨɜɟɪɲɟɧɧɨ ɧɟɞɨɫɬɚɬɨɱɧɚ ɞɥɹ ɫɨɡɞɚɧɢɹ ɷɮɮɟɤɬɢɜɧɵɯ ɩɪɢɥɨɠɟɧɢɣ, ɪɚɛɨɬɚɸɳɢɯ ɜ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɣ ɤɥɢɟɧɬ-ɫɟɪɜɟɪɧɨɣ ɫɪɟɞɟ. ɇɟɨɛɯɨɞɢɦɵɦɢ ɱɟɪɬɚɦɢ ɤɥɢɟɧɬ-ɫɟɪɜɟɪɧɵɯ ɩɪɨɝɪɚɦɦ ɹɜɥɹɸɬɫɹ ɪɚɰɢɨɧɚɥɶɧɨɟ ɪɚɡɞɟɥɟɧɢɟ ɮɭɧɤɰɢɣ ɤɥɢɟɧɬɫɤɨɣ ɢ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɟɣ ɩɪɢɥɨɠɟɧɢɹ ɢ ɩɪɚɜɢɥɶɧɚɹ ɨɪɝɚɧɢɡɚɰɢɹ ɬɪɚɧɡɚɤɰɢɣ. ɋɥɟɞɨɜɚɧɢɟ ɡɞɟɫɶ ɩɪɢɟɦɚɦ ɢ ɧɚɜɵɤɚɦ ɪɚɡɪɚɛɨɬɤɢ ɩɟɪɫɨɧɚɥɶɧɵɯ ɩɪɢɥɨɠɟɧɢɣ ɦɨɠɟɬ ɩɪɢɜɨɞɢɬɶ ɤ ɬɹɠɟɥɵɦ ɨɲɢɛɤɚɦ. ɑɬɨɛɵ ɢɯ ɢɡɛɟɠɚɬɶ, ɧɭɠɧɵ ɨɩɵɬ ɢ ɡɧɚɧɢɟ ɨɫɨɛɟɧɧɨɫɬɟɣ ɤɨɧɤɪɟɬɧɨɣ ɋɍȻȾ. ɋ ɞɪɭɝɨɣ ɫɬɨɪɨɧɵ, ɤɧɢɝɢ, ɩɨɫɜɹɳɟɧɧɵɟ ɨɫɨɛɟɧɧɨɫɬɹɦ ɫɟɪɜɟɪɨɜ ɛɚɡ ɞɚɧɧɵɯ (SQL Server, Oracle ɢɥɢ ɞɪ.), ɫɨɞɟɪɠɚɬ ɦɧɨɠɟɫɬɜɨ ɫɜɟɞɟɧɢɣ, ɧɟɨɛɯɨɞɢɦɵɯ ɞɥɹ ɩɪɨɟɤɬɢɪɨɜɚɧɢɹ, ɧɚɫɬɪɨɣɤɢ, ɫɨɩɪɨɜɨɠɞɟɧɢɹ, ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ, ɧɚɩɢɫɚɧɢɹ ɫɟɪɜɟɪɧɵɯ ɩɪɨɰɟɞɭɪ ɢ ɬ.ɩ., ɧɨ ɢɯ ɢɡɭɱɟɧɢɟ ɧɟ ɞɚɟɬ ɨɬɜɟɬɚ ɧɚ ɝɥɚɜɧɵɣ ɜɨɩɪɨɫ – ɤɚɤ ɩɢɫɚɬɶ ɤɥɢɟɧɬ-ɫɟɪɜɟɪɧɵɟ ɩɪɨɝɪɚɦɦɵ ɞɥɹ ɛɚɡ ɞɚɧɧɵɯ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɨɛɪɚɡɨɜɚɥɫɹ ɨɩɪɟɞɟɥɟɧɧɵɣ ɪɚɡɪɵɜ, ɩɪɟɨɞɨɥɟɬɶ ɤɨɬɨɪɵɣ ɦɨɠɧɨ ɥɢɲɶ ɧɚ ɩɪɚɤɬɢɤɟ. Ⱦɚɧɧɨɟ ɩɨɫɨɛɢɟ ɩɪɢɡɜɚɧɨ ɨɛɥɟɝɱɢɬɶ ɩɟɪɜɵɟ ɲɚɝɢ ɩɨ ɫɨɡɞɚɧɢɸ ɤɥɢɟɧɬ-ɫɟɪɜɟɪɧɵɯ ɩɪɢɥɨɠɟɧɢɣ, ɟɝɨ ɡɚɞɚɱɚ – ɨɛɨɡɧɚɱɢɬɶ ɬɢɩɢɱɧɵɟ ɩɪɨɛɥɟɦɵ, ɬɪɭɞɧɨɫɬɢ, ɨɲɢɛɤɢ ɢ ɩɭɬɢ ɢɯ ɪɚɡɪɟɲɟɧɢɹ. Ⱥɜɬɨɪɵ ɩɪɟɤɪɚɫɧɨ ɨɫɨɡɧɚɸɬ: ɚ) ɱɬɨ ɧɟɥɶɡɹ ɨɛɴɹɬɶ ɧɟɨɛɴɹɬɧɨɟ, ɛ) ɧɟɬ ɧɢɱɟɝɨ ɛɟɫɩɨɥɟɡɧɟɟ, ɱɟɦ ɭɧɢɜɟɪɫɚɥɶɧɵɟ ɪɟɰɟɩɬɵ, ɜ) ɢɡɭɱɚɬɶ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟ ɩɨ ɤɧɢɝɚɦ – ɛɟɫɫɦɵɫɥɟɧɧɚɹ ɬɪɚɬɚ ɜɪɟɦɟɧɢ. ɉɨɷɬɨɦɭ ɦɚɬɟɪɢɚɥ ɢɡɥɚɝɚɟɬɫɹ ɩɪɢɦɟɧɢɬɟɥɶɧɨ ɤ ɤɨɧɤɪɟɬɧɨɣ ɋɍȻȾ ɢ ɤɨɧɤɪɟɬɧɨɣ ɬɟɯɧɨɥɨɝɢɢ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ. Ɋɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɫɟɪɜɟɪ InterBase (ɢɧɬɟɪɟɫ ɤ ɧɟɦɭ ɫɨ ɫɬɨɪɨɧɵ ɪɚɡɪɚɛɨɬɱɢɤɨɜ ɫɬɚɛɢɥɶɧɨ ɜɵɫɨɤ) ɢ ɬɟɯɧɨɥɨɝɢɹ ɞɨɫɬɭɩɚ IBX, ɪɟɚɥɢɡɨɜɚɧɧɚɹ ɫ ɩɨɦɨɳɶɸ ɫɩɟɰɢɚɥɢɡɢɪɨɜɚɧɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ Delphi. ȼɵɜɨɞɵ ɢ ɡɚɤɥɸɱɟɧɢɹ ɫɨɩɪɨɜɨɠɞɚɸɬɫɹ ɩɪɢɦɟɪɚɦɢ ɢ ɥɚɛɨɪɚɬɨɪɧɵɦɢ ɪɚɛɨɬɚɦɢ, ɬɚɤ ɱɬɨ ɱɢɬɚɬɟɥɶ ɢɡɛɚɜɥɟɧ ɨɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɦɟɯɚɧɢɱɟɫɤɨɝɨ ɡɚɩɨɦɢɧɚɧɢɹ – ɜɫɟ ɩɪɨɜɟɪɹɬɫɹ ɧɚ ɩɪɚɤɬɢɤɟ. Ⱦɥɹ ɪɚɛɨɬɵ ɫ ɩɨɫɨɛɢɟɦ ɧɟɨɛɯɨɞɢɦɨ ɡɧɚɤɨɦɫɬɜɨ ɫ ɨɫɧɨɜɧɵɦɢ ɤɨɦɩɨɧɟɧɬɚɦɢ Delphi ɞɥɹ ɪɚɛɨɬɵ ɫ ɛɚɡɚɦɢ ɞɚɧɧɵɯ ɜ ɪɚɦɤɚɯ ɩɨɫɨɛɢɹ [5] ɢ ɡɧɚɧɢɟ ɹɡɵɤɚ SQL. 3
1. Ɉɫɧɨɜɵ ɪɚɛɨɬɵ ɜ InterBase ɋɟɪɜɟɪ ɛɚɡ ɞɚɧɧɵɯ InterBase ɜɵɩɭɫɤɚɟɬɫɹ ɞɥɹ ɪɚɡɥɢɱɧɵɯ ɩɪɨɝɪɚɦɦɧɨ-ɚɩɩɚɪɚɬɧɵɯ ɩɥɚɬɮɨɪɦ (Windows, Linux ɢ ɦɧɨɝɢɯ ɞɪɭɝɢɯ) ɢ, ɱɬɨ ɨɱɟɧɶ ɜɚɠɧɨ, ɹɜɥɹɟɬɫɹ ɨɛɳɟɞɨɫɬɭɩɧɵɦ. ȼɟɪɫɢɢ InterBase, ɜɵɩɭɫɤɚɟɦɵɟ ɮɢɪɦɨɣ Borland, ɫɥɟɞɭɟɬ ɩɪɢɨɛɪɟɬɚɬɶ ɡɚ ɞɟɧɶɝɢ. ȼ ɬɨ ɠɟ ɜɪɟɦɹ ɢɫɯɨɞɧɵɟ ɬɟɤɫɬɵ InterBase ɨɬɤɪɵɬɵ ɞɥɹ ɪɚɡɪɚɛɨɬɱɢɤɨɜ ɢ ɜ ɪɚɦɤɚɯ ɨɬɤɪɵɬɵɯ ɩɪɨɟɤɬɨɜ Firebird ɢ Jaffil ɜɵɩɭɫɤɚɸɬɫɹ ɫɜɨɢ ɫɨɜɟɪɲɟɧɧɨ ɛɟɫɩɥɚɬɧɵɟ ɭɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɧɵɟ ɜɟɪɫɢɢ ɫɟɪɜɟɪɚ. ɂɡɜɟɫɬɧɵɣ ɧɟɞɨɫɬɚɬɨɤ InterBase – ɨɬɫɭɬɫɬɜɢɟ ɫɪɟɞɫɬɜ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɣ ɩɨɞɞɟɪɠɤɢ ɩɨɥɧɨɫɬɶɸ ɤɨɦɩɟɧɫɢɪɭɟɬɫɹ ɦɧɨɝɨɱɢɫɥɟɧɧɵɦɢ ɭɬɢɥɢɬɚɦɢ ɢ ɩɪɨɝɪɚɦɦɧɵɦɢ ɤɨɦɩɥɟɤɫɚɦɢ ɫɬɨɪɨɧɧɢɯ ɪɚɡɪɚɛɨɬɱɢɤɨɜ – IBAdmin, IBManager, IBExpert ɢ ɞɪ., ɦɧɨɝɢɟ ɢɡ ɤɨɬɨɪɵɯ ɬɚɤɠɟ ɹɜɥɹɸɬɫɹ ɛɟɫɩɥɚɬɧɵɦɢ. ȼ ɰɟɥɨɦ, InterBase – ɨɩɬɢɦɚɥɶɧɨɟ ɪɟɲɟɧɢɟ ɞɥɹ ɦɚɥɵɯ ɢ ɫɪɟɞɧɢɯ ɨɪɝɚɧɢɡɚɰɢɣ ɫ ɱɢɫɥɨɦ ɪɚɛɨɱɢɯ ɫɬɚɧɰɢɣ ɩɨɪɹɞɤɚ ɧɟɫɤɨɥɶɤɢɯ ɞɟɫɹɬɤɨɜ. ȼɨɡɦɨɠɧɨɫɬɢ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ InterBase ɨɝɪɚɧɢɱɟɧɵ ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ Oracle ɢɥɢ MS SQL Server, ɧɨ ɩɪɢ ɷɬɨɦ ɨɛɟɫɩɟɱɢɜɚɟɬɫɹ ɩɪɢɟɦɥɟɦɚɹ ɞɥɹ ɦɧɨɝɢɯ ɡɚɞɚɱ ɫɬɟɩɟɧɶ ɡɚɳɢɬɵ ɢɧɮɨɪɦɚɰɢɢ. 1.1. ɍɫɬɚɧɨɜɤɚ InterBase ɍɫɬɚɧɨɜɤɚ InterBase ɢɥɢ Firebird ɩɪɨɢɫɯɨɞɢɬ ɛɵɫɬɪɨ ɢ, ɤɚɤ ɩɪɚɜɢɥɨ, ɧɟ ɜɵɡɵɜɚɟɬ ɡɚɬɪɭɞɧɟɧɢɣ. ɇɚɩɪɢɦɟɪ, ɩɪɢ ɭɫɬɚɧɨɜɤɟ ɫɟɪɜɟɪɚ Firebird 1.5 ɧɟɨɛɯɨɞɢɦɨ ɡɚɩɭɫɬɢɬɶ ɭɫɬɚɧɨɜɨɱɧɵɣ ɮɚɣɥ Firebird-1.5.2.4731-Win32.ɟɯɟ ɢ ɫɥɟɞɨɜɚɬɶ ɢɧɫɬɪɭɤɰɢɹɦ, ɩɪɢɧɢɦɚɹ ɭɫɬɚɧɨɜɤɢ ɩɨ ɭɦɨɥɱɚɧɢɸ (ɜ ɱɚɫɬɧɨɫɬɢ, ɫɨɝɥɚɫɢɜɲɢɫɶ ɫ ɡɚɩɭɫɤɨɦ Firebird ɩɪɢ ɫɬɚɪɬɟ Windows ɜ ɤɚɱɟɫɬɜɟ ɫɥɭɠɛɵ). Firebird ɩɪɟɞɥɨɠɢɬ ȼɚɦ ɞɜɚ ɜɚɪɢɚɧɬɚ ɭɫɬɚɧɨɜɤɢ – Classic ɢ SuperServer. ȼ ɜɚɪɢɚɧɬɟ Classic ɤɚɠɞɵɣ ɡɚɩɪɨɫ ɤɥɢɟɧɬɚ ɨɛɪɚɛɚɬɵɜɚɟɬɫɹ ɜ ɨɬɞɟɥɶɧɨɦ ɩɪɨɰɟɫɫɟ, ɜ ɜɚɪɢɚɧɬɟ SuperServer – ɨɬɞɟɥɶɧɵɦɢ ɩɨɬɨɤɚɦɢ ɜɧɭɬɪɢ ɟɞɢɧɨɝɨ ɩɪɨɰɟɫɫɚ. ɉɟɪɜɵɣ ɜɚɪɢɚɧɬ ɨɬɥɢɱɚɟɬɫɹ ɫɬɚɛɢɥɶɧɨɫɬɶɸ ɪɚɛɨɬɵ, ɜɬɨɪɨɣ – ɦɟɧɶɲɢɦ ɩɨɬɪɟɛɥɟɧɢɟɦ ɫɢɫɬɟɦɧɵɯ ɪɟɫɭɪɫɨɜ. ɉɪɢ ɭɫɬɚɧɨɜɤɟ FireBird ɜ ɫɟɬɢ ɧɟɨɛɯɨɞɢɦɨ ɭɫɬɚɧɨɜɢɬɶ ɫɟɪɜɟɪ ɧɚ ɨɞɧɨɦ ɢɡ ɭɡɥɨɜ ɫɟɬɢ, ɤɨɬɨɪɵɣ ɛɭɞɟɬ ɢɝɪɚɬɶ ɪɨɥɶ ɫɟɪɜɟɪɚ ɛɚɡ ɞɚɧɧɵɯ. ɇɚ ɪɚɛɨɱɢɯ ɫɬɚɧɰɢɹɯ ɫɟɬɢ ɧɟɨɛɯɨɞɢɦɨ ɭɫɬɚɧɨɜɢɬɶ ɤɥɢɟɧɬ FireBird. ɗɬɨ ɦɨɠɧɨ ɜɵɩɨɥɧɢɬɶ ɪɚɡɥɢɱɧɵɦɢ ɫɩɨɫɨɛɚɦɢ. ȼɨ-ɩɟɪɜɵɯ, ɡɚɩɭɫɬɢɬɶ ɭɫɬɚɧɨɜɨɱɧɵɣ ɮɚɣɥ, ɨɬɤɥɸɱɢɜ ɨɩɰɢɸ ɭɫɬɚɧɨɜɤɢ ɫɟɪɜɟɪɚ, ɚ ɨɫɬɚɜɢɜ ɬɨɥɶɤɨ ɭɫɬɚɧɨɜɤɭ ɤɥɢɟɧɬɚ. ȼɨ-ɜɬɨɪɵɯ, ɨɬɦɟɬɢɬɶ ɩɪɢ ɭɫɬɚɧɨɜɤɟ Delphi ɮɥɚɠɨɤ Install InterBase Client. ɇɚɤɨɧɟɰ, ɦɨɠɧɨ ɫɤɨɩɢɪɨɜɚɬɶ ɮɚɣɥ gds32.dll ɜ ɩɚɩɤɭ Windows\System32. ɗɬɨ ɟɞɢɧɫɬɜɟɧɧɵɣ ɮɚɣɥ, ɧɟɨɛɯɨɞɢɦɵɣ ɞɥɹ ɪɚɛɨɬɵ ɤɥɢɟɧɬɚ.
4
1.2. ɂɧɫɬɪɭɦɟɧɬɚɥɶɧɵɟ ɫɪɟɞɫɬɜɚ ɍɬɢɥɢɬɚ InterBase Console (ɫɨɤɪɚɳɟɧɧɨ IBConsole) – ɨɫɧɨɜɧɚɹ ɭɬɢɥɢɬɚ ɜ InterBase ɜɟɪɫɢɣ 6–7 ɞɥɹ ɪɚɛɨɬɵ ɫ ȻȾ. ȿɟ ɮɭɧɤɰɢɢ: x ɫɨɡɞɚɧɢɟ ɛɚɡɵ ɞɚɧɧɵɯ; x ɫɨɟɞɢɧɟɧɢɟ ɫ ȻȾ ɢ ɜɵɩɨɥɧɟɧɢɟ SQL-ɡɚɩɪɨɫɨɜ; x ɨɬɨɛɪɚɠɟɧɢɟ ɢɧɮɨɪɦɚɰɢɢ ɨ ȻȾ; x ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɟ ȻȾ. ȼ ɰɟɥɨɦ ɮɭɧɤɰɢɨɧɚɥɶɧɵɟ ɜɨɡɦɨɠɧɨɫɬɢ IBConsole ɧɟɜɟɥɢɤɢ, ɩɨɷɬɨɦɭ ɱɚɫɬɨ ɩɨɥɶɡɭɸɬɫɹ ɭɬɢɥɢɬɨɣ SQL Explorer, ɜɯɨɞɹɳɟɣ ɜ ɫɨɫɬɚɜ Delphi. SQL Explorer ɪɚɛɨɬɚɟɬ ɱɟɪɟɡ BDE ɢ ɩɨɡɜɨɥɹɟɬ ɫɨɡɞɚɜɚɬɶ ɬɚɛɥɢɰɵ ɢ ɞɪɭɝɢɟ ɨɛɴɟɤɬɵ ȻȾ ɜ ɞɢɚɥɨɝɨɜɨɦ ɪɟɠɢɦɟ. Ɉɞɧɚɤɨ, ɩɨ ɦɧɟɧɢɸ ɚɜɬɨɪɨɜ, ɩɪɟɞɩɨɱɬɢɬɟɥɶɧɟɣ ɹɜɥɹɟɬɫɹ ɫɜɨɛɨɞɧɨ ɪɚɫɩɪɨɫɬɪɚɧɹɟɦɚɹ ɭɬɢɥɢɬɚ IBExpert, ɨɬɥɢɱɚɸɳɚɹɫɹ ɛɨɝɚɬɨɣ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶɸ, ɩɪɨɫɬɨɬɨɣ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɢ ɫɬɚɛɢɥɶɧɨɫɬɶɸ ɪɚɛɨɬɵ. Ɋɚɫɫɦɨɬɪɢɦ ɩɨɞɪɨɛɧɟɟ ɨɫɧɨɜɧɵɟ ɜɨɡɦɨɠɧɨɫɬɢ IBExpert ɢ ɦɟɬɨɞɢɤɭ ɟɟ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɧɚ ɩɪɢɦɟɪɟ ɜɟɪɫɢɢ 2.5. ɍɬɢɥɢɬɚ ɩɨɞɞɟɪɠɢɜɚɟɬ ɧɟɫɤɨɥɶɤɨ ɹɡɵɤɨɜ ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɝɨ ɢɧɬɟɪɮɟɣɫɚ, ɜ ɬɨɦ ɱɢɫɥɟ ɢ ɪɭɫɫɤɢɣ (ɤɨɬɨɪɵɣ ɦɨɠɧɨ ɜɵɛɪɚɬɶ ɱɟɪɟɡ ɩɭɧɤɬ ɦɟɧɸ Options – Environment Option – Interface Language), ɧɨ ɞɚɥɟɟ ɦɵ ɛɭɞɟɦ ɢɡ ɩɟɞɚɝɨɝɢɱɟɫɤɢɯ ɩɨɛɭɠɞɟɧɢɣ (ɬ. ɟ. ɢɡ ɜɪɟɞɧɨɫɬɢ) ɢɫɩɨɥɶɡɨɜɚɬɶ ɚɧɝɥɨɹɡɵɱɧɵɣ ɢɧɬɟɪɮɟɣɫ. 1.3. ɋɨɡɞɚɧɢɟ ɢ ɪɟɝɢɫɬɪɚɰɢɹ ɛɚɡɵ ɞɚɧɧɵɯ ɋɨɡɞɚɧɢɟ ɧɨɜɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɩɪɨɢɫɯɨɞɢɬ ɜ ɱɟɬɵɪɟ ɷɬɚɩɚ: x ɫɨɡɞɚɧɢɟ ɧɨɜɨɣ ɩɭɫɬɨɣ ȻȾ, ɯɪɚɧɹɳɟɣɫɹ ɜ ɮɚɣɥɟ ɫ ɪɚɫɲɢɪɟɧɢɟɦ *.gdb (ɞɥɹ InterBase) *.fdb (ɞɥɹ Firebird); x ɪɟɝɢɫɬɪɚɰɢɹ ȻȾ ɜ IBExpert; x ɫɨɟɞɢɧɟɧɢɟ ɫ ȻȾ; x ɫɨɡɞɚɧɢɟ ɬɚɛɥɢɰ ɢ ɞɪɭɝɢɯ ɦɟɬɚɞɚɧɧɵɯ. ɉɪɟɞɩɨɥɨɠɢɦ, ɱɬɨ ɫɟɪɜɟɪ ɭɫɬɚɧɨɜɥɟɧ ɭ ȼɚɫ ɧɚ ɥɨɤɚɥɶɧɨɦ ɤɨɦɩɶɸɬɟɪɟ ɞɨɦɚ ɢɥɢ ɧɚ ɬɨɦ ɠɟ ɤɨɦɩɶɸɬɟɪɟ, ɧɚ ɤɨɬɨɪɨɦ ɛɭɞɟɬ ɞɚɥɟɟ ɪɚɛɨɬɚɬɶ ɤɥɢɟɧɬɫɤɨɟ ɉɈ. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ ɫɟɪɜɟɪ ɡɚɩɭɳɟɧ: ɜ Windows 98 ɨɧ ɛɭɞɟɬ ɜɢɞɟɧ ɜ ɩɪɚɜɨɣ ɱɚɫɬɢ ɩɚɧɟɥɢ ɡɚɞɚɱ; ɜ Windows 2000/XP ɭɩɪɚɜɜ ɜɢɞɟ ɡɧɚɱɤɚ ɥɹɬɶ ɟɝɨ ɡɚɩɭɫɤɨɦ ɦɨɠɧɨ ɱɟɪɟɡ ɫɩɢɫɨɤ ɫɥɭɠɛ (Services), ɜ ɤɨɬɨɪɨɦ ɩɪɢɫɭɬɫɬɜɭɸɬ ɫɥɭɠɛɵ InterBase (ɢɥɢ Firebird) Guardian ɢ InterBase Server. ȼɵɛɟɪɢɬɟ ɜ ɝɥɚɜɧɨɦ ɦɟɧɸ IBExpert ɩɭɧɤɬ DataBase – Create DataBase. ȼ ɩɨɥɟ Server ɜɜɟɞɢɬɟ Local, ɜ ɩɨɥɟ Database – ɩɭɬɶ ɤ ɧɨɜɨɦɭ, ɟɳɟ ɧɟ ɫɭɳɟɫɬɜɭɸɳɟɦɭ ɮɚɣɥɭ (ɪɢɫ. 1.1):
5
Ɋɢɫ. 1.1. ȼ ɩɨɥɟ UserName ɜɜɨɞɢɬɫɹ ɢɦɹ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ SYSDBA, ɜ ɩɨɥɟ Password – ɩɚɪɨɥɶ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ masterkey (ɜɩɪɨɱɟɦ, ɧɚɞɟɟɦɫɹ, ɱɬɨ ȼɵ ɷɬɨɬ ɜɫɟɦ ɢɡɜɟɫɬɧɵɣ ɩɚɪɨɥɶ ɭɠɟ ɡɚɦɟɧɢɥɢ ɢɥɢ ɫɤɨɪɨ ɡɚɦɟɧɢɬɟ). ȼ ɤɚɱɟɫɬɜɟ SQL Dialect ɭɤɚɠɢɬɟ Dialect 3. ɗɬɨɬ ɞɢɚɥɟɤɬ ɹɡɵɤɚ SQL ɩɨɞɞɟɪɠɢɜɚɟɬɫɹ ɧɚɱɢɧɚɹ ɫ ɜɟɪɫɢɣ InterBase 6 ɢ FireBird ɢ ɨɬɥɢɱɚɟɬɫɹ ɪɚɫɲɢɪɟɧɧɵɦɢ ɜɨɡɦɨɠɧɨɫɬɹɦɢ. Ⱦɢɚɥɟɤɬ 1 ɢɫɩɨɥɶɡɭɣɬɟ, ɟɫɥɢ ɧɟɨɛɯɨɞɢɦɨ ɨɛɟɫɩɟɱɢɬɶ ɫɨɜɦɟɫɬɢɦɨɫɬɶ ɫ InterBase ɪɚɧɧɢɯ ɜɟɪɫɢɣ. Ɉɫɬɚɥɶɧɵɟ ɩɨɥɹ ɦɨɠɧɨ ɨɫɬɚɜɢɬɶ ɛɟɡ ɢɡɦɟɧɟɧɢɣ. Ɋɟɝɢɫɬɪɚɰɢɹ ɧɟɨɛɯɨɞɢɦɚ ɞɥɹ ɭɞɨɛɫɬɜɚ ɞɚɥɶɧɟɣɲɟɣ ɪɚɛɨɬɵ ɫ IBExpert. ɉɪɢ ɪɟɝɢɫɬɪɚɰɢɢ IBExpert ɡɚɩɨɦɢɧɚɟɬ ɩɭɬɶ ɤ ȻȾ, ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ, ɩɚɪɨɥɶ ɢ ɞɪɭɝɢɟ ɩɚɪɚɦɟɬɪɵ ɫɨɟɞɢɧɟɧɢɹ. ɉɪɢ ɩɨɫɥɟɞɭɸɳɢɯ ɡɚɩɭɫɤɚɯ ɨɬɨɛɪɚɠɚɟɬɫɹ ɫɩɢɫɨɤ ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɧɧɵɯ ɛɚɡ, ɚ ɩɪɢ ɩɨɞɤɥɸɱɟɧɢɢ ɤ ɧɢɦ ɜɜɨɞ ɭɱɟɬɧɵɯ ɞɚɧɧɵɯ ɭɠɟ ɧɟ ɬɪɟɛɭɟɬɫɹ. Ɉɤɧɨ ɪɟɝɢɫɬɪɚɰɢɢ ɛɚɡɵ ɞɚɧɧɵɯ (ɪɢɫ. 1.2) ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɨɹɜɥɹɟɬɫɹ ɫɪɚɡɭ ɩɨɫɥɟ ɟɟ ɫɨɡɞɚɧɢɹ. Ɂɞɟɫɶ ɧɟɨɛɯɨɞɢɦɨ ɭɤɚɡɚɬɶ ɢɦɹ ɢ ɜɟɪɫɢɸ ɫɟɪɜɟɪɚ (ɜ ɞɚɧɧɨɦ ɫɥɭɱɚɟ FireBird 1.5), ɜɵɛɪɚɜ ɢɯ ɢɡ ɫɩɢɫɤɚ, ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɩɚɪɨɥɶ, ɚ ɬɚɤɠɟ ɚɥɢɚɫ – ɫɨɤɪɚɳɟɧɧɨɟ ɢɦɹ ȻȾ. Ȼɭɞɶɬɟ ɜɧɢɦɚɬɟɥɶɧɵ ɢ ɭɬɨɱɧɢɬɟ, ɤɚɤɚɹ ɜɟɪɫɢɹ InterBase ɭ ȼɚɫ ɭɫɬɚɧɨɜɥɟɧɚ. Ɉɫɬɚɥɶɧɵɟ ɩɨɥɹ ɡɚɩɨɥɧɹɬɶ ɧɟ ɨɛɹɡɚɬɟɥɶɧɨ. ɉɨɫɥɟ ɪɟɝɢɫɬɪɚɰɢɢ ɜ ɨɤɧɟ DataBase Explorer ɩɨɹɜɢɬɫɹ ɚɥɢɚɫ ȻȾ – NewSklad (ɪɢɫ. 1.3). Ⱦɥɹ ɞɚɥɶɧɟɣɲɟɣ ɪɚɛɨɬɵ ɧɟɨɛɯɨɞɢɦɨ ɫɨɟɞɢɧɢɬɶɫɹ ɫ ȻȾ, ɞɜɚ ɪɚɡɚ ɳɟɥɤɧɭɜ ɩɨ ɚɥɢɚɫɭ, ɩɨɫɥɟ ɱɟɝɨ ɩɨɹɜɢɬɫɹ ɫɩɢɫɨɤ ɦɟɬɚɞɚɧɧɵɯ (ɞɨɦɟɧɨɜ, ɬɚɛɥɢɰ, ɩɪɟɞɫɬɚɜɥɟɧɢɣ, ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ, ɬɪɢɝɝɟɪɨɜ, ɝɟɧɟɪɚɬɨɪɨɜ, ɢɫɤɥɸɱɟɧɢɣ, ɮɭɧɤɰɢɣ, ɨɩɪɟɞɟɥɹɟɦɵɯ ɩɨɥɶɡɨɜɚɬɟɥɟɦ ɢ ɪɨɥɟɣ, ɪɢɫ. 1.4).
6
Ɋɢɫ. 1.2.
Ɋɢɫ. 1.3.
Ɋɢɫ. 1.4. Ɍɟɩɟɪɶ ɦɟɬɚɞɚɧɧɵɟ ɦɨɠɧɨ ɫɨɡɞɚɜɚɬɶ ɢ ɦɨɞɢɮɢɰɢɪɨɜɚɬɶ. ɇɨ ɫɧɚɱɚɥɚ ɨɛɪɚɬɢɦ ȼɚɲɟ ɜɧɢɦɚɧɢɟ ɧɚ ɫɥɟɞɭɸɳɟɟ ɨɱɟɧɶ ɜɚɠɧɨɟ ɨɛɫɬɨɹɬɟɥɶɫɬɜɨ, 7
ɤɨɬɨɪɨɟ ɧɚɞɨ ɭɱɢɬɵɜɚɬɶ ɩɪɢ ɪɚɛɨɬɟ ɜ ɫɟɬɢ. ɂɦɟɧɚ ɛɚɡ ɞɚɧɧɵɯ ɜ InterBase ɫɬɪɨɹɬɫɹ ɩɨ ɩɪɚɜɢɥɭ: Server_Name:Full_FileName, ɝɞɟ Server_Name – ɫɟɬɟɜɨɟ ɢɦɹ ɤɨɦɩɶɸɬɟɪɚ, ɧɚ ɤɨɬɨɪɨɦ ɭɫɬɚɧɨɜɥɟɧ ɫɟɪɜɟɪ InterBase. ȼ ɤɚɱɟɫɬɜɟ ɫɟɬɟɜɨɝɨ ɢɦɟɧɢ ɦɨɝɭɬ ɜɵɫɬɭɩɚɬɶ ɢɦɹ NetBios, ɞɨɦɟɧɧɨɟ ɢɦɹ ɢɥɢ IP-ɚɞɪɟɫ ɤɨɦɩɶɸɬɟɪɚ. Full_FileName – ɢɦɹ ɮɚɣɥɚ ɫ ɪɚɫɲɢɪɟɧɢɟɦ *.gdb, ɨɛɵɱɧɨ ɫ ɭɤɚɡɚɧɢɟɦ ɩɭɬɢ. ɇɚɩɪɢɦɟɪ: c1r214srv:d:\ib\4gr\MyBase\sklad.gdb. ɇɚɩɪɚɜɥɟɧɢɟ ɫɥɷɲɚ ɡɧɚɱɟɧɢɹ ɧɟ ɢɦɟɟɬ. ɇɨ ɜ ɢɦɟɧɢ ɮɚɣɥɚ ɧɟɥɶɡɹ ɭɤɚɡɵɜɚɬɶ ɧɢ ɢɦɟɧɚ ɩɚɩɨɤ ɨɛɳɟɝɨ ɞɨɫɬɭɩɚ, ɧɢ ɨɬɨɛɪɚɠɟɧɢɹ ɷɬɢɯ ɩɚɩɨɤ ɧɚ ɥɨɝɢɱɟɫɤɢɟ ɛɭɤɜɵ ɞɢɫɤɨɜ. ɇɚɩɪɢɦɟɪ, ɧɟɞɨɩɭɫɬɢɦɚ ɡɚɩɢɫɶ \\c1r214srv\MyBase\sklad.gdb.
ɇɟɥɶɡɹ ɬɚɤɠɟ ɡɚɩɢɫɵɜɚɬɶ c1r214srv:H:\MyBase\sklad.gdb, ɟɫɥɢ ɛɭɤɜɚ H ɭɤɚɡɵɜɚɟɬ ɧɟ ɧɚ ɮɢɡɢɱɟɫɤɢɣ ɞɢɫɤ, ɚ ɨɛɨɡɧɚɱɚɟɬ ɫɟɬɟɜɭɸ ɩɚɩɤɭ ɨɛɳɟɝɨ ɞɨɫɬɭɩɚ. ɇɚɩɪɢɦɟɪ, ɟɫɥɢ ɧɚ ɫɟɪɜɟɪɟ ɧɚ ɞɢɫɤɟ D ɡɚɜɟɞɟɧɚ ɩɚɩɤɚ ɨɛɳɟɝɨ ɞɨɫɬɭɩɚ d:\ib, ɨɬɨɛɪɚɠɚɟɦɚɹ ɧɚ ɛɭɤɜɭ H. ȼ ɤɚɱɟɫɬɜɟ ɩɭɬɢ ɤ ɛɚɡɟ ɞɚɧɧɵɯ ɦɨɠɧɨ ɩɪɨɩɢɫɵɜɚɬɶ ɬɨɥɶɤɨ ɮɢɡɢɱɟɫɤɢɣ ɩɭɬɶ ɤ ȻȾ ɧɚ ɤɨɦɩɶɸɬɟɪɟ, ɝɞɟ ɭɫɬɚɧɨɜɥɟɧ ɫɟɪɜɟɪ. ȼ ɩɪɢɜɟɞɟɧɧɨɦ ɩɪɢɦɟɪɟ ɬɚɤɢɦ ɩɭɬɟɦ ɹɜɥɹɥɫɹ ɩɭɬɶ d:\ib\4gr\MyBase\sklad.gdb, ɤɨɬɨɪɵɣ ɢ ɧɚɞɨ ɭɤɚɡɵɜɚɬɶ ɩɪɢ ɪɟɝɢɫɬɪɚɰɢɢ ɫɟɪɜɟɪɚ. ȼ ɪɟɚɥɶɧɵɯ ɫɢɬɭɚɰɢɹɯ ɞɥɹ ɜɵɹɫɧɟɧɢɹ ɞɨɩɭɫɬɢɦɵɯ ɩɭɬɟɣ ɨɛɪɚɬɢɬɟɫɶ ɤ ɚɞɦɢɧɢɫɬɪɚɬɨɪɭ ɫɟɬɢ. ɉɪɢ ɪɚɛɨɬɟ ɜ ɫɟɬɢ ɨɤɧɚ ɫɨɡɞɚɧɢɹ ɢ ɪɟɝɢɫɬɪɚɰɢɢ ȻȾ ɜ IBExpert ɢɦɟɸɬ ɧɟɫɤɨɥɶɤɨ ɢɧɨɣ ɜɢɞ (ɪɢɫ. 1.5), ɝɞɟ ɞɥɹ ɭɞɨɛɫɬɜɚ ɢɦɹ ɫɟɪɜɟɪɚ c1r214srv ɡɚɩɢɫɵɜɚɟɬɫɹ ɨɬɞɟɥɶɧɨ ɜ ɜɟɪɯɧɟɣ ɱɚɫɬɢ ɨɤɧɚ. Ɋɚɡɭɦɟɟɬɫɹ, ɟɫɥɢ ȻȾ ɢɫɩɨɥɶɡɭɟɬɫɹ ɧɟ ɬɨɥɶɤɨ ɞɥɹ ɭɱɟɛɧɵɯ ɰɟɥɟɣ, ɬɨ ɚɞɦɢɧɢɫɬɪɚɬɨɪ ɞɨɥɠɟɧ ɡɚɪɚɧɟɟ ɫɨɡɞɚɬɶ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ȻȾ ɫ ɧɟɚɞɦɢɧɢɫɬɪɚɬɢɜɧɵɦɢ ɩɪɚɜɚɦɢ, ɢɦɟɧɚ ɢ ɩɚɪɨɥɢ ɤɨɬɨɪɵɯ ȼɵ, ɤɚɤ ɪɹɞɨɜɵɟ ɩɨɥɶɡɨɜɚɬɟɥɢ, ɭɤɚɡɵɜɚɟɬɟ ɜɦɟɫɬɨ SYSDBA ɢ masterkey (ɩ. 1.7.2).
8
Ɋɢɫ. 1.5. ȿɫɥɢ ȼɚɦ ɬɪɟɛɭɟɬɫɹ ɩɟɪɟɧɟɫɬɢ ɝɨɬɨɜɭɸ ɛɚɡɭ ɞɚɧɧɵɯ ɫ ɞɪɭɝɨɝɨ ɤɨɦɩɶɸɬɟɪɚ, ɬɨ ɞɥɹ ɪɟɝɢɫɬɪɚɰɢɢ ɟɟ ɧɚ ɫɟɪɜɟɪɟ ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ ɞɜɚ ɞɟɣɫɬɜɢɹ: x ɫɤɨɩɢɪɨɜɚɬɶ ɮɚɣɥ H:\4gr\MyBase;
ȻȾ
ɧɚ
ɫɟɪɜɟɪ,
ɧɚɩɪɢɦɟɪ
ɜ
ɩɚɩɤɭ
x ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɬɶ ȻȾ, ɜɵɛɪɚɜ ɜ ɝɥɚɜɧɨɦ ɦɟɧɸ IBExpert ɩɭɧɤɬ DataBase – Register DataBase ɢ ɡɚɩɨɥɧɢɜ ɨɤɧɨ (ɪɢɫ. 1.6).
Ɋɢɫ. 1.6. 9
ɇɚɫɬɨɹɬɟɥɶɧɨ ɧɟ ɪɟɤɨɦɟɧɞɭɟɬɫɹ ɪɟɝɢɫɬɪɢɪɨɜɚɬɶ ɛɚɡɵ ɞɚɧɧɵɯ ɫ ɩɪɚɜɚɦɢ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ SYSDBA. Ⱦɟɥɨ ɜ ɬɨɦ, ɱɬɨ IBExpert ɫɨɯɪɚɧɹɟɬ ɩɚɪɨɥɶ, ɧɟɨɛɯɨɞɢɦɵɣ ɞɥɹ ɩɨɞɤɥɸɱɟɧɢɹ ɤ ɫɟɪɜɟɪɭ, ɜ ɫɜɨɟɦ ɤɨɧɮɢɝɭɪɚɰɢɨɧɧɨɦ ɮɚɣɥɟ ɜ ɧɟɡɚɲɢɮɪɨɜɚɧɧɨɦ ɜɢɞɟ. Ⱦɥɹ ɯɚɤɟɪɚ ɥɭɱɲɟɝɨ ɩɨɞɚɪɤɚ ɧɟ ɧɚɣɬɢ. ȿɫɥɢ ɠɟ ɧɟɨɛɯɨɞɢɦɨɫɬɶ ɜ ɬɚɤɨɣ ɪɟɝɢɫɬɪɚɰɢɢ ɜɫɟ ɠɟ ɜɨɡɧɢɤɥɚ, ɬɨ ɫɥɟɞɭɟɬ ɡɚɳɢɬɢɬɶ ɮɚɣɥɵ IBExpert ɨɬ ɧɟɫɚɧɤɰɢɨɧɢɪɨɜɚɧɧɨɝɨ ɞɨɫɬɭɩɚ ɫɪɟɞɫɬɜɚɦɢ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɵ. ɇɚɢɥɭɱɲɢɣ ɜɚɪɢɚɧɬ – ɨɬɤɚɡɚɬɶɫɹ ɨɬ ɢɫɩɨɥɶɡɨɜɚɧɢɹ IBExpert ɧɚ ɤɥɢɟɧɬɫɤɢɯ ɤɨɦɩɶɸɬɟɪɚɯ ɢ ɢɫɩɨɥɶɡɨɜɚɬɶ ɟɟ ɬɨɥɶɤɨ ɧɚ ɤɨɦɩɶɸɬɟɪɟ-ɫɟɪɜɟɪɟ ȻȾ, ɤɭɞɚ ɞɨɫɬɭɩ ɨɛɵɱɧɵɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ ɡɚɩɪɟɳɟɧ ɩɨɥɢɬɢɤɨɣ ɛɟɡɨɩɚɫɧɨɫɬɢ ɫɟɪɜɟɪɚ. Ɂɚɦɟɱɚɧɢɟ. ȼ ɥɢɬɟɪɚɬɭɪɟ ɪɟɤɨɦɟɧɞɭɟɬɫɹ ɞɥɹ ɤɨɪɪɟɤɬɧɨɣ ɪɚɛɨɬɵ ɫ ɪɭɫɫɤɢɦɢ ɛɭɤɜɚɦɢ ɧɚɫɬɪɚɢɜɚɬɶ InterBase ɫɩɟɰɢɚɥɶɧɵɦ ɨɛɪɚɡɨɦ: ɭɤɚɡɵɜɚɬɶ ɜ ɤɚɱɟɫɬɜɟ ɧɚɛɨɪɚ ɫɢɦɜɨɥɨɜ (CharSet) ɩɪɢ ɫɨɡɞɚɧɢɢ ȻȾ WIN1251 ɢ ɡɚɞɚɜɚɬɶ ɚɬɪɢɛɭɬ COLLATE PXW_CYRL ɩɪɢ ɨɩɪɟɞɟɥɟɧɢɢ ɫɬɪɨɤɨɜɵɯ ɩɨɥɟɣ. Ɉɞɧɚɤɨ ɪɟɚɥɶɧɨ ɜɫɟ ɷɬɨ ɧɟɨɛɯɨɞɢɦɨ ɬɨɥɶɤɨ ɞɥɹ ɩɪɚɜɢɥɶɧɨɣ ɪɚɛɨɬɵ ɮɭɧɤɰɢɢ Upper ɹɡɵɤɚ SQL ɫ ɪɭɫɫɤɢɦɢ ɛɭɤɜɚɦ ɢ ɫɨɪɬɢɪɨɜɤɢ (ORDER BY), ɧɟɱɭɜɫɬɜɢɬɟɥɶɧɨɣ ɤ ɪɟɝɢɫɬɪɭ ɛɭɤɜ. ɉɨ ɦɧɟɧɢɸ ɚɜɬɨɪɨɜ, ɫɨɜɩɚɞɚɸɳɟɦɭ ɫ ɬɨɱɤɨɣ ɡɪɟɧɢɹ ɧɟɤɨɬɨɪɵɯ ɚɜɬɨɪɢɬɟɬɨɜ ɢɡ Internet-ɮɨɪɭɦɨɜ, ɭɞɨɛɧɟɟ ɩɨɫɬɭɩɚɬɶ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ. ɉɪɢ ɫɨɡɞɚɧɢɢ ȻȾ ɧɚɛɨɪ ɫɢɦɜɨɥɨɜ ɧɟ ɭɤɚɡɵɜɚɟɬɫɹ (NONE), ɩɨɪɹɞɨɤ ɫɨɪɬɢɪɨɜɤɢ COLLATE PXW_CYRL ɧɢɝɞɟ ɧɟ ɡɚɞɚɟɬɫɹ. ȼɦɟɫɬɨ ɮɭɧɤɰɢɢ Upper ɢɫɩɨɥɶɡɭɟɬɫɹ ɮɭɧɤɰɢɹ UpCase ɢɡ ɦɨɞɭɥɹ CASEUDF, ɤɨɬɨɪɵɣ ɦɨɠɧɨ ɫɤɚɱɚɬɶ ɩɨ ɚɞɪɟɫɭ http://www.ibase.ru/ download/caseudf.zip ɢ ɭɫɬɚɧɨɜɢɬɶ ɧɚ ɫɟɪɜɟɪɟ (ɪɚɡɞɟɥ 3). Ɍɨɝɞɚ ɩɨɢɫɤ ɢ ɫɨɪɬɢɪɨɜɤɚ, ɧɟɱɭɜɫɬɜɢɬɟɥɶɧɵɟ ɤ ɪɟɝɢɫɬɪɭ ɛɭɤɜ, ɡɚɩɢɫɵɜɚɸɬɫɹ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: SELECT * FROM Customers WHERE UpCase(CustName)=”ɂȼȺɇɈȼ” ORDER BY UpCase(Address).
ɋɬɚɧɞɚɪɬɧɚɹ ɮɭɧɤɰɢɹ Upper ɹɡɵɤɚ SQL, ɩɟɪɟɜɨɞɹɳɚɹ ɫɢɦɜɨɥɵ ɤ ɜɟɪɯɧɟɦɭ ɪɟɝɢɫɬɪɭ, ɫ ɪɭɫɫɤɢɦɢ ɛɭɤɜɚɦɢ ɧɟ ɪɚɛɨɬɚɟɬ. 1.4. ɋɨɡɞɚɧɢɟ ɬɚɛɥɢɰ Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɬɚɛɥɢɰ, ɝɟɧɟɪɚɬɨɪɨɜ, ɬɪɢɝɝɟɪɨɜ ɢ ɞɪɭɝɢɯ ɦɟɬɚɞɚɧɧɵɯ (ɤɚɤ, ɜɩɪɨɱɟɦ, ɢ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ ɥɸɛɵɯ SQL-ɡɚɩɪɨɫɨɜ) ɧɟɨɛɯɨɞɢɦɨ ɫɨɟɞɢɧɢɬɶɫɹ ɫ ɭɠɟ ɫɭɳɟɫɬɜɭɸɳɟɣ ȻȾ. Ⱦɥɹ ɷɬɨɝɨ ɩɨɫɥɟ ɡɚɩɭɫɤɚ IBExpert ɪɚɫɤɪɨɣɬɟ ɚɥɢɚɫ ȻȾ, ɜɵɞɟɥɢɬɟ ɜɟɬɤɭ Tables ɢ ɜ ɤɨɧɬɟɤɫɬɧɨɦ ɦɟɧɸ ɜɵɛɟɪɢɬɟ ɩɭɧɤɬ New Table. ɋɪɚɡɭ ɠɟ ɢɡɦɟɧɢɬɟ ɢɦɹ ɬɚɛɥɢɰɵ ɧɚ Customers (ɜɟɪɯɧɸɸ ɱɚɫɬɶ ɨɤɧɚ ɧɚ ɪɢɫ. 1.7). Ⱦɨɛɚɜɶɬɟ ɢɦɟɧɚ ɩɨɥɟɣ, ɜɵɛɢɪɚɹ ɢɯ ɬɢɩ (ɢɥɢ ɞɨɦɟɧ) ɢɡ ɫɩɢɫɤɚ ɞɨɫɬɭɩɧɵɯ ɬɢɩɨɜ (ɢɥɢ ɞɨɦɟɧɨɜ). ɑɬɨɛɵ ɨɛɴɹɜɢɬɶ ɩɨɥɟ ɩɟɪɜɢɱɧɵɦ ɤɥɸɱɨɦ ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚɩɪɨɬɢɜ ɧɟɝɨ ɜ ɤɨɥɨɧɤɟ PK. 10
ɇɚɠɚɬɢɟ ɩɟɪɜɨɣ ɤɧɨɩɤɢ ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɢɥɢ Ctrl+F9 ɝɟɧɟɪɢɪɭɟɬ DDL ɨɩɟɪɚɬɨɪ ɫɨɡɞɚɧɢɹ ɬɚɛɥɢɰɵ, ɤɨɬɨɪɨɟ ɡɚɬɟɦ ɫɥɟɞɭɟɬ ɩɨɞɬɜɟɪɞɢɬɶ, ɧɚɠɚɜ ɤɧɨɩɤɭ Commit ɜ ɫɥɟɞɭɸɳɟɦ ɨɤɧɟ. Ɂɚɦɟɬɢɦ, ɱɬɨ ɢ ɞɚɥɟɟ ɜɫɟ ɞɟɣɫɬɜɢɹ ɜ IBExpert ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɤɚɤ ɬɪɚɧɡɚɤɰɢɢ ɢ ɬɪɟɛɭɸɬ ɹɜɧɨɝɨ ɩɨɞɬɜɟɪɠɞɟɧɢɹ (Commit), ɱɬɨ ɩɨɜɵɲɚɟɬ ɧɚɞɟɠɧɨɫɬɶ ɪɚɛɨɬɵ.
Ɋɢɫ. 1.7. ɉɨɫɥɟ ɬɨɝɨ ɤɚɤ ɬɚɛɥɢɰɚ ɛɵɥɚ ɫɨɡɞɚɧɚ, ɟɟ ɫɬɪɭɤɬɭɪɭ ɦɨɠɧɨ ɩɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɦɨɞɢɮɢɰɢɪɨɜɚɬɶ. ɇɚɩɪɢɦɟɪ, ɱɬɨɛɵ ɞɨɛɚɜɢɬɶ ɧɨɜɨɟ ɩɨɥɟ, ɫɥɟɞɭɟɬ ɜ ɤɨɧɬɟɤɫɬɧɨɦ ɦɟɧɸ ɜɵɛɪɚɬɶ New Field, ɜ ɩɨɹɜɢɜɲɟɦɫɹ ɨɤɧɟ (ɪɢɫ. 1.8) ɡɚɞɚɬɶ ɢɦɹ ɩɨɥɹ ɢ ɟɝɨ ɬɢɩ ɢ ɜ ɡɚɜɟɪɲɟɧɢɟ ɧɚɠɚɬɶ Ctrl+Alt+C (ɩɨɞɬɜɟɪɠɞɟɧɢɟ ɬɪɚɧɡɚɤɰɢɢ).
Ɋɢɫ. 1.8. 11
IBExpert ɩɵɬɚɟɬɫɹ ɤɨɪɪɟɤɬɧɨ ɦɨɞɢɮɢɰɢɪɨɜɚɬɶ ɫɬɪɭɤɬɭɪɭ ɬɚɛɥɢɰ ɛɟɡ ɩɨɬɟɪɢ ɫɨɞɟɪɠɚɳɢɯɫɹ ɜ ɧɢɯ ɞɚɧɧɵɯ. Ɂɚɦɟɱɚɧɢɟ: ɞɥɹ ɢɡɦɟɧɟɧɢɹ ɬɢɩɚ ɩɨɥɹ ɫɭɳɟɫɬɜɭɸɬ ɞɜɚ ɫɩɨɫɨɛɚ. ȼ ɩɟɪɜɨɦ ɫɩɨɫɨɛɟ ɫɥɟɞɭɟɬ ɭɞɚɥɢɬɶ ɩɨɥɟ ɢ ɫɨɡɞɚɬɶ ɟɝɨ ɡɚɧɨɜɨ. ȼɬɨɪɨɣ ɫɩɨɫɨɛ ɩɪɟɞɩɨɱɬɢɬɟɥɶɧɟɟ, ɧɨ ɬɪɟɛɭɟɬ ɧɟɤɨɬɨɪɨɣ ɩɪɟɞɭɫɦɨɬɪɢɬɟɥɶɧɨɫɬɢ: ɫɬɚɪɚɣɬɟɫɶ ɹɜɧɨ ɫɨɡɞɚɜɚɬɶ ɞɨɦɟɧɵ ɞɥɹ ɜɫɟɯ ɢɫɩɨɥɶɡɭɟɦɵɯ ɜ ȻȾ ɬɢɩɨɜ ɞɚɧɧɵɯ. Ⱦɥɹ ɢɡɦɟɧɟɧɢɹ ɬɢɩɚ ɞɨɫɬɚɬɨɱɧɨ ɛɭɞɟɬ ɜɵɛɪɚɬɶ ɧɟɨɛɯɨɞɢɦɵɣ ɞɨɦɟɧ ɢɡ ɫɩɢɫɤɚ ɧɚ ɩɟɪɜɨɣ ɜɤɥɚɞɤɟ ɩɪɟɞɵɞɭɳɟɝɨ ɨɤɧɚ. InterBase ɚɜɬɨɦɚɬɢɱɟɫɤɢ, ɧɟɹɜɧɨ ɫɨɡɞɚɟɬ ɞɨɦɟɧɵ ɞɥɹ ɜɫɟɯ ɫɨɡɞɚɜɚɟɦɵɯ ɩɨɥɟɣ, ɧɨ ɩɪɢɫɜɚɢɜɚɟɬ ɢɦ «ɧɟɭɞɨɛɨɱɢɬɚɟɦɵɟ» ɢɦɟɧɚ, ɧɚɩɪɢɦɟɪ, RDB$6. ɉɨɷɬɨɦɭ ɥɭɱɲɟ ɫɨɡɞɚɜɚɬɶ ɞɨɦɟɧɵ ɹɜɧɨ. Ⱦɥɹ ɹɜɧɨɝɨ ɫɨɡɞɚɧɢɹ ɞɨɦɟɧɚ ɜɵɞɟɥɢɬɟ ɨɛɴɟɤɬ Domains ɜ ɨɤɧɟ Database Explorer, ɧɚɠɦɢɬɟ CTRL+N ɢ ɡɚɩɨɥɧɢɬɟ ɨɤɧɨ, ɩɨɤɚɡɚɧɧɨɟ ɧɚ ɪɢɫ. 1.9, ɭɤɚɡɚɜ ɩɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɧɚɤɥɚɞɵɜɚɟɦɵɟ ɧɚ ɞɨɦɟɧ ɨɝɪɚɧɢɱɟɧɢɹ. Ⱦɚɥɟɟ ɩɪɢ ɫɨɡɞɚɧɢɢ ɩɨɥɹ ɭɤɚɡɵɜɚɟɦ ɧɟ ɬɢɩ Varchar(40) not null, ɚ ɢɦɹ ɞɨɦɟɧɚ Address_Domain.
Ɋɢɫ. 1.9. 1.5. ɋɨɡɞɚɧɢɟ ɝɟɧɟɪɚɬɨɪɨɜ, ɬɪɢɝɝɟɪɨɜ ɢ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ Ƚɟɧɟɪɚɬɨɪɵ ɨɛɵɱɧɨ ɢɫɩɨɥɶɡɭɸɬɫɹ ɜ InterBase ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɭɧɢɤɚɥɶɧɵɯ ɚɜɬɨɢɧɤɪɟɦɟɧɬɧɵɯ ɡɧɚɱɟɧɢɣ ɫɭɪɪɨɝɚɬɧɵɯ ɩɟɪɜɢɱɧɵɯ ɤɥɸɱɟɣ ɩɪɢ ɜɫɬɚɜɤɟ ɧɨɜɵɯ ɡɚɩɢɫɟɣ. Ɂɚɧɟɫɟɧɢɟ ɢɯ ɜ ɩɟɪɜɢɱɧɵɟ ɤɥɸɱɟɜɵɟ ɩɨɥɹ ɦɨɠɟɬ ɛɵɬɶ ɜɵɩɨɥɧɟɧɨ ɢɥɢ ɬɪɢɝɝɟɪɨɦ (ɚɜɬɨɦɚɬɢɱɟɫɤɢ), ɢɥɢ ɤɥɢɟɧɬɫɤɢɦ ɩɪɢɥɨɠɟɧɢɟɦ. ɋɨɡɞɚɬɶ ɝɟɧɟɪɚɬɨɪ ɩɪɨɳɟ ɜɫɟɝɨ ɫɪɚɡɭ ɩɪɢ ɨɛɴɹɜɥɟɧɢɢ ɩɟɪɜɢɱɧɨɝɨ ɤɥɸɱɟɜɨɝɨ ɩɨɥɹ. Ⱦɥɹ ɷɬɨɝɨ ɧɚɞɨ ɩɟɪɟɣɬɢ ɧɚ ɜɤɥɚɞɤɭ AutoIncrement ɢ ɩɨɦɟɬɢɬɶ ɮɥɚɝ Create Generator. Ƚɟɧɟɪɚɬɨɪ ɛɭɞɟɬ ɫɨɡɞɚɧ ɚɜɬɨɦɚɬɢɱɟɫɤɢ, ɟɝɨ ɢɦɹ ɢ ɧɚɱɚɥɶɧɨɟ ɡɧɚɱɟɧɢɟ ɦɨɠɧɨ ɩɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɨɬɪɟɞɚɤɬɢɪɨɜɚɬɶ.
12
Ɋɢɫ. 1.10. ɇɚ ɜɤɥɚɞɤɟ Trigger ɨɬɦɟɬɶɬɟ ɮɥɚɝ Create Trigger, ɱɬɨ ɩɪɢɜɟɞɟɬ ɤ ɚɧɚɥɨɝɢɱɧɨɦɭ ɪɟɡɭɥɶɬɚɬɭ.
Ɋɢɫ. 1.11. Ɂɞɟɫɶ ɛɵɥ ɫɨɡɞɚɧ ɬɪɢɝɝɟɪ, ɜɵɩɨɥɧɹɸɳɢɣɫɹ ɩɨɫɥɟ ɫɨɛɵɬɢɹ ɜɫɬɚɜɤɢ ɧɨɜɨɣ ɡɚɩɢɫɢ ɢ ɡɚɩɨɥɧɹɸɳɢɣ ɤɥɸɱɟɜɨɟ ɩɨɥɟ ɧɨɜɨɣ ɡɚɩɢɫɢ ɭɧɢɤɚɥɶɧɵɦ ɡɧɚɱɟɧɢɟɦ. ɇɚ ɜɫɹɤɢɣ ɫɥɭɱɚɣ ɫɝɟɧɟɪɢɪɭɣɬɟ ɬɟɦ ɠɟ ɫɩɨɫɨɛɨɦ ɢ ɯɪɚɧɢɦɭɸ ɩɪɨɰɟɞɭɪɭ (ɜɤɥɚɞɤɚ Procedure) ɞɥɹ ɩɟɪɟɞɚɱɢ ɡɧɚɱɟɧɢɹ ɝɟɧɟɪɚɬɨɪɚ ɜɨ ɜɧɟɲɧɸɸ ɫɪɟɞɭ, ɧɚɩɪɢɦɟɪ, ɜ ɤɥɢɟɧɬɫɤɨɟ ɩɪɢɥɨɠɟɧɢɟ. CREATE PROCEDURE SP_GEN_CUSTOMERS_ID
13
RETURNS (ID INTEGER) AS BEGIN ID = GEN_ID(GEN_CUSTOMERS_ID, 1); SUSPEND; END
Ƚɟɧɟɪɚɬɨɪɵ, ɬɪɢɝɝɟɪɵ ɢ ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ɦɨɠɧɨ ɬɚɤɠɟ ɫɨɡɞɚɜɚɬɶ ɢ ɜɪɭɱɧɭɸ (ɱɟɪɟɡ ɨɤɧɨ Database Explorer). ɉɪɢ ɫɨɡɞɚɧɢɢ ɬɪɢɝɝɟɪɨɜ ɢ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ ɨɬɤɪɵɜɚɟɬɫɹ ɭɞɨɛɧɵɣ ɪɟɞɚɤɬɨɪ ɫ ɫɢɧɬɚɤɫɢɱɟɫɤɨɣ ɩɨɞɫɜɟɬɤɨɣ ɢ ɧɢɫɩɚɞɚɸɳɢɦɢ ɫɩɢɫɤɚɦɢ ɩɨɞɫɤɚɡɨɤ. ȼɧɟɲɧɢɣ ɜɢɞ ɪɟɞɚɤɬɨɪɚ ɩɪɟɞɫɬɚɜɥɟɧ ɧɚ ɪɢɫ. 1.12. Ɉɬɦɟɬɢɦ, ɱɬɨ ɪɟɞɚɤɬɢɪɭɟɬɫɹ ɬɨɥɶɤɨ ɬɟɥɨ ɬɪɢɝɝɟɪɚ. ɇɚɡɜɚɧɢɟ ɬɚɛɥɢɰɵ ɢ ɫɨɛɵɬɢɟ ɞɥɹ ɬɪɢɝɝɟɪɚ (After Insert ɢ ɬ.ɩ.) ɜɵɛɢɪɚɸɬɫɹ ɢɡ ɫɩɢɫɤɨɜ. Ⱥɧɚɥɨɝɢɱɧɵɟ ɞɟɣɫɬɜɢɹ ɦɨɠɧɨ ɜɵɩɨɥɧɢɬɶ ɞɥɹ ɜɫɟɯ ɫɨɡɞɚɜɚɟɦɵɯ ɬɚɛɥɢɰ. ɉɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɦɨɠɧɨ ɫɨɡɞɚɬɶ ɞɨɩɨɥɧɢɬɟɥɶɧɵɟ ɬɪɢɝɝɟɪɵ, ɧɚɩɪɢɦɟɪ ɞɥɹ ɤɚɫɤɚɞɧɵɯ ɜɨɡɞɟɣɫɬɜɢɣ ɢɥɢ ɜɟɞɟɧɢɹ ɫɬɚɬɢɫɬɢɤɢ. Ɂɚɦɟɬɢɦ, ɱɬɨ ɞɥɹ ɤɚɠɞɨɝɨ ɞɟɣɫɬɜɢɹ ɩɨ ɫɨɡɞɚɧɢɸ ɬɚɛɥɢɰ ɢ ɞɪɭɝɢɯ ɨɛɴɟɤɬɨɜ ɦɨɠɧɨ ɩɪɨɫɦɨɬɪɟɬɶ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɨɩɟɪɚɬɨɪ ɨɩɪɟɞɟɥɟɧɢɹ ɞɚɧɧɵɯ ɧɚ ɡɚɤɥɚɞɤɟ DDL. Ⱦɟɣɫɬɜɢɟ ɜɫɬɭɩɚɟɬ ɜ ɫɢɥɭ ɩɨɫɥɟ ɩɪɢɦɟɧɟɧɢɹ (ɤɧɨɩɤɚ ɫ «ɦɨɥɧɢɟɣ» ɧɚ ɩɚɧɟɥɢ ɜ ɜɟɪɯɧɟɣ ɱɚɫɬɢ ɨɤɧɚ).
Ɋɢɫ. 1.12. 1.6. ȼɵɩɨɥɧɟɧɢɟ SQL-ɡɚɩɪɨɫɨɜ ȼ IBExpert ɫɭɳɟɫɬɜɭɟɬ ɧɟɫɤɨɥɶɤɨ ɫɩɨɫɨɛɨɜ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɬɨɪɨɜ ɹɡɵɤɚ SQL. ɂɧɫɬɪɭɦɟɧɬ SQL Editor (ɤɥɚɜɢɲɚ F12) ɧɚɢɛɨɥɟɟ ɭɧɢɜɟɪɫɚɥɟɧ 14
ɢ ɩɪɟɞɧɚɡɧɚɱɟɧ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ ɩɪɨɢɡɜɨɥɶɧɵɯ ɨɩɟɪɚɬɨɪɨɜ ɫɨɡɞɚɧɢɹ, ɜɵɛɨɪɤɢ, ɦɚɧɢɩɭɥɢɪɨɜɚɧɢɹ ɢ ɭɩɪɚɜɥɟɧɢɹ ɞɚɧɧɵɦɢ.
Ɋɢɫ. 1.13. ɂɧɫɬɪɭɦɟɧɬ Query Builder (ɩɭɧɤɬ ɦɟɧɸ Tools) ɭɞɨɛɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ, ɤɚɤ ɫɥɟɞɭɟɬ ɢɡ ɧɚɡɜɚɧɢɹ, ɞɥɹ ɜɢɡɭɚɥɶɧɨɝɨ ɩɨɫɬɪɨɟɧɢɹ ɡɚɩɪɨɫɨɜ SELECT. ȼɤɥɚɞɤɚ Builder ɩɪɟɞɧɚɡɧɚɱɟɧɚ ɞɥɹ ɤɨɧɫɬɪɭɢɪɨɜɚɧɢɹ ɡɚɩɪɨɫɚ, ɜɤɥɚɞɤɚ Edit – ɞɥɹ ɩɪɨɫɦɨɬɪɚ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɟɝɨ ɬɟɤɫɬɚ, Result – ɩɪɨɫɦɨɬɪɚ ɪɟɡɭɥɶɬɚɬɚ. Ⱦɥɹ ɜɵɩɨɥɧɟɧɢɹ ɡɚɩɪɨɫɚ ɧɚɠɦɢɬɟ F9, ɧɨ ɩɟɪɟɞ ɷɬɢɦ ɭɛɟɞɢɬɟɫɶ, ɱɬɨ ɧɭɠɧɚɹ ɛɚɡɚ ɞɚɧɧɵɯ (NewSklad) ɜɵɛɪɚɧɚ ɜ ɥɟɜɨɦ ɜɟɪɯɧɟɦ ɭɝɥɭ ɨɤɧɚ ɪɢɫ. 1.13. ɂɧɫɬɪɭɦɟɧɬ Script Executive ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɢ ɜɵɩɨɥɧɟɧɢɹ ɫɤɪɢɩɬɨɜ – ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɟɣ SQL-ɨɩɟɪɚɬɨɪɨɜ. ɇɚɩɪɢɦɟɪ, ɭ ȼɚɫ ɢɦɟɟɬɫɹ ɫɤɪɢɩɬ ɞɥɹ ɫɨɡɞɚɧɢɹ ɛɚɡɵ ɞɚɧɧɵɯ, ɩɨɥɭɱɟɧɧɵɣ ɩɪɢ ɩɨɦɨɳɢ ɫɢɫɬɟɦɵ Case-ɩɪɨɟɤɬɢɪɨɜɚɧɢɹ ERWIN. ɋɤɪɢɩɬ ɯɪɚɧɢɬɫɹ ɜ ɬɟɤɫɬɨɜɨɦ ɮɚɣɥɟ sklad.sql ɢ ɫɨɞɟɪɠɢɬ ɞɜɚ ɨɩɟɪɚɬɨɪɚ Create Table. Ɂɚɝɪɭɡɢɬɟ ɷɬɨɬ ɮɚɣɥ ɜ Script Executive (ɪɢɫ. 1.14).
Ɋɢɫ. 1.14. Ɂɚɩɭɫɬɢɬɟ ɫɤɪɢɩɬ ɫ ɩɨɦɨɳɶɸ ɤɥɚɜɢɲɢ F9. ȼ ɨɤɧɟ Database Explorer ɩɨɹɜɹɬɫɹ ɞɜɟ ɫɨɡɞɚɧɧɵɟ ɫɤɪɢɩɬɨɦ ɬɚɛɥɢɰɵ, ɤɨɬɨɪɵɟ ɦɨɠɧɨ ɜ ɞɚɥɶɧɟɣɲɟɦ ɦɨɞɢɮɢɰɢɪɨɜɚɬɶ, ɞɨɛɚɜɢɜ, ɧɚɩɪɢɦɟɪ, ɨɝɪɚɧɢɱɟɧɢɟ ɫɫɵɥɨɱɧɨɣ ɰɟɥɨɫɬɧɨɫɬɢ. 15
Ɋɢɫ. 1.15. 1.7. ɍɩɪɚɜɥɟɧɢɟ ɩɨɥɶɡɨɜɚɬɟɥɹɦɢ Ʉɚɠɞɵɣ ɫɟɪɜɟɪ InterBase ɢɦɟɟɬ ɩɨɥɶɡɨɜɚɬɟɥɹ SYSDBA ɫ ɚɞɦɢɧɢɫɬɪɚɬɢɜɧɵɦɢ ɩɨɥɧɨɦɨɱɢɹɦɢ. ɉɚɪɨɥɶ ɩɨ ɭɦɨɥɱɚɧɢɸ – masterkey. ɋɧɚɱɚɥɚ ɷɬɨ ɟɞɢɧɫɬɜɟɧɧɵɣ ɚɜɬɨɪɢɡɨɜɚɧɧɵɣ ɩɨɥɶɡɨɜɚɬɟɥɶ ɧɚ ɫɟɪɜɟɪɟ. ɂ ɨɧ ɞɨɥɠɟɧ ɚɜɬɨɪɢɡɨɜɚɬɶ (ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɬɶ) ɞɪɭɝɢɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. Ɍɨɥɶɤɨ ɩɨɥɶɡɨɜɚɬɟɥɶ SYSDBA ɢɦɟɟɬ ɩɪɚɜɚ ɧɚ ɞɨɛɚɜɥɟɧɢɟ, ɦɨɞɢɮɢɤɚɰɢɸ ɢ ɭɞɚɥɟɧɢɟ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. ɂɦɟɧɚ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɦɨɝɭɬ ɛɵɬɶ ɞɥɢɧɨɣ ɞɨ 31 ɫɢɦɜɨɥɚ, ɧɟ ɹɜɥɹɸɬɫɹ ɱɭɜɫɬɜɢɬɟɥɶɧɵɦɢ ɤ ɫɦɟɧɟ ɪɟɝɢɫɬɪɚ, ɧɨ ɧɟ ɞɨɥɠɧɵ ɫɨɞɟɪɠɚɬɶ ɩɪɨɛɟɥɨɜ. ɉɚɪɨɥɢ InterBase ɱɭɜɫɬɜɢɬɟɥɶɧɵ ɤ ɪɟɝɢɫɬɪɭ ɛɭɤɜ. Ɂɧɚɱɟɧɢɟ ɢɦɟɸɬ ɬɨɥɶɤɨ ɩɟɪɜɵɟ 8 ɫɢɦɜɨɥɨɜ ɩɚɪɨɥɹ, ɧɨ ɞɥɢɧɚ ɩɚɪɨɥɹ ɦɨɠɟɬ ɞɨɫɬɢɝɚɬɶ 32 ɫɢɦɜɨɥɨɜ. Ɋɚɫɫɦɨɬɪɢɦ ɨɫɧɨɜɧɵɟ ɨɩɟɪɚɰɢɢ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ InterBase. 1.7.1. ɋɦɟɧɚ ɩɚɪɨɥɹ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ Ɉɛɵɱɧɨ ɷɬɨ ɫɚɦɚɹ ɩɟɪɜɚɹ ɨɩɟɪɚɰɢɹ ɩɨɫɥɟ ɭɫɬɚɧɨɜɤɢ ɫɟɪɜɟɪɚ. ȼɵɛɟɪɢɬɟ ɜ ɝɥɚɜɧɨɦ ɦɟɧɸ Tools – User Manager. ȼ ɩɨɹɜɢɜɲɟɦɫɹ ɨɤɧɟ ɜɜɨɞɢɦ SYSDBA ɢ masterkey. ȼɵɞɟɥɹɟɦ ɩɨɥɶɡɨɜɚɬɟɥɹ (ɩɨɤɚ ɨɧ ɬɨɥɶɤɨ ɨɞɢɧ) ɢ ɧɚɠɢɦɚɟɦ Edit.
Ɋɢɫ. 1.16. 16
ȼɜɨɞɢɦ ɢ ɩɨɞɬɜɟɪɠɞɚɟɦ ɧɨɜɵɣ ɩɚɪɨɥɶ. ȿɫɥɢ ɜ IBExpert ɭɠɟ ɛɵɥɢ ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɧɵ ɛɚɡɵ ɞɚɧɧɵɯ ɫɨ ɫɬɚɪɵɦ ɩɚɪɨɥɟɦ, ɬɨ ɢɯ ɜɫɟ ɩɪɢɞɟɬɫɹ ɩɟɪɟɪɟɝɢɫɬɪɢɪɨɜɚɬɶ, ɢɧɚɱɟ ɫɨɟɞɢɧɟɧɢɟ ɧɟ ɛɭɞɟɬ ɭɫɬɚɧɨɜɥɟɧɨ. ȼ ɷɬɨɦ – ɫɦɵɫɥ ɩɨɹɜɥɹɸɳɟɝɨɫɹ ɧɚ ɷɤɪɚɧɟ ɩɪɟɞɭɩɪɟɠɞɟɧɢɹ. 1.7.2. Ⱦɨɛɚɜɥɟɧɢɟ ɧɨɜɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ ȼ ɨɤɧɟ User Manager ɧɚɠɢɦɚɟɦ Add ɢ ɞɨɛɚɜɥɹɟɦ ɢɧɮɨɪɦɚɰɢɸ.
Ɋɢɫ. 1.17. ɇɨɜɵɣ ɩɨɥɶɡɨɜɚɬɟɥɶ STUDENT ɫɦɨɠɟɬ ɫɨɡɞɚɜɚɬɶ ɛɚɡɵ ɞɚɧɧɵɯ ɢ ɪɟɝɢɫɬɪɢɪɨɜɚɬɶ ɢɯ, ɩɨɫɥɟ ɱɟɝɨ ɨɧ ɫɬɚɧɟɬ ɢɯ ɜɥɚɞɟɥɶɰɟɦ (owner) ɫ ɩɪɚɜɨɦ ɩɨɥɧɨɝɨ ɞɨɫɬɭɩɚ. ɉɪɢ ɫɨɟɞɢɧɟɧɢɢ c ɛɚɡɨɣ ɞɚɧɧɵɯ STUDENT ɛɭɞɟɬ ɭɤɚɡɵɜɚɬɶ ɫɜɨɢ ɭɱɟɬɧɵɟ ɞɚɧɧɵɟ. ȼɥɚɞɟɥɟɰ ɛɚɡɵ ɞɚɧɧɵɯ ɦɨɠɟɬ ɩɪɟɞɨɫɬɚɜɥɹɬɶ ɩɪɢɜɢɥɟɝɢɢ ɞɨɫɬɭɩɚ ɤ ɫɜɨɟɣ ȻȾ ɞɪɭɝɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ, ɪɚɡɪɟɲɚɹ ɢɥɢ ɡɚɩɪɟɳɚɹ ɢɦ ɨɬɞɟɥɶɧɵɟ ɨɩɟɪɚɰɢɢ. 1.7.3. ɉɪɟɞɨɫɬɚɜɥɟɧɢɟ ɩɪɢɜɢɥɟɝɢɣ ɉɨɞɤɥɸɱɟɧɢɟ ɤ ȻȾ ɧɟ ɨɡɧɚɱɚɟɬ ɚɜɬɨɦɚɬɢɱɟɫɤɭɸ ɜɨɡɦɨɠɧɨɫɬɶ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɢ ɞɚɠɟ ɨɬɨɛɪɚɠɟɧɢɹ ɞɚɧɧɵɯ. ɉɪɢɜɢɥɟɝɢɢ ɞɨɥɠɧɵ ɛɵɬɶ ɡɚɞɚɧɵ ɹɜɧɵɦ ɨɛɪɚɡɨɦ; ɩɨɥɶɡɨɜɚɬɟɥɢ ɧɟ ɫɦɨɝɭɬ ɨɛɪɚɳɚɬɶɫɹ ɧɢ ɤ ɨɞɧɨɦɭ ɨɛɴɟɤɬɭ ȻȾ, ɩɨɤɚ ɧɟ ɩɨɥɭɱɚɬ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɟ ɩɪɢɜɢɥɟɝɢɢ. ɉɪɢɜɢɥɟɝɢɢ, ɞɚɧɧɵɟ ɫɩɟɰɢɚɥɶɧɨɦɭ «ɩɨɥɶɡɨɜɚɬɟɥɸ» PUBLIC, ɩɪɢɦɟɧɢɦɵ ɞɥɹ ɜɫɟɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ. ɋɧɚɱɚɥɚ ɬɨɥɶɤɨ ɫɨɡɞɚɬɟɥɶ ɬɚɛɥɢɰɵ (owner) ɢɦɟɟɬ ɞɨɫɬɭɩ ɤ ɞɚɧɧɵɦ, ɧɨ ɨɧ ɦɨɠɟɬ ɧɚɡɧɚɱɚɬɶ ɩɪɢɜɢɥɟɝɢɢ ɞɪɭɝɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ (ɩɪɟɞɨɫɬɚɜɥɹɬɶ ɝɪɚɧɬ). Grant (ɚɧɝɥ.) – ɞɚɪ, ɩɪɟɞɨɫɬɚɜɥɟɧɢɟ, ɫɭɛɫɢɞɢɹ. Ɉɞɧɨɢɦɟɧɧɵɣ SQLɨɩɟɪɚɬɨɪ GRANT ɧɚɡɧɚɱɚɟɬ ɩɪɢɜɢɥɟɝɢɢ ɞɨɫɬɭɩɚ ɪɚɡɥɢɱɧɵɦ ɫɭɛɴɟɤɬɚɦ ɛɟɡɨɩɚɫɧɨɫɬɢ – ɤɨɧɤɪɟɬɧɵɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ, ɪɨɥɹɦ (ɩ. 3.4), ɚ ɬɚɤɠɟ ɯɪɚɧɢɦɵɦ ɩɪɨɰɟɞɭɪɚɦ ɢ ɬɪɢɝɝɟɪɚɦ. Ɉɛɴɟɤɬɚɦɢ ɛɟɡɨɩɚɫɧɨɫɬɢ (ɨɯɪɚɧɹɟɦɵɦɢ ɨɛɴɟɤɬɚɦ), ɤ ɤɨɬɨɪɵɦ ɩɪɢɦɟɧɹɟɬɫɹ GRANT, ɦɨɝɭɬ ɛɵɬɶ ɬɚɛɥɢɰɵ ɰɟɥɢɤɨɦ, ɫɬɨɥɛɰɵ ɬɚɛɥɢɰ, ɬɪɢɝɝɟɪɵ, ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ, ɩɪɨɫɦɨɬɪɵ. 17
SQL-ɨɩɟɪɚɬɨɪ REVOKE ɭɞɚɥɹɟɬ ɪɚɧɟɟ ɩɪɟɞɨɫɬɚɜɥɟɧɧɵɟ ɩɪɢɜɢɥɟɝɢɢ ɞɨɫɬɭɩɚ. ɉɪɢɜɢɥɟɝɢɹ
Ɋɚɡɪɟɲɚɟɬ ɩɨɥɶɡɨɜɚɬɟɥɹɦ…
SELECT DELETE INSERT UPDATE EXECUTE REFERENCES
ɩɪɨɫɦɚɬɪɢɜɚɬɶ ɫɬɪɨɤɢ ɜ ɬɚɛɥɢɰɟ ɢɥɢ ɩɪɨɫɦɨɬɪɟ ɭɞɚɥɹɬɶ ɫɬɪɨɤɢ ɜɫɬɚɜɥɹɬɶ ɫɬɪɨɤɢ ɢɡɦɟɧɹɬɶ ɜɫɟ ɢɥɢ ɭɤɚɡɚɧɧɵɟ ɫɬɨɥɛɰɵ ɜɵɩɨɥɧɹɬɶ ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ɫɨɡɞɚɜɚɬɶ ɜɧɟɲɧɢɣ ɤɥɸɱ, ɤɨɬɨɪɵɣ ɫɫɵɥɚɟɬɫɹ ɧɚ ɭɤɚɡɚɧɧɵɣ ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ ɬɚɛɥɢɰɵ, ɞɚɠɟ ɟɫɥɢ ɩɨɥɶɡɨɜɚɬɟɥɶ ɧɟ ɹɜɥɹɟɬɫɹ ɟɟ ɜɥɚɞɟɥɶɰɟɦ Ɉɛɴɟɞɢɧɹɟɬ SELECT, DELETE, INSERT, UPDATE, ɢ REFERENCES
ALL
ɉɪɢɜɢɥɟɝɢɢ ɦɨɠɧɨ ɧɚɡɧɚɱɚɬɶ ɜ ɞɢɚɥɨɝɨɜɨɦ ɪɟɠɢɦɟ ɫ ɩɨɦɨɳɶɸ IBExpert. ȼɵɡɨɜɢɬɟ ɜ ɝɥɚɜɧɨɦ ɦɟɧɸ ɢɧɫɬɪɭɦɟɧɬ Tools – Grant Manager. Ɉɬɤɪɨɟɬɫɹ ɨɤɧɨ, ɩɪɟɞɫɬɚɜɥɟɧɧɨɟ ɧɚ ɪɢɫ. 1.18. Ʉɚɤ ɜɢɞɢɦ, ɩɟɪɜɨɧɚɱɚɥɶɧɨ ɜɫɟ ɩɪɚɜɚ ɢɦɟɸɬɫɹ ɬɨɥɶɤɨ ɭ SYSDBA. ɍ ɩɨɥɶɡɨɜɚɬɟɥɟɣ STUDENT ɢ PUBLIC ɢɯ ɧɟɬ.
Ɋɢɫ. 1.18. ɇɚɡɧɚɱɟɧɢɟ ɩɪɢɜɢɥɟɝɢɣ ɩɪɨɢɡɜɨɞɢɬɫɹ ɞɜɨɣɧɵɦ ɳɟɥɱɤɨɦ ɥɢɛɨ ɜɵɛɨɪɨɦ ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ, ɥɢɛɨ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ. Ʉɧɨɩɤɢ ɫ ɢɡɨɛɪɚɠɟɧɢɟɦ «ɥɚɞɨɧɢ» ɨɡɧɚɱɚɸɬ Grant WITH GRANT OPTION. 18
ɉɨɥɶɡɨɜɚɬɟɥɶ, ɨɛɥɚɞɚɸɳɢɣ ɬɚɤɢɦɢ ɩɪɢɜɢɥɟɝɢɹɦɢ, ɦɨɠɟɬ ɩɪɟɞɨɫɬɚɜɥɹɬɶ ɭɤɚɡɚɧɧɭɸ ɩɪɢɜɢɥɟɝɢɸ ɞɪɭɝɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹɦ. ɉɪɢɜɢɥɟɝɢɢ ɦɨɝɭɬ ɧɚɡɧɚɱɚɬɶɫɹ ɤɚɤ ɩɨ ɨɬɧɨɲɟɧɢɸ ɤ ɬɚɛɥɢɰɚɦ, ɬɚɤ ɢ ɤ ɨɬɞɟɥɶɧɵɦ ɤɨɥɨɧɤɚɦ (ɫɦ. ɧɢɠɧɸɸ ɱɚɫɬɶ ɨɤɧɚ). 1.7.4. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɪɨɥɟɣ Ɋɨɥɶ – ɢɦɟɧɨɜɚɧɧɵɣ ɧɚɛɨɪ ɩɪɢɜɢɥɟɝɢɣ. Ɋɨɥɶ ɜɵɩɨɥɧɹɟɬ ɬɟ ɠɟ ɮɭɧɤɰɢɢ, ɱɬɨ ɢ ɝɪɭɩɩɵ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɜ Windows 2000/XP. Ɋɟɤɨɦɟɧɞɭɟɬɫɹ ɩɪɢɜɢɥɟɝɢɢ ɧɚɡɧɚɱɚɬɶ ɢɦɟɧɧɨ ɪɨɥɹɦ, ɚ ɧɟ ɩɨɥɶɡɨɜɚɬɟɥɹɦ. ɉɨɥɶɡɨɜɚɬɟɥɢ ɩɪɢɯɨɞɹɬ ɢ ɭɯɨɞɹɬ, ɚ ɪɨɥɢ – ɨɫɬɚɸɬɫɹ. ȿɫɥɢ ɩɪɢɜɢɥɟɝɢɢ ɞɚɧɵ ɧɟ ɪɨɥɹɦ, ɚ ɩɨɥɶɡɨɜɚɬɟɥɹɦ, ɬɨ ɩɪɢ ɞɨɛɚɜɥɟɧɢɢ ɧɨɜɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ ɩɨɬɪɟɛɭɟɬɫɹ ɢɯ ɜɫɟ ɧɚɡɧɚɱɚɬɶ ɟɦɭ ɡɚɧɨɜɨ. ɉɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɠɟ ɪɨɥɢ ɞɨɫɬɚɬɨɱɧɨ ɛɭɞɟɬ ɧɚɡɧɚɱɢɬɶ ɬɨɥɶɤɨ ɟɟ ɧɨɜɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ. ɉɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɞɟɣɫɬɜɢɣ ɫɥɟɞɭɸɳɚɹ: ɫɨɡɞɚɬɶ ɪɨɥɶ, ɜɤɥɸɱɢɬɶ ɜ ɟɟ ɫɨɫɬɚɜ ɧɟɨɛɯɨɞɢɦɵɟ ɩɪɢɜɢɥɟɝɢɢ, ɧɚɡɧɚɱɢɬɶ ɪɨɥɶ ɩɨɥɶɡɨɜɚɬɟɥɸ. ȼɫɟ ɨɩɟɪɚɰɢɢ ɦɨɝɭɬ ɛɵɬɶ ɜɵɩɨɥɧɟɧɵ ɫ ɩɨɦɨɳɶɸ ɫɬɚɧɞɚɪɬɧɨɝɨ ɨɩɟɪɚɬɨɪɚ GRANT, ɧɨ ɜ IBExpert ɢɦɟɸɬɫɹ ɢ ɛɨɥɟɟ ɭɞɨɛɧɵɟ ɞɢɚɥɨɝɨɜɵɟ ɫɪɟɞɫɬɜɚ. ɋɨɡɞɚɞɢɦ ɜ ɤɚɱɟɫɬɜɟ ɩɪɢɦɟɪɚ ɪɨɥɢ Manager ɢ Guest. Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɪɨɥɟɣ ɫɥɭɠɢɬ ɜɤɥɚɞɤɚ Roles ɢɧɫɬɪɭɦɟɧɬɚ User Manager.
Ɋɢɫ. 1.19. ɇɚɡɧɚɱɟɧɢɟ ɩɪɢɜɢɥɟɝɢɣ ɞɥɹ ɪɨɥɟɣ ɜɵɩɨɥɧɹɟɬɫɹ ɫ ɩɨɦɨɳɶɸ Grant Manager (ɪɢɫ. 1.18), ɤɚɤ ɢ ɞɥɹ ɨɛɵɱɧɵɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ, ɬɨɥɶɤɨ ɜ ɤɨɦɛɢɧɢɪɨɜɚɧɧɨɦ ɫɩɢɫɤɟ ɜ ɥɟɜɨɦ ɜɟɪɯɧɟɦ ɭɝɥɭ ɨɤɧɚ ɫɥɟɞɭɸɬ ɜɵɛɪɚɬɶ ɷɥɟɦɟɧɬ ɧɟ «Users», ɚ «Roles». Ȼɭɞɶɬɟ ɜɧɢɦɚɬɟɥɶɧɵ: ɪɨɥɢ, ɜ ɨɬɥɢɱɢɟ ɨɬ ɩɨɥɶɡɨɜɚɬɟɥɟɣ, ɯɪɚɧɹɬɫɹ ɜ ɫɚɦɨɣ ɛɚɡɟ ɞɚɧɧɵɯ, ɩɨɷɬɨɦɭ ɩɟɪɟɞ ɧɚɡɧɚɱɟɧɢɟɦ ɩɪɢɜɢɥɟɝɢɣ ɧɟɨɛɯɨɞɢɦɨ ɤ ɷɬɨɣ ɛɚɡɟ ɩɨɞɤɥɸɱɢɬɶɫɹ. (ɉɨɥɶɡɨɜɚɬɟɥɢ InterBase ɨɩɪɟɞɟɥɹɸɬɫɹ ɧɚ ɭɪɨɜɧɟ ɫɟɪɜɟɪɚ ɢ ɯɪɚɧɹɬɫɹ ɜ ɫɥɭɠɟɛɧɨɣ ɛɚɡɟ ɞɚɧɧɵɯ isc4.gdb). Ⱦɥɹ ɜɤɥɸɱɟɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɜ ɫɨɫɬɚɜ ɪɨɥɢ ɩɟɪɟɣɞɢɬɟ ɧɚ ɜɤɥɚɞɤɭ Membership ɢ ɨɬɦɟɬɶɬɟ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɮɥɚɠɨɤ (ɪɢɫ. 1.20). ȼɵɛɨɪ ɮɥɚɝɚ With ADMIN OPTION ɨɡɧɚɱɚɟɬ, ɱɬɨ ɩɨɥɶɡɨɜɚɬɟɥɶ, ɜɤɥɸɱɟɧɧɵɣ ɜ ɫɨɫɬɚɜ ɪɨɥɢ, ɛɭɞɟɬ ɢɦɟɬɶ ɜɨɡɦɨɠɧɨɫɬɶ ɧɚɡɧɚɱɟɧɢɹ, ɨɬɡɵɜɚ ɢ ɭɞɚɥɟɧɢɹ ɪɨɥɢ, ɬ. ɟ. ɫɬɚɧɟɬ ɟɟ ɚɞɦɢɧɢɫɬɪɚɬɨɪɨɦ. 19
Ɋɢɫ. 1.20. Ɂɚɦɟɱɚɧɢɟ. ȿɫɥɢ ɩɨɥɶɡɨɜɚɬɟɥɶ ɢɦɟɟɬ ɩɪɢɜɢɥɟɝɢɢ ɞɨɫɬɭɩɚ ɤ ȻȾ ɬɨɥɶɤɨ ɱɟɪɟɡ ɪɨɥɶ, ɬɨ ɢɦɹ ɪɨɥɢ ɞɨɥɠɧɨ ɛɵɬɶ ɭɤɚɡɚɧɨ ɩɪɢ ɥɸɛɨɦ ɫɨɟɞɢɧɟɧɢɢ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ, ɧɚɩɪɢɦɟɪ, ɱɟɪɟɡ ɨɩɟɪɚɬɨɪɵ SQL, ɜ ɨɤɧɟ ɪɟɝɢɫɬɪɚɰɢɢ IBExpert, ɜ ɤɨɦɩɨɧɟɧɬɚɯ ɤɥɢɟɧɬɫɤɢɯ ɩɪɢɥɨɠɟɧɢɣ ɢ ɬ. ɩ. 1.8. ɋɨɡɞɚɧɢɟ UDF ɉɨɦɢɦɨ ɜɫɬɪɨɟɧɧɵɯ ɩɪɨɫɬɟɣɲɢɯ ɮɭɧɤɰɢɣ ɹɡɵɤɚ SQL, ɬɚɤɢɯ, ɤɚɤ min(), max(), avg(), InterBase ɩɨɞɞɟɪɠɢɜɚɟɬ ɛɢɛɥɢɨɬɟɤɢ ɜɧɟɲɧɢɯ ɮɭɧɤɰɢɣ UDF (ɮɭɧɤɰɢɣ, ɨɩɪɟɞɟɥɹɟɦɵɯ ɩɨɥɶɡɨɜɚɬɟɥɟɦ). UDF ɫɭɳɟɫɬɜɟɧɧɨ ɪɚɫɲɢɪɹɸɬ ɜɨɡɦɨɠɧɨɫɬɢ ɹɡɵɤɚ SQL. ɇɚɩɪɢɦɟɪ, ɜ ɫɨɫɬɚɜ Firebird ɜɯɨɞɹɬ UDF ɦɚɬɟɦɚɬɢɱɟɫɤɢɯ ɢ ɤɚɥɟɧɞɚɪɧɵɯ ɮɭɧɤɰɢɣ. UDF ɦɨɠɧɨ ɫɨɡɞɚɜɚɬɶ ɫ ɩɨɦɨɳɶɸ ɥɸɛɵɯ ɤɨɦɩɢɥɹɬɨɪɨɜ (ɋ, Delphi, Fortran ɢ ɬ. ɩ.). Ⱦɥɹ ɷɬɨɝɨ ɧɟɨɛɯɨɞɢɦɨ ɧɚɩɢɫɚɬɶ ɧɟɨɛɯɨɞɢɦɵɟ ɮɭɧɤɰɢɢ, ɨɬɤɨɦɩɢɥɢɪɨɜɚɬɶ ɢɯ, ɜɤɥɸɱɢɬɶ ɜ ɫɨɫɬɚɜ DLL ɢ ɨɛɴɹɜɢɬɶ ɧɚ ɫɟɪɜɟɪɟ InterBase. UDF ɦɨɠɟɬ ɩɪɢɧɹɬɶ ɞɨ 10 ɩɚɪɚɦɟɬɪɨɜ, ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɥɸɛɨɦɭ ɬɢɩɭ ɞɚɧɧɵɯ InterBase, ɡɚ ɢɫɤɥɸɱɟɧɢɟɦ ɦɚɫɫɢɜɨɜ. ȼɫɟ ɜɯɨɞɧɵɟ ɩɚɪɚɦɟɬɪɵ ɩɟɪɟɞɚɸɬɫɹ ɩɨ ɫɫɵɥɤɟ. ȼɨɡɜɪɚɳɚɟɦɵɟ ɡɧɚɱɟɧɢɹ ɩɟɪɟɞɚɸɬɫɹ ɥɢɛɨ ɩɨ ɫɫɵɥɤɟ (ɩɨ ɭɦɨɥɱɚɧɢɸ), ɥɢɛɨ ɩɨ ɡɧɚɱɟɧɢɸ. ȼ ɩɨɫɥɟɞɧɟɦ ɫɥɭɱɚɟ ɧɟɨɛɯɨɞɢɦɨ ɭɱɢɬɵɜɚɬɶ ɫɨɨɬɜɟɬɫɬɜɢɟ ɬɢɩɨɜ. Ɍɢɩ Interbase Integer Double precision Cstring Date
Ɍɢɩ Object Pascal Integer Double PChar type IBDateTime=record Days: integer; Msec: cardinal; end;
20
ɑɬɨɛɵ ɩɟɪɟɞɚɬɶ ɱɢɫɥɨɜɨɟ ɡɧɚɱɟɧɢɟ ɩɨ ɡɧɚɱɟɧɢɸ, ɫɥɟɞɭɟɬ ɩɪɢ ɨɛɴɹɜɥɟɧɢɢ UDF ɜ ȻȾ ɩɨɫɥɟ ɜɵɯɨɞɧɨɝɨ ɩɚɪɚɦɟɬɪɚ ɭɤɚɡɚɬɶ ɫɥɭɠɟɛɧɨɟ ɫɥɨɜɨ BY VALUE. ɉɨɫɥɟ ɬɨɝɨ ɤɚɤ ɮɭɧɤɰɢɢ ɨɬɤɨɦɩɢɥɢɪɨɜɚɧɵ ɜ ɛɢɛɥɢɨɬɟɤɭ, ɢɯ ɧɭɠɧɨ ɨɛɴɹɜɢɬɶ ɞɥɹ ɜɫɟɯ ȻȾ, ɜ ɤɨɬɨɪɵɯ ɩɥɚɧɢɪɭɟɬɫɹ ɟɟ ɢɫɩɨɥɶɡɨɜɚɧɢɟ. Ʉɚɠɞɭɸ ɮɭɧɤɰɢɸ ɬɪɟɛɭɟɬɫɹ ɨɛɴɹɜɥɹɬɶ ɨɬɞɟɥɶɧɨ, ɧɨ ɬɨɥɶɤɨ ɨɞɢɧ ɪɚɡ ɞɥɹ ɤɚɠɞɨɣ ȻȾ. Ɉɛɴɹɜɥɟɧɢɟ ɮɭɧɤɰɢɢ ɢɧɮɨɪɦɢɪɭɟɬ ȻȾ ɨ ɟɟ ɪɚɫɩɨɥɨɠɟɧɢɢ ɢ ɫɜɨɣɫɬɜɚɯ. ɋɢɧɬɚɤɫɢɫ ɨɛɴɹɜɥɟɧɢɹ: DECLARE EXTERNAL FUNCTION name [datatype | CSTRING(ɞɥɢɧɚ) [,datatype | CSTRING(ɞɥɢɧɚ)…]] RETURNS {datatype [BY VALUE] | CSTRING(ɞɥɢɧɚ)} [FREE_IT] ENTRY_POINT ‘entryname’ MODULE_NAME ‘modulename’; Name
ɂɦɹ UDF ɞɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɜ SQL-ɨɩɟɪɚɬɨɪɚɯ; ɦɨɠɟɬ ɨɬɥɢɱɚɬɶɫɹ ɨɬ ɢɦɟɧɢ, ɭɤɚɡɚɧɧɨɝɨ ɩɨɫɥɟ ENRT_POINT
Datatype RETURNS BY VALUE CSTRING (ɞɥɢɧɚ) FREE_IT
’ me’
Ɍɢɩ ɜɯɨɞɧɨɝɨ ɢɥɢ ɜɨɡɜɪɚɳɚɟɦɨɝɨ ɩɚɪɚɦɟɬɪɚ Ɉɩɪɟɞɟɥɹɟɬ ɜɨɡɜɪɚɳɚɟɦɨɟ ɮɭɧɤɰɢɟɣ ɡɧɚɱɟɧɢɟ Ɉɩɪɟɞɟɥɹɟɬ, ɱɬɨ ɜɨɡɜɪɚɳɚɟɦɵɣ ɪɟɡɭɥɶɬɚɬ ɞɨɥɠɟɧ ɩɟɪɟɞɚɜɚɬɶɫɹ ɩɨ ɡɧɚɱɟɧɢɸ ɍɤɚɡɵɜɚɟɬɫɹ ɞɥɹ ɩɚɪɚɦɟɬɪɨɜ ɫɬɪɨɤɨɜɨɝɨ ɬɢɩɚ
ɉɨɫɥɟ ɡɚɜɟɪɲɟɧɢɹ ɪɚɛɨɬɵ UDF ɨɫɜɨɛɨɠɞɚɟɬ ɩɚɦɹɬɶ, ɜɵɞɟɥɟɧɧɭɸ ɩɨɞ ɜɨɡɜɪɚɳɚɟɦɨɟ ɩɨ ɫɫɵɥɤɟ ɡɧɚɱɟɧɢɟ ‘entryname ɋɬɪɨɤɚ ɜ ɤɚɜɵɱɤɚɯ, ɨɩɪɟɞɟɥɹɸɳɚɹ ɢɦɹ ɮɭɧɤɰɢɢ ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ ɤɚɤ ɨɧɨ ɯɪɚɧɢɬɫɹ ɜ ɛɢɛɥɢɨɬɟɤɟ; ‘modulena Ɉɩɢɫɚɧɢɟ ɮɚɣɥɚ, ɢɞɟɧɬɢɮɢɰɢɪɭɸɳɟɟ ɛɢɛɥɢɨɬɟɤɭ, ɜ ɤɨɬɨɪɨɣ ɯɪɚɧɢɬɫɹ UDF
Ɂɚɦɟɱɚɧɢɟ. ɇɚɱɢɧɚɹ ɫ InterBase 6, UDF ɞɨɥɠɧɵ ɯɪɚɧɢɬɶɫɹ ɬɨɥɶɤɨ ɜ ɩɚɩɤɟ ..\InterBase\udf. Ʉɨɝɞɚ UDF ɫɨɡɞɚɧɚ ɢ ɨɛɴɹɜɥɟɧɚ ɜ ȻȾ, ɟɟ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɜ ɨɩɟɪɚɬɨɪɚɯ SQL, ɜ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪɚɯ ɢ ɬɪɢɝɝɟɪɚɯ. Ⱦɥɹ ɷɬɨɝɨ ɫɥɟɞɭɟɬ ɜɫɬɚɜɢɬɶ ɟɟ ɢɦɹ ɜ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɟ ɦɟɫɬɨ SQL-ɨɩɟɪɚɬɨɪɚ, ɡɚɤɥɸɱɢɜ ɜɯɨɞɧɵɟ ɩɚɪɚɦɟɬɪɵ ɜ ɤɪɭɝɥɵɟ ɫɤɨɛɤɢ. ɉɪɨɞɟɦɨɧɫɬɪɢɪɭɟɦ ɩɨɞɤɥɸɱɟɧɢɟ ɢ ɢɫɩɨɥɶɡɨɜɚɧɢɟ UDF ɧɚ ɩɪɢɦɟɪɟ ɛɢɛɥɢɨɬɟɤɢ caseudf.dll (ɚɜɬɨɪ – Ⱦ. Ʉɭɡɶɦɟɧɤɨ, ɫɨɡɞɚɬɟɥɶ ɫɚɣɬɚ ibase.ru). ɉɨɫɦɨɬɪɢɦ ɢɫɯɨɞɧɵɣ ɬɟɤɫɬ ɛɢɛɥɢɨɬɟɤɢ. Ʉɚɤ ɜɢɞɢɦ, ɷɬɨ ɨɛɵɱɧɚɹ DLL, ɧɚɩɢɫɚɧɧɚɹ ɧɚ Delphi. library caseudf; { Copyright Dmitry Kuzmenko, Epsylon Technologies } { e-mail:
[email protected], web: http://ib.demo.ru }
21
{ ɜɨɨɛɳɟ ɨ ɤɨɩɢɪɚɣɬɟ ɧɚ ɬɚɤɢɟ ɮɭɧɤɰɢɢ ɝɨɜɨɪɢɬɶ } { ɫɦɟɲɧɨ, ɬɚɤ ɱɬɨ ɩɨɥɶɡɭɣɬɟɫɶ ɧɚ ɡɞɨɪɨɜɶɟ } uses Windows, SysUtils; function UpCase(CStr: PChar): PChar; cdecl; export; begin CharUpperBuff(CStr, Length(CStr)); Result:=CStr; end; { ɞɪɭɝɢɟ ɮɭɧɤɰɢɢ, ɚ ɬɚɤɠɟ ɤɨɦɦɟɧɬɚɪɢɢ ɢ ɢɧɫɬɪɭɤɰɢɢ ɚɜɬɨɪɚ ɞɥɹ ɤɪɚɬɤɨɫɬɢ ɨɩɭɳɟɧɵ } exports UpCase; begin isMultiThread:=True; end.
ȼ DataBase Explorer ɜɵɛɟɪɟɦ ɩɭɧɤɬ UDFs – New ɢ ɡɚɩɨɥɧɢɦ ɨɬɤɪɵɜɲɭɸɫɹ ɮɨɪɦɭ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ (ɪɢɫ. 1.21) ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɟɟ ɨɛɴɹɜɥɟɧɢɟɦ ɜ DLL. ɋɝɟɧɟɪɢɪɨɜɚɧɧɨɟ ɨɛɴɹɜɥɟɧɢɟ UDF ɧɚ SQL, ɡɚɩɢɫɚɧɧɨɟ ɧɚ ɜɤɥɚɞɤɟ DDL, ɛɭɞɟɬ ɢɦɟɬɶ ɜɢɞ: DECLARE EXTERNAL FUNCTION UPCASE CSTRING(255) RETURNS CSTRING(255) ENTRY_POINT 'UpCase' MODULE_NAME 'CASEUDF.DLL'
Ɉɛɵɱɧɨ ɚɜɬɨɪɵ UDF ɧɟ ɩɪɢɥɚɝɚɸɬ ɤ ɮɚɣɥɭ *.dll ɢɫɯɨɞɧɵɣ ɤɨɞ, ɚ ɩɪɟɞɨɫɬɚɜɥɹɸɬ ɬɨɥɶɤɨ ɜɵɲɟɩɪɢɜɟɞɟɧɧɵɣ SQL-ɨɩɟɪɚɬɨɪ, ɱɬɨ ɜɩɨɥɧɟ ɞɨɫɬɚɬɨɱɧɨ.
Ɋɢɫ. 1.21. 2. ɋɟɪɜɟɪɧɚɹ ɱɚɫɬɶ ɩɪɢɥɨɠɟɧɢɹ 2.1. ɉɪɨɟɤɬɢɪɨɜɚɧɢɟ ɩɪɢɥɨɠɟɧɢɣ ɋɨɜɪɟɦɟɧɧɵɟ ɫɪɟɞɫɬɜɚ ɜɢɡɭɚɥɶɧɨɣ ɪɚɡɪɚɛɨɬɤɢ (Delphi, Visual Studio .Net) ɩɪɟɞɨɫɬɚɜɥɹɸɬ ɛɨɥɶɲɨɟ ɤɨɥɢɱɟɫɬɜɨ ɪɚɡɧɨɨɛɪɚɡɧɵɯ ɢɧɫɬɪɭɦɟɧɬɨɜ 22
ɞɥɹ ɧɚɩɢɫɚɧɢɹ ɩɪɨɝɪɚɦɦ, ɨɛɪɚɳɚɸɳɢɯɫɹ ɤ ɛɚɡɚɦ ɞɚɧɧɵɯ. Ɉɞɧɚ ɢ ɬɚ ɠɟ ɡɚɞɚɱɚ ɦɨɠɟɬ ɛɵɬɶ ɪɟɲɟɧɚ ɪɚɡɥɢɱɧɵɦɢ ɫɩɨɫɨɛɚɦɢ: ɫ ɩɪɢɦɟɧɟɧɢɟɦ ɤɨɧɰɟɩɰɢɢ «ɧɚɛɨɪ ɞɚɧɧɵɯ» (DataSet) ɜ ɤɥɢɟɧɬɫɤɨɦ ɩɪɢɥɨɠɟɧɢɢ, ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɵɦ ɜɵɡɨɜɨɦ SQL-ɡɚɩɪɨɫɨɜ ɢɡ ɤɥɢɟɧɬɚ, ɫɪɟɞɫɬɜɚɦɢ ɜɯɨɞɧɨɝɨ ɹɡɵɤɚ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɢ ɋɍȻȾ ɢ ɞɪ. Ɉɫɧɨɜɧɵɦ ɤɪɢɬɟɪɢɟɦ ɜɵɛɨɪɚ ɹɜɥɹɟɬɫɹ ɷɮɮɟɤɬɢɜɧɨɫɬɶ (ɧɚɞɟɠɧɨɫɬɶ, ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɶ) ɜ ɤɨɧɤɪɟɬɧɵɯ ɭɫɥɨɜɢɹɯ. ȼ ɥɸɛɨɦ ɫɥɭɱɚɟ ɩɪɢɥɨɠɟɧɢɟ ɛɭɞɟɬ ɫɨɫɬɨɹɬɶ ɢɡ ɫɟɪɜɟɪɧɨɣ ɢ ɤɥɢɟɧɬɫɤɨɣ ɱɚɫɬɢ, ɩɪɢɱɟɦ ɢɡ ɫɨɨɛɪɚɠɟɧɢɣ ɷɮɮɟɤɬɢɜɧɨɫɬɢ ɩɪɢɨɪɢɬɟɬ, ɤɚɤ ɩɪɚɜɢɥɨ, ɨɬɞɚɟɬɫɹ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɢ, ɧɚɢɛɨɥɟɟ ɩɨɥɧɨ ɭɱɢɬɵɜɚɸɳɟɣ ɨɫɨɛɟɧɧɨɫɬɢ ɤɨɧɤɪɟɬɧɨɣ ɋɍȻȾ. ɉɨɷɬɨɦɭ, ɧɟɫɦɨɬɪɹ ɧɚ ɜɧɟɲɧɸɸ ɫɯɨɠɟɫɬɶ, ɩɪɢɥɨɠɟɧɢɹ ɞɥɹ ɫɪɟɞɵ ɤɥɢɟɧɬ-ɫɟɪɜɟɪ ɫɭɳɟɫɬɜɟɧɧɨ ɨɬɥɢɱɚɸɬɫɹ ɨɬ ɩɪɢɥɨɠɟɧɢɣ ɞɥɹ ɥɨɤɚɥɶɧɵɯ ɛɚɡ ɞɚɧɧɵɯ. ɂɯ ɧɟɨɛɯɨɞɢɦɵɦɢ ɱɟɪɬɚɦɢ ɹɜɥɹɸɬɫɹ ɪɚɰɢɨɧɚɥɶɧɨɟ ɪɚɫɩɪɟɞɟɥɟɧɢɟ ɮɭɧɤɰɢɣ ɦɟɠɞɭ ɤɥɢɟɧɬɫɤɨɣ ɢ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɹɦɢ ɢ ɩɪɨɞɭɦɚɧɧɚɹ ɨɪɝɚɧɢɡɚɰɢɹ ɬɪɚɧɡɚɤɰɢɣ (ɪɚɡɞɟɥ 3) ɫ ɭɱɟɬɨɦ ɨɫɨɛɟɧɧɨɫɬɟɣ ɢɫɩɨɥɶɡɭɟɦɨɝɨ ɫɟɪɜɟɪɚ ɛɚɡɵ ɞɚɧɧɵɯ. Ȼɟɡ ɷɬɨɝɨ ɨɞɧɨɜɪɟɦɟɧɧɚɹ ɪɚɛɨɬɚ ɞɟɫɹɬɤɨɜ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɛɟɡ ɡɚɞɟɪɠɟɤ ɢ ɫɛɨɟɜ ɧɟɜɨɡɦɨɠɧɚ. ɉɪɨɝɪɚɦɦɚ, «ɦɟɯɚɧɢɱɟɫɤɢ» ɩɟɪɟɧɟɫɟɧɧɚɹ ɩɪɨɝɪɚɦɦɢɫɬɨɦ ɢɡ ɨɞɧɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɣ ɫɪɟɞɵ ɜ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɭɸ, ɦɨɠɟɬ ɨɤɚɡɚɬɶɫɹ ɩɨɫɥɟɞɧɟɣ ɜ ɟɝɨ ɩɪɨɮɟɫɫɢɨɧɚɥɶɧɨɣ ɤɚɪɶɟɪɟ. ɇɟ ɫɥɟɞɭɟɬ ɬɚɤɠɟ ɫɥɢɲɤɨɦ ɭɜɥɟɤɚɬɶɫɹ ɧɨɪɦɚɥɢɡɚɰɢɟɣ ɛɚɡɵ ɞɚɧɧɵɯ. ɇɨɪɦɚɥɢɡɚɰɢɹ ɫɩɨɫɨɛɫɬɜɭɟɬ ɰɟɥɨɫɬɧɨɫɬɢ ȻȾ, ɢɫɤɥɸɱɚɟɬ ɢɡ ɬɚɛɥɢɰ ɢɡɛɵɬɨɱɧɭɸ ɢɧɮɨɪɦɚɰɢɸ ɢ ɫɨɤɪɚɳɚɟɬ ɪɚɡɦɟɪ ȻȾ. ɉɨɛɨɱɧɵɣ ɷɮɮɟɤɬ – ɡɚɦɟɞɥɟɧɢɟ ɪɚɛɨɬɵ ɩɪɢ ɞɨɫɬɭɩɟ ɤ ɦɧɨɠɟɫɬɜɭ ɧɟɛɨɥɶɲɢɯ ɬɚɛɥɢɰ – ɜ ɤɥɢɟɧɬɫɟɪɜɟɪɧɨɣ ɫɪɟɞɟ ɦɨɠɟɬ ɨɤɚɡɚɬɶɫɹ ɛɨɥɟɟ ɡɧɚɱɢɦɵɦ. Ɏɭɧɤɰɢɢ ɤɥɢɟɧɬɫɤɨɣ ɢ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɢ ɩɪɢɥɨɠɟɧɢɹ ɦɨɠɧɨ ɪɚɫɩɪɟɞɟɥɢɬɶ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫɨ ɫɥɟɞɭɸɳɟɣ ɬɚɛɥɢɰɟɣ. Ⱦɟɣɫɬɜɢɟ
ɂɧɫɬɪɭɦɟɧɬ
Ɂɚɩɨɥɧɟɧɢɟ ɫɭɪɪɨɝɚɬɧɵɯ ɩɟɪɜɢɱɧɵɯ Ƚɟɧɟɪɚɬɨɪɵ ɤɥɸɱɟɣ ɉɨɞɞɟɪɠɤɚ ɫɫɵɥɨɱɧɨɣ ɰɟɥɨɫɬɧɨɫɬɢ Ɍɪɢɝɝɟɪɵ ɢɥɢ ɨɝɪɚɧɢɱɟɧɢɹ ɧɚ ɬɚɛɥɢɰɵ ȼɟɞɟɧɢɟ ɫɬɚɬɢɫɬɢɤɢ Ɍɪɢɝɝɟɪɵ Ȼɢɡɧɟɫ-ɩɪɚɜɢɥɚ, ɫɜɹɡɚɧɧɵɟ ɫ ɢɡɦɟɧɟɧɢɟɦ Ɍɪɢɝɝɟɪɵ ɢɥɢ ɧɟɫɤɨɥɶɤɢɯ ɬɚɛɥɢɰ ɜ ɪɚɦɤɚɯ ɨɞɧɨɣ ɬɪɚɧ- ɯɪɚɧɢɦɵɟ ɩɪɨɡɚɤɰɢɢ ɰɟɞɭɪɵ Ɉɝɪɚɧɢɱɟɧɢɹ ɧɚ ɡɧɚɱɟɧɢɹ ɜɜɨɞɢɦɵɯ ɞɚɧ- Ɉɝɪɚɧɢɱɟɧɢɟ ɧɵɯ CHECK ɩɪɢ ɫɨɡɞɚɧɢɢ ɬɚɛɥɢɰ Ɂɚɩɪɨɫɵ, ɜɤɥɸɱɚɸɳɢɟ ɫɥɨɠɧɵɟ ɚɥɝɨɪɢɬ- ɏɪɚɧɢɦɵɟ ɩɪɨɦɵ ɫ ɰɢɤɥɚɦɢ ɢ ɜɟɬɜɥɟɧɢɟɦ ɰɟɞɭɪɵ 23
ɑɚɫɬɨ ɢɫɩɨɥɶɡɭɟɦɵɟ ɜ SQL-ɨɩɟɪɚɬɨɪɚɯ ɮɭɧɤɰɢɢ ȼɵɛɨɪɤɢ ɢɡ ɧɟɫɤɨɥɶɤɢɯ ɫɜɹɡɚɧɧɵɯ ɬɚɛɥɢɰ, ɩɨɥɭɱɟɧɧɵɯ ɜ ɪɟɡɭɥɶɬɚɬɟ ɧɨɪɦɚɥɢɡɚɰɢɢ ɂɧɬɟɪɮɟɣɫ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ ɢ ɢɧɬɟɪɩɪɟɬɚɰɢɹ ɪɟɡɭɥɶɬɚɬɨɜ ɡɚɩɪɨɫɨɜ
UDF, ɜɵɩɨɥɧɹɸɳɢɟɫɹ ɧɚ ɫɟɪɜɟɪɟ ɉɪɟɞɫɬɚɜɥɟɧɢɹ Ʉɥɢɟɧɬɫɤɨɟ ɩɪɢɥɨɠɟɧɢɟ
2.2. Ƚɟɧɟɪɚɬɨɪɵ Ƚɟɧɟɪɚɬɨɪ – ɷɬɨ ɯɪɚɧɢɦɵɣ ɧɚ ɫɟɪɜɟɪɟ ɦɟɯɚɧɢɡɦ, ɤɨɬɨɪɵɣ ɫɨɡɞɚɟɬ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɵɣ ɭɧɢɤɚɥɶɧɵɣ ɧɨɦɟɪ. Ƚɟɧɟɪɚɬɨɪ ɨɛɵɱɧɨ ɩɪɢɦɟɧɹɟɬɫɹ ɞɥɹ ɫɨɡɞɚɧɢɹ ɭɧɢɤɚɥɶɧɵɯ ɡɧɚɱɟɧɢɣ, ɜɫɬɚɜɥɹɟɦɵɯ ɜ ɫɬɨɥɛɟɰ, ɢɫɩɨɥɶɡɭɟɦɵɣ ɤɚɤ PRIMARY KEY. Ⱦɥɹ ɛɚɡɵ ɞɚɧɧɵɯ ɦɨɠɟɬ ɛɵɬɶ ɨɩɪɟɞɟɥɟɧɨ ɥɸɛɨɟ ɱɢɫɥɨ ɝɟɧɟɪɚɬɨɪɨɜ, ɤɚɠɞɵɣ ɝɟɧɟɪɚɬɨɪ ɞɨɥɠɟɧ ɢɦɟɬɶ ɭɧɢɤɚɥɶɧɨɟ ɢɦɹ. Ƚɟɧɟɪɚɬɨɪ ɩɪɢ ɨɛɪɚɳɟɧɢɢ ɤ ɧɟɦɭ ɜɨɡɜɪɚɳɚɟɬ ɧɨɜɨɟ ɭɧɢɤɚɥɶɧɨɟ ɡɧɚɱɟɧɢɟ. ɋɨɡɞɚɧɢɟ ɝɟɧɟɪɚɬɨɪɚ: CREATE GENERATOR ɂɦɹȽɟɧɟɪɚɬɨɪɚ;
ɍɫɬɚɧɨɜɤɚ ɧɚɱɚɥɶɧɨɝɨ ɡɧɚɱɟɧɢɹ: SET GENERATOR ɂɦɹȽɟɧɟɪɚɬɨɪɚ TO ɇɚɱɁɧɚɱɟɧɢɟ;
Ⱦɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɝɟɧɟɪɚɬɨɪɭ ɫɥɭɠɢɬ ɮɭɧɤɰɢɹ: GEN_ID (ɂɦɹȽɟɧɟɪɚɬɨɪɚ, ɉɪɢɪɚɳɟɧɢɟ);
Ɇɟɯɚɧɢɡɦ ɝɟɧɟɪɚɬɨɪɨɜ ɝɚɪɚɧɬɢɪɭɟɬ, ɱɬɨ ɞɚɠɟ ɩɪɢ ɤɨɧɤɭɪɟɧɬɧɨɦ (ɩɚɪɚɥɥɟɥɶɧɨɦ) ɜɵɡɨɜɟ ɮɭɧɤɰɢɢ GEN_ID ɤɚɠɞɨɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɛɭɞɟɬ ɜɵɞɚɜɚɬɶɫɹ ɭɧɢɤɚɥɶɧɨɟ ɡɧɚɱɟɧɢɟ. ɉɨɫɥɟɞɧɟɟ ɡɧɚɱɟɧɢɟ ɝɟɧɟɪɚɬɨɪɚ ɜɫɟɝɞɚ ɡɚɩɨɦɢɧɚɟɬɫɹ ɜ ȻȾ, ɩɨɷɬɨɦɭ ɪɚɡɪɚɛɨɬɱɢɤɭ ɧɟ ɧɭɠɧɨ ɡɚɛɨɬɢɬɶɫɹ ɨ «ɜɨɫɫɬɚɧɨɜɥɟɧɢɢ» ɟɝɨ ɦɚɤɫɢɦɚɥɶɧɨɝɨ ɡɧɚɱɟɧɢɹ ɩɨɫɥɟ ɩɨɞɫɨɟɞɢɧɟɧɢɹ ɤ ȻȾ. Ɂɧɚɱɟɧɢɹ, ɜɵɞɚɜɚɟɦɵɟ ɝɟɧɟɪɚɬɨɪɚɦɢ, ɨɬɧɨɫɹɬɫɹ ɤ ɰɟɥɨɦɭ ɬɢɩɭ. ɋɩɨɫɨɛɵ ɨɛɪɚɳɟɧɢɹ ɤ ɝɟɧɟɪɚɬɨɪɭ. 1. ɋ ɩɨɦɨɳɶɸ ɬɪɢɝɝɟɪɚ ɧɚ ɜɫɬɚɜɤɭ (ɩ. 2.4). Ƚɟɧɟɪɚɬɨɪ ɜɵɡɵɜɚɟɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ. ȼ ɨɩɟɪɚɬɨɪɟ INSERT ɤɥɸɱɟɜɨɟ ɩɨɥɟ, ɞɥɹ ɤɨɬɨɪɨɝɨ ɩɨɫɬɪɨɟɧ ɝɟɧɟɪɚɬɨɪ, ɞɨɥɠɧɨ ɛɵɬɶ ɨɩɭɳɟɧɨ: INSERT INTO customers(CustName, Address) VALUES (’ɂɜɚɧɨɜ’, ’Ɇɨɫɤɜɚ’)
2. əɜɧɵɦ ɨɛɪɚɡɨɦ: INSERT INTO customers(CustID, CustName, Address) VALUES (GEN_ID(G1,1),’ɂɜɚɧɨɜ’, ’Ɇɨɫɤɜɚ’)
Ɂɞɟɫɶ G1 – ɢɦɹ ɪɚɧɟɟ ɫɨɡɞɚɧɧɨɝɨ ɝɟɧɟɪɚɬɨɪɚ. 24
ɉɟɪɜɵɣ ɫɩɨɫɨɛ ɜɨ ɦɧɨɝɢɯ ɫɥɭɱɚɹɯ ɩɪɟɞɩɨɱɬɢɬɟɥɟɧ, ɬɚɤ ɤɚɤ ɬɪɢɝɝɟɪ ɜɵɩɨɥɧɹɟɬɫɹ ɜɫɟɝɞɚ, ɧɟɡɚɜɢɫɢɦɨ ɨɬ ɬɨɝɨ, ɤɚɤ ɩɪɨɢɫɯɨɞɢɬ ɜɫɬɚɜɤɚ ɧɨɜɨɣ ɡɚɩɢɫɢ – ɢɡ IBExpert, ɤɥɢɟɧɬɫɤɨɝɨ ɩɪɢɥɨɠɟɧɢɹ ɧɚ Delphi, Web-ɩɪɢɥɨɠɟɧɢɣ ɢ ɬ.ɩ. ɇɨ ɟɫɥɢ ɩɥɚɧɢɪɭɟɬɫɹ ɞɨɫɬɭɩ ɤ ɞɚɧɧɵɦ ɬɨɥɶɤɨ ɢɡ ɤɥɢɟɧɬɫɤɨɝɨ ɩɪɢɥɨɠɟɧɢɹ, ɬɨ ɥɭɱɲɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɜɬɨɪɨɣ ɫɩɨɫɨɛ, ɬɚɤ ɤɚɤ ɡɧɚɱɟɧɢɟ ɩɟɪɜɢɱɧɨɝɨ ɤɥɸɱɚ ɛɭɞɟɬ ɢɡɜɟɫɬɧɨ ɤɥɢɟɧɬɭ ɢ ɧɟ ɩɨɧɚɞɨɛɢɬɫɹ ɬɪɭɞɨɟɦɤɨɝɨ ɩɟɪɟɨɬɤɪɵɬɢɹ ɧɚɛɨɪɚ ɞɚɧɧɵɯ. 2.3. ɏɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ɏɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ (Stored Procedures) – ɷɬɨ ɨɬɞɟɥɶɧɵɟ ɩɪɨɝɪɚɦɦɵ, ɧɚɩɢɫɚɧɧɵɟ ɧɚ ɹɡɵɤɟ ɩɪɨɰɟɞɭɪ ɢ ɬɪɢɝɝɟɪɨɜ InterBase, ɤɨɬɨɪɵɣ ɹɜɥɹɟɬɫɹ ɪɚɫɲɢɪɟɧɢɟɦ SQL. ɏɪɚɧɢɦɚɹ ɩɪɨɰɟɞɭɪɚ ɧɚɯɨɞɢɬɫɹ ɜ ȻȾ ɧɚ ɫɟɪɜɟɪɟ ɢ ɜɵɡɵɜɚɟɬɫɹ ɢɡ ɩɪɢɥɨɠɟɧɢɣ, ɩɨɥɭɱɚɹ ɜɯɨɞɧɵɟ ɩɚɪɚɦɟɬɪɵ ɢ ɜɨɡɜɪɚɳɚɹ ɩɨɥɭɱɟɧɧɵɟ ɪɟɡɭɥɶɬɚɬɵ. Ɋɟɚɥɢɡɚɰɢɹ ɚɥɝɨɪɢɬɦɨɜ ɫ ɩɨɦɨɳɶɸ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ ɢɦɟɟɬ ɫɥɟɞɭɸɳɢɟ ɩɪɟɢɦɭɳɟɫɬɜɚ ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ ɪɟɚɥɢɡɚɰɢɟɣ ɧɚ ɫɬɨɪɨɧɟ ɤɥɢɟɧɬɚ. x Ɇɨɞɭɥɶɧɨɫɬɶ: ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ɦɨɝɭɬ ɛɵɬɶ ɨɛɳɢɦɢ ɞɥɹ ɜɫɟɯ ɩɪɢɥɨɠɟɧɢɣ, ɤɨɬɨɪɵɟ ɨɛɪɚɳɚɸɬɫɹ ɤ ɬɨɣ ɠɟ ɫɚɦɨɣ ɛɚɡɟ ɞɚɧɧɵɯ, ɱɬɨ ɩɨɡɜɨɥɹɟɬ ɢɡɛɟɝɚɬɶ ɩɨɜɬɨɪɹɸɳɟɝɨɫɹ ɤɨɞɚ ɢ ɭɦɟɧɶɲɚɟɬ ɪɚɡɦɟɪ ɩɪɢɥɨɠɟɧɢɣ. ɉɪɢ ɢɫɩɪɚɜɥɟɧɢɢ ɨɲɢɛɨɤ ɢɥɢ ɦɨɞɢɮɢɤɚɰɢɢ ɩɪɨɰɟɞɭɪ ɢɡɦɟɧɟɧɢɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɨɬɪɚɠɚɸɬɫɹ ɜɨ ɜɫɟɯ ɢɫɩɨɥɶɡɭɸɳɢɯ ɢɯ ɩɪɢɥɨɠɟɧɢɹɯ; ɩɟɪɟɤɨɦɩɢɥɹɰɢɹ ɤɥɢɟɧɬɫɤɢɯ ɩɪɢɥɨɠɟɧɢɣ ɧɟ ɬɪɟɛɭɟɬɫɹ. x ɍɥɭɱɲɟɧɢɟ ɷɮɮɟɤɬɢɜɧɨɫɬɢ ɢ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɢ. ɏɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ɜɵɩɨɥɧɹɸɬɫɹ ɫɟɪɜɟɪɨɦ, ɚ ɧɟ ɤɥɢɟɧɬɨɦ, ɱɬɨ ɜɨ ɦɧɨɝɢɯ ɫɥɭɱɚɹɯ ɫɧɢɠɚɟɬ ɫɟɬɟɜɨɣ ɬɪɚɮɢɤ. SQL-ɡɚɩɪɨɫɵ ɹɜɥɹɸɬɫɹ ɨɬɤɨɦɩɢɥɢɪɨɜɚɧɧɵɦɢ, ɩɨɷɬɨɦɭ ɩɨɜɬɨɪɧɚɹ ɩɨɞɝɨɬɨɜɤɚ ɢɯ ɤ ɜɵɩɨɥɧɟɧɢɸ ɫɟɪɜɟɪɨɦ ɧɟ ɩɪɨɢɡɜɨɞɢɬɫɹ. x ɇɚɞɟɠɧɨɫɬɶ ɢ ɛɟɡɨɩɚɫɧɨɫɬɶ. ȼ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪɚɯ ɧɚɯɨɞɹɬɫɹ ɨɬɥɚɠɟɧɧɵɟ ɡɚɩɪɨɫɵ, «ɢɫɩɨɪɬɢɬɶ» ɤɨɬɨɪɵɟ ɩɨɥɶɡɨɜɚɬɟɥɶ ɧɟ ɜ ɫɨɫɬɨɹɧɢɢ. Ɍɟɤɫɬ ɡɚɩɪɨɫɚ, ɧɚɡɜɚɧɢɹ ɬɚɛɥɢɰ ɢ ɩɨɥɟɣ ɫɤɪɵɬɵ ɨɬ ɡɥɨɭɦɵɲɥɟɧɧɢɤɚ. ɏɚɤɟɪɫɤɚɹ ɚɬɚɤɚ, ɢɡɜɟɫɬɧɚɹ ɩɨɞ ɧɚɡɜɚɧɢɟɦ «ɢɧɴɟɤɰɢɹ SQLɤɨɞɚ» [3], ɬɚɤɠɟ ɡɚɬɪɭɞɧɟɧɚ ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɞɢɧɚɦɢɱɟɫɤɨɝɨ SQL ɜ ɤɥɢɟɧɬɟ. Ɏɨɪɦɚɬ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ: CREATE PROCEDURE ɂɦɹɉɪɨɰ [(ȼɯɉɚɪ Ɍɢɩ [,ȼɯɉɚɪ Ɍɢɩ] …)] RETURNS [(ȼɵɯɉɚɪ Ɍɢɩ [,ȼɵɯɉɚɪ Ɍɢɩ] …)] AS <Ɍɟɥɨ ɩɪɨɰɟɞɭɪɵ>
ɉɪɢɥɨɠɟɧɢɟ ɨɛɦɟɧɢɜɚɟɬɫɹ ɢɧɮɨɪɦɚɰɢɟɣ ɫ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɨɣ ɱɟɪɟɡ ɫɩɢɫɨɤ ɜɯɨɞɧɵɯ ɢ ɜɵɯɨɞɧɵɯ ɩɚɪɚɦɟɬɪɨɜ. ȼɨɡɦɨɠɧɵɟ ɬɢɩɵ ɩɚɪɚɦɟɬɪɨɜ ɫɦ. ɜ ɩɪɢɥɨɠɟɧɢɢ. 25
Ɍɟɥɨ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ ɢɦɟɟɬ ɜɢɞ <Ɉɛɴɹɜɥɟɧɢɹ ɥɨɤɚɥɶɧɵɯ ɩɟɪɟɦɟɧɧɵɯ> BEGIN <Ɉɩɟɪɚɬɨɪ> … <Ɉɩɟɪɚɬɨɪ> END
ȿɫɥɢ ɜ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɟ ɢɫɩɨɥɶɡɭɸɬɫɹ ɥɨɤɚɥɶɧɵɟ ɩɟɪɟɦɟɧɧɵɟ, ɬɨ ɜɫɟ ɨɧɢ ɞɨɥɠɧɵ ɛɵɬɶ ɨɛɴɹɜɥɟɧɵ: DECLARE VARIABLE ɂɦɹɉɟɪɟɦɟɧɧɨɣ Ɍɢɩ;
Ʉɚɠɞɚɹ ɥɨɤɚɥɶɧɚɹ ɩɟɪɟɦɟɧɧɚɹ ɨɛɴɹɜɥɹɟɬɫɹ ɨɬɞɟɥɶɧɵɦ ɨɩɟɪɚɬɨɪɨɦ. ɉɪɢ ɧɚɩɢɫɚɧɢɢ ɬɟɥɚ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ ɦɨɝɭɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ: x ɨɩɟɪɚɬɨɪ ɩɪɢɫɜɚɢɜɚɧɢɹ ɂɦɹɉɟɪɟɦɟɧɧɨɣ = ɜɵɪɚɠɟɧɢɟ, x ɨɩɟɪɚɬɨɪɧɵɟ ɫɤɨɛɤɢ BEGIN … END, x ɭɫɥɨɜɧɵɣ ɨɩɟɪɚɬɨɪ IF(<ɭɫɥɨɜɢɟ>)THEN <ɨɩɟɪɚɬɨɪ1> ELSE <ɨɩɟɪɚɬɨɪ2>,
x
ɨɩɟɪɚɬɨɪ ɰɢɤɥɚ
WHILE (<ɭɫɥɨɜɢɟ>) DO <ɨɩɟɪɚɬɨɪ>
ɢ ɧɟɤɨɬɨɪɵɟ ɞɪɭɝɢɟ [1]. ɏɪɚɧɢɦɚɹ ɩɪɨɰɟɞɭɪɚ ɦɨɠɟɬ ɫɨɞɟɪɠɚɬɶ ɨɩɟɪɚɬɨɪɵ ɹɡɵɤɚ SQL. InterBase ɧɟ ɪɚɡɪɟɲɚɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɜ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪɚɯ ɨɩɟɪɚɬɨɪɵ ɨɩɪɟɞɟɥɟɧɢɹ ɞɚɧɧɵɯ DDL, ɨɩɟɪɚɬɨɪɵ ɭɩɪɚɜɥɟɧɢɹ ɬɪɚɧɡɚɤɰɢɹɦɢ ɢ ɤɭɪɫɨɪɵ. Ɉɩɟɪɚɬɨɪ SELECT ɢɫɩɨɥɶɡɭɟɬɫɹ ɜ ɪɚɫɲɢɪɟɧɧɨɣ ɪɟɞɚɤɰɢɢ. ȼ ɧɟɝɨ ɞɨɛɚɜɥɹɟɬɫɹ ɩɪɟɞɥɨɠɟɧɢɟ INTO :ɩɟɪɟɦɟɧɧɚɹ [, :ɩɟɪɟɦɟɧɧɚɹ]. ȼ ɩɟɪɟɱɢɫɥɟɧɧɵɟ ɩɟɪɟɦɟɧɧɵɟ ɛɭɞɭɬ ɡɚɩɢɫɚɧɵ ɡɧɚɱɟɧɢɹ, ɜɨɡɜɪɚɳɚɟɦɵɟ ɨɩɟɪɚɬɨɪɨɦ SELECT. ȼ ɤɚɱɟɫɬɜɟ ɩɟɪɟɦɟɧɧɵɯ ɦɨɝɭɬ ɜɵɫɬɭɩɚɬɶ ɥɨɤɚɥɶɧɵɟ ɩɟɪɟɦɟɧɧɵɟ ɢ ɜɵɯɨɞɧɵɟ ɩɚɪɚɦɟɬɪɵ. ɉɟɪɟɦɟɧɧɵɟ ɢ ɩɚɪɚɦɟɬɪɵ ɜɧɭɬɪɢ ɨɩɟɪɚɬɨɪɨɜ SQL ɩɪɟɞɜɚɪɹɸɬɫɹ ɞɜɨɟɬɨɱɢɟɦ. ɏɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ɦɨɝɭɬ ɧɟ ɜɨɡɜɪɚɳɚɬɶ ɩɚɪɚɦɟɬɪɨɜ, ɜɨɡɜɪɚɳɚɬɶ ɨɞɢɧ ɷɤɡɟɦɩɥɹɪ ɩɚɪɚɦɟɬɪɨɜ (ɟɫɥɢ ɩɚɪɚɦɟɬɪ ɩɨɥɭɱɟɧ ɜ ɪɟɡɭɥɶɬɚɬɟ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɬɨɪɚ SELECT, ɜɨɡɜɪɚɳɚɸɳɟɝɨ ɨɞɧɭ ɫɬɪɨɤɭ) ɢɥɢ ɧɟɫɤɨɥɶɤɨ ɷɤɡɟɦɩɥɹɪɨɜ ɩɚɪɚɦɟɬɪɨɜ ɫɬɪɨɤ (ɟɫɥɢ SELECT ɜɨɡɜɪɚɳɚɟɬ ɧɟɫɤɨɥɶɤɨ ɫɬɪɨɤ). ȿɫɥɢ ɜ ɫɩɢɫɤɟ RETURNS [(ȼɵɯɉɚɪ Ɍɢɩ [,ȼɵɯɉɚɪ Ɍɢɩ] …)] ɢɦɟɸɬɫɹ ɜɵɯɨɞɧɵɟ ɩɚɪɚɦɟɬɪɵ, ɬɨ ɜ ɬɟɥɟ ɩɪɨɰɟɞɭɪɵ ɨɛɹɡɚɬɟɥɶɧɨ ɞɨɥɠɟɧ ɩɪɢɫɭɬɫɬɜɨɜɚɬɶ ɨɩɟɪɚɬɨɪ SUSPEND. Ɉɩɟɪɚɬɨɪ SUSPEND ɩɟɪɟɞɚɟɬ ɡɧɚɱɟɧɢɹ ɜɵɯɨɞɧɵɯ ɩɚɪɚɦɟɬɪɨɜ ɜɵɡɵɜɚɸɳɟɦɭ ɩɪɢɥɨɠɟɧɢɸ ɢ ɩɪɢɨɫɬɚɧɚɜɥɢɜɚɟɬ ɪɚɛɨɬɭ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ, ɩɨɤɚ ɩɪɢɥɨɠɟɧɢɟ ɧɟ ɡɚɩɪɨɫɢɬ ɫɥɟɞɭɸɳɭɸ ɩɨɪɰɢɸ ɩɚɪɚɦɟɬɪɨɜ. ȿɫɥɢ ɨɩɟɪɚɬɨɪ SUSPEND ɧɟ ɭɤɚɡɚɬɶ, ɬɨ ɡɧɚɱɟɧɢɹ ɩɚɪɚɦɟɬɪɨɜ ɜ ɜɵɡɵɜɚɸɳɭɸ ɩɪɨɝɪɚɦɦɭ ɩɟɪɟɞɚɧɵ ɧɟ ɛɭɞɭɬ! 26
ȼ ɩɪɨɰɟɞɭɪɚɯ, ɜɨɡɜɪɚɳɚɸɳɢɯ ɧɟɫɤɨɥɶɤɨ ɫɬɪɨɤ, ɨɛɵɱɧɨ ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɨɧɫɬɪɭɤɰɢɹ FOR <ɨɩɟɪɚɬɨɪ SELECT> DO SUSPEND;
Ɂɞɟɫɶ ɨɩɟɪɚɬɨɪ SUSPEND ɜɵɩɨɥɧɹɟɬɫɹ ɞɥɹ ɤɚɠɞɨɣ ɫɬɪɨɤɢ, ɜɨɡɜɪɚɳɟɧɧɨɣ ɨɩɟɪɚɬɨɪɨɦ SELECT. Ɉɩɟɪɚɬɨɪ SUSPEND ɩɟɪɟɞɚɟɬ ɡɧɚɱɟɧɢɹ ɜɵɯɨɞɧɵɯ ɩɚɪɚɦɟɬɪɨɜ ɜɵɡɵɜɚɸɳɟɦɭ ɩɪɢɥɨɠɟɧɢɸ ɢ ɩɪɢɨɫɬɚɧɚɜɥɢɜɚɟɬ ɪɚɛɨɬɭ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ, ɩɨɤɚ ɩɪɢɥɨɠɟɧɢɟ ɧɟ ɡɚɩɪɨɫɢɬ ɫɥɟɞɭɸɳɭɸ ɩɨɪɰɢɸ ɩɚɪɚɦɟɬɪɨɜ. ɉɨɫɥɟ ɷɬɨɝɨ ɭɩɪɚɜɥɟɧɢɟ ɫɧɨɜɚ ɩɟɪɟɞɚɟɬɫɹ ɨɩɟɪɚɬɨɪɭ SELECT. Ⱦɚɧɧɚɹ ɤɨɧɫɬɪɭɤɰɢɹ ɹɜɥɹɟɬɫɹ ɱɚɫɬɢɱɧɨɣ ɡɚɦɟɧɨɣ ɤɭɪɫɨɪɚɦ (ɭɤɚɡɚɬɟɥɹɦ ɧɚ ɧɚɛɨɪ ɫɬɪɨɤ), ɤɨɬɨɪɵɟ InterBase, ɜ ɨɬɥɢɱɢɟ ɨɬ ɞɪɭɝɢɯ ɋɍȻȾ, ɩɨɡɜɨɥɹɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɬɨɥɶɤɨ ɜɨ ɜɫɬɪɨɟɧɧɨɦ SQL [1] ɜ ɤɥɢɟɧɬɫɤɢɯ ɩɪɨɝɪɚɦɦɚɯ. ɇɚɩɨɦɧɢɦ, ɱɬɨ ɤɭɪɫɨɪɵ ɪɟɲɚɸɬ ɩɪɨɛɥɟɦɭ ɩɨɫɬɪɨɱɧɨɝɨ ɞɨɫɬɭɩɚ ɤ ɪɟɡɭɥɶɬɚɬɚɦ ɜɵɛɨɪɤɢ. ɂɡ ɩɪɢɥɨɠɟɧɢɹ ɯɪɚɧɢɦɚɹ ɩɪɨɰɟɞɭɪɚ, ɜɨɡɜɪɚɳɚɸɳɚɹ ɩɚɪɚɦɟɬɪɵ, ɜɵɡɵɜɚɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɨɩɟɪɚɬɨɪɚ SELECT * FROM <ɂɦɹɏɉ> (<ɫɩɢɫɨɤ ɜɯɨɞɧɵɯ ɩɚɪɚɦɟɬɪɨɜ>),
ɤɨɬɨɪɵɣ ɜɵɞɚɟɬ ɦɧɨɠɟɫɬɜɨ ɩɨɥɭɱɟɧɧɵɯ ɨɬ ɩɪɨɰɟɞɭɪɵ ɷɤɡɟɦɩɥɹɪɨɜ ɩɚɪɚɦɟɬɪɨɜ. ȼ Delphi ɞɥɹ ɬɚɤɨɝɨ ɫɩɨɫɨɛɚ ɜɵɡɨɜɚ ɦɨɠɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɤɨɦɩɨɧɟɧɬ TIBQuery. Ɂɚɩɪɨɫ ɭɤɚɡɵɜɚɟɬɫɹ ɜ ɫɜɨɣɫɬɜɟ SQL ɬɢɩɚ TStrings. Ⱦɥɹ ɜɵɡɨɜɚ ɩɪɨɰɟɞɭɪ, ɧɟ ɜɨɡɜɪɚɳɚɸɳɢɯ ɩɚɪɚɦɟɬɪɨɜ, ɧɚɩɪɢɦɟɪ, ɩɪɨɰɟɞɭɪ, ɦɨɞɢɮɢɰɢɪɭɸɳɢɯ ɞɚɧɧɵɟ, ɜ Delphi ɞɨɥɠɟɧ ɩɪɢɦɟɧɹɬɶɫɹ ɦɟɬɨɞ ExecProc ɤɨɦɩɨɧɟɧɬɚ TIBStoredProc (ɩ. 3.5). Ɉɧ ɦɨɠɟɬ ɩɪɢɦɟɧɹɬɶɫɹ ɢ ɞɥɹ ɜɵɡɨɜɚ ɩɪɨɰɟɞɭɪ, ɜɨɡɜɪɚɳɚɸɳɢɯ ɩɚɪɚɦɟɬɪɵ ɜ ɟɞɢɧɫɬɜɟɧɧɨɦ ɷɤɡɟɦɩɥɹɪɟ. ɉɪɢɦɟɪ. ɋɨɡɞɚɞɢɦ ɯɪɚɧɢɦɭɸ ɩɪɨɰɟɞɭɪɭ, ɜɨɡɜɪɚɳɚɸɳɭɸ ɞɚɬɵ ɢ ɤɨɥɢɱɟɫɬɜɚ ɨɬɝɪɭɡɤɢ ɬɨɜɚɪɚ, ɧɚɡɜɚɧɢɟ ɤɨɬɨɪɨɝɨ ɩɟɪɟɞɚɟɬɫɹ ɩɪɨɰɟɞɭɪɟ ɜ ɤɚɱɟɫɬɜɟ ɜɯɨɞɧɨɝɨ ɩɚɪɚɦɟɬɪɚ. CREATE PROCEDURE GetOrders (PName VARCHAR(20)) RETURNS (out_date DATE, out_total INTEGER) AS BEGIN FOR SELECT O.SaleDate, P.Total FROM Orders O, Products P WHERE (O.ProdID=P.ProdID) and (P.ProdName= :PName) INTO :out_data, out_total; DO SUSPEND; END
Ɂɚɩɪɨɫ ɞɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɏɉ ɢɦɟɟɬ ɜɢɞ SELECT * FROM GetOrders (’ɋɚɯɚɪ’).
27
ȿɫɥɢ ɟɝɨ ɩɨɦɟɫɬɢɬɶ ɜ TIBQuery, ɬɨ ɨɛɪɚɬɢɬɶɫɹ ɤ ɡɧɚɱɟɧɢɹɦ ɩɚɪɚɦɟɬɪɨɜ ɦɨɠɧɨ ɛɭɞɟɬ ɩɨɫɥɟ ɜɵɡɨɜɚ ɦɟɬɨɞɚ Open: q.SQL.Text:= ’SELECT * FROM GetOrders (:par)’; q.ParamByName(’par’).AsString:= ’ɋɚɯɚɪ’; q.Open;
Ɂɧɚɱɟɧɢɹ ɩɚɪɚɦɟɬɪɨɜ Out_Date ɢ Out_Total ɛɭɞɭɬ ɜɵɜɟɞɟɧɵ ɜ «ɫɟɬɤɭ» DBGrid, ɫɜɹɡɚɧɧɭɸ ɫ ɤɨɦɩɨɧɟɧɬɨɦ q: TIBQuery. 2.4. Ɍɪɢɝɝɟɪɵ Ɍɪɢɝɝɟɪ – ɷɬɨ ɪɚɡɧɨɜɢɞɧɨɫɬɶ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ, ɤɨɬɨɪɚɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɜɵɡɵɜɚɟɬɫɹ ɫɟɪɜɟɪɨɦ ɩɪɢ ɧɚɫɬɭɩɥɟɧɢɢ ɫɨɛɵɬɢɹ ɞɨɛɚɜɥɟɧɢɹ, ɢɡɦɟɧɟɧɢɹ ɢɥɢ ɭɞɚɥɟɧɢɹ ɫɬɪɨɤɢ ɜ ɬɚɛɥɢɰɟ. Ʉ ɬɪɢɝɝɟɪɭ ɧɟɥɶɡɹ ɨɛɪɚɬɢɬɶɫɹ ɢɡ ɩɪɢɤɥɚɞɧɨɣ ɩɪɨɝɪɚɦɦɵ, ɭ ɧɟɝɨ ɨɬɫɭɬɫɬɜɭɸɬ ɜɯɨɞɧɵɟ ɢ ɜɵɯɨɞɧɵɟ ɩɚɪɚɦɟɬɪɵ. Ɍɪɢɝɝɟɪ ɧɢɤɨɝɞɚ ɧɟ ɜɵɡɵɜɚɟɬɫɹ ɩɨɥɶɡɨɜɚɬɟɥɟɦ ɹɜɧɨ, ɨɧ ɫɪɚɛɚɬɵɜɚɟɬ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɪɢ ɧɚɫɬɭɩɥɟɧɢɢ ɭɤɚɡɚɧɧɵɯ ɫɨɛɵɬɢɣ ɜ ȻȾ. ɋ ɩɨɦɨɳɶɸ ɬɪɢɝɝɟɪɨɜ ɨɛɵɱɧɨ ɪɟɚɥɢɡɭɸɬɫɹ ɛɢɡɧɟɫ-ɩɪɚɜɢɥɚ, ɡɚɞɚɸɳɢɟ ɥɨɝɢɤɭ ɪɚɛɨɬɭ ɫ ȻȾ (ɩ. 2.1), ɧɚɩɪɢɦɟɪ, ɝɟɧɟɪɚɬɨɪɵ ɞɥɹ ɩɨɞɞɟɪɠɚɧɢɹ ɭɧɢɤɚɥɶɧɵɯ ɡɧɚɱɟɧɢɣ ɤɥɸɱɟɜɵɯ ɩɨɥɟɣ, ɤɨɧɬɪɨɥɶ ɞɨɩɭɫɬɢɦɨɫɬɢ ɜɜɨɞɢɦɵɯ ɡɧɚɱɟɧɢɣ ɩɪɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ, ɜɟɞɟɧɢɟ ɪɟɝɢɫɬɪɚɰɢɨɧɧɵɯ ɠɭɪɧɚɥɨɜ ɢ ɬ. ɩ. Ɍɪɢɝɝɟɪ ɧɟɥɶɡɹ «ɡɚɛɵɬɶ» ɜɵɡɜɚɬɶ, ɨɧ ɜɵɩɨɥɧɹɟɬɫɹ ɜɫɟɝɞɚ. Ɍɪɢɝɝɟɪ ɫɨɡɞɚɟɬɫɹ ɨɩɟɪɚɬɨɪɨɦ CREATE TRIGGER ɂɦɹɌɪɢɝɝɟɪɚ FOR ɂɦɹɌɚɛɥɢɰɵ [ACTIVE | INACTIVE] {BEFORE | AFTER} {DELETE | INSERT | UPDATE} [POSITION <ɧɨɦɟɪ>] AS <Ɍɟɥɨ ɬɪɢɝɝɟɪɚ>
Ɂɞɟɫɶ: ACTIVE | INACTIVE ɭɤɚɡɵɜɚɟɬ, ɚɤɬɢɜɟɧ ɬɪɢɝɝɟɪ ɢɥɢ ɧɟɬ. ɉɨ ɭɦɨɥɱɚ-
ɧɢɸ ɞɟɣɫɬɜɭɟɬ ACTIVE. BEFORE | AFTER ɭɤɚɡɵɜɚɟɬ ɦɨɦɟɧɬ ɜɵɩɨɥɧɟɧɢɹ ɬɪɢɝɝɟɪɚ, ɞɨ ɢɥɢ ɩɨɫɥɟ ɡɚɩɨɦɢɧɚɧɢɹ ɢɡɦɟɧɟɧɢɣ ɜ ȻȾ. DELETE | INSERT | UPDATE ɭɤɚɡɵɜɚɟɬ ɬɢɩ ɫɨɛɵɬɢɹ, ɧɚ ɤɨɬɨɪɨɟ ɪɟɚɝɢɪɭɟɬ ɬɪɢɝɝɟɪ. Ɍɪɢɝɝɟɪ ɫɨɡɞɚɟɬɫɹ ɢ ɢɦɟɟɬ ɫɢɥɭ ɞɥɹ ɤɚɠɞɨɣ ɬɚɛɥɢɰɵ ɜ ɨɬɞɟɥɶɧɨɫɬɢ. Ɉɞɧɨɦɭ ɫɨɛɵɬɢɸ ɦɨɠɟɬ ɛɵɬɶ ɧɚɡɧɚɱɟɧɨ ɧɟɫɤɨɥɶɤɨ ɬɪɢɝɝɟɪɨɜ, ɬɨɝɞɚ ɜ ɚɬɪɢɛɭɬɟ POSITION <ɧɨɦɟɪ> ɭɤɚɡɵɜɚɟɬɫɹ ɨɱɟɪɟɞɧɨɫɬɶ (ɩɨɪɹɞɤɨɜɵɣ ɧɨɦɟɪ) ɢɯ ɜɵɩɨɥɧɟɧɢɹ. ɉɟɪɜɵɦ ɫɬɚɪɬɭɟɬ ɬɪɢɝɝɟɪ ɫ ɦɟɧɶɲɢɦ ɧɨɦɟɪɨɦ. Ⱥɥɝɨɪɢɬɦɢɱɟɫɤɢɣ ɹɡɵɤ ɬɪɢɝɝɟɪɨɜ ɬɚɤɨɣ ɠɟ, ɤɚɤ ɭ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ. Ɉɬɥɢɱɢɟ ɫɨɫɬɨɢɬ ɜ ɜɨɡɦɨɠɧɨɫɬɢ ɨɛɪɚɳɟɧɢɹ ɤ ɫɬɚɪɵɦ ɢ ɧɨɜɵɦ ɡɧɚɱɟɧɢɹɦ ɫɬɨɥɛɰɨɜ ɬɚɛɥɢɰɵ, ɯɪɚɧɹɳɢɯɫɹ ɜ ɬɚɤ ɧɚɡɵɜɚɟɦɵɯ ɤɨɧɬɟɤɫɬɧɵɯ ɩɟɪɟ-
28
ɦɟɧɧɵɯ OLD ɢ NEW. ɗɬɨ ɨɱɟɧɶ ɭɞɨɛɧɨ ɞɥɹ ɩɪɨɜɟɪɤɢ ɩɪɚɜɢɥɶɧɨɫɬɢ ɡɚɩɢɫɵɜɚɟɦɵɯ ɡɧɚɱɟɧɢɣ. Ɂɚɩɢɫɶ OLD.ɂɦɹɋɬɨɥɛɰɚ ɨɡɧɚɱɚɟɬ ɨɛɪɚɳɟɧɢɟ ɤ ɡɧɚɱɟɧɢɸ ɫɬɨɥɛɰɚ ɞɨ ɜɧɟɫɟɧɢɹ ɜɨɡɦɨɠɧɵɯ ɢɡɦɟɧɟɧɢɣ. Ɂɚɩɢɫɶ NEW.ɂɦɹɋɬɨɥɛɰɚ – ɤ ɡɧɚɱɟɧɢɸ ɫɬɨɥɛɰɚ ɩɨɫɥɟ ɜɧɟɫɟɧɢɹ ɜɨɡɦɨɠɧɵɯ ɢɡɦɟɧɟɧɢɣ. ȼ ɬɪɢɝɝɟɪɚɯ BEFORE | AFTER UPDATE ɦɨɠɧɨ ɨɛɪɚɳɚɬɶɫɹ ɤ ɨɛɟɢɦ ɤɨɧɬɟɤɫɬɧɵɦ ɩɟɪɟɦɟɧɧɵɦ. ȼɚɠɧɨ ɩɨɦɧɢɬɶ ɬɪɢ ɩɪɨɫɬɵɯ ɩɪɚɜɢɥɚ: x ɟɫɥɢ ɬɪɢɝɝɟɪ ɫɨɡɞɚɟɬɫɹ ɞɥɹ ɫɨɛɵɬɢɹ ɜɫɬɚɜɤɢ, ɬɨ ɫɬɚɪɨɝɨ ɡɧɚɱɟɧɢɹ ɫɬɨɥɛɰɚ ɧɟ ɫɭɳɟɫɬɜɭɟɬ, ɩɨɷɬɨɦɭ OLD ɢɫɩɨɥɶɡɨɜɚɬɶ ɧɟɥɶɡɹ; x ɩɪɢ ɭɞɚɥɟɧɢɢ ɧɟ ɢɦɟɟɬ ɫɦɵɫɥɚ ɤɨɧɬɟɤɫɬɧɚɹ ɩɟɪɟɦɟɧɧɚɹ NEW; x ɜ ɬɪɢɝɝɟɪɚɯ AFTER ɡɧɚɱɟɧɢɟ NEW ɦɨɠɧɨ ɬɨɥɶɤɨ ɱɢɬɚɬɶ, ɧɨ ɧɟɥɶɡɹ ɢɡɦɟɧɹɬɶ. ɉɪɢɦɟɪ ɬɪɢɝɝɟɪɚ ɞɥɹ ɩɨɞɞɟɪɠɚɧɢɹ ɫɫɵɥɨɱɧɨɣ ɰɟɥɨɫɬɧɨɫɬɢ ɩɭɬɟɦ ɤɚɫɤɚɞɧɵɯ ɢɡɦɟɧɟɧɢɣ ɜ ɫɜɹɡɚɧɧɵɯ ɬɚɛɥɢɰɚɯ: CREATE TRIGGER BY_Change_CustID FOR Customers BEFORE UPDATE AS BEGIN IF (old.CustID <> new.CustID) THEN UPDATE Orders SET CustID=new.CustID WHERE CustID =old.CustID END
Ɂɚɦɟɱɚɧɢɟ: ɩɟɪɟɞ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɬɚɤɨɝɨ ɪɨɞɚ ɬɪɢɝɝɟɪɨɜ ɧɟɨɛɯɨɞɢɦɨ ɭɞɚɥɢɬɶ ɢɡ ɨɝɪɚɧɢɱɟɧɢɣ ɫɫɵɥɨɱɧɨɣ ɰɟɥɨɫɬɧɨɫɬɢ ɞɟɣɫɬɜɢɹ ON DELETE CASCADE, ɟɫɥɢ ɨɧɢ ɢɦɟɸɬɫɹ. ɉɪɢɦɟɪ ɬɪɢɝɝɟɪɚ ɞɥɹ ɡɚɩɨɥɧɟɧɢɹ ɩɟɪɜɢɱɧɨɝɨ ɤɥɸɱɚ: CREATE TRIGGER By_Insert_Pk FOR Orders BEFORE INSERT POSITION 1 AS BEGIN new.num=gen_id(g1,1); END
ɉɪɢɦɟɪ ɬɪɢɝɝɟɪɚ ɞɥɹ ɨɬɩɭɫɤɚ ɬɨɜɚɪɚ: CREATE TRIGGER By_Insert_Cnt FOR Orders BEFORE INSERT POSITION 0 AS DECLARE cnt integer; BEGIN /* ɉɪɨɜɟɪɹɟɦ ɧɚɥɢɱɢɟ ɬɨɜɚɪɚ ɧɚ ɫɤɥɚɞɟ */ SELECT rest FROM Products WHERE (Products.ProdID=new.ProdID) INTO :cnt; IF (new.ProdCount<=cnt) THEN /* ȿɫɥɢ ɨɫɬɚɬɨɤ ɞɨɫɬɚɬɨɱɟɧ, ɬɨ ɢɡɦɟɧɹɟɦ ɜ ɬɚɛɥɢɰɟ products */
29
UPDATE products SET Rest=Rest-new.ProdCount WHERE Products.ProdID = new.ProdID; ELSE /* Ƚɟɧɟɪɢɪɭɟɦ ɢɫɤɥɸɱɟɧɢɟ, ɩɪɢɜɨɞɹɳɟɟ ɤ ɨɬɤɚɬɭ ɜɫɟɣ */ /* ɬɪɚɧɡɚɤɰɢɢ, ɩɵɬɚɜɲɟɣɫɹ ɩɪɨɞɚɬɶ ɬɨɜɚɪ. */ /* Ɍɨ ɟɫɬɶ ɜɫɬɚɜɤɚ ɜ ɬɚɛɥɢɰɭ Orders ɬɚɤɠɟ ɨɬɦɟɧɹɟɬɫɹ */ EXCEPTION RestOut; END
Ɂɚɦɟɱɚɧɢɹ. 1. ȼ ɩɨɫɥɟɞɧɟɦ ɩɪɢɦɟɪɟ ɧɟɨɛɯɨɞɢɦɨ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɨɩɪɟɞɟɥɢɬɶ ɢɫɤɥɸɱɟɧɢɟ ɫɥɟɞɭɸɳɢɦ ɨɩɟɪɚɬɨɪɨɦ DDL. CREATE EXCEPTION RestOut 'ɇɚ ɫɤɥɚɞɟ ɧɟɬ ɧɭɠɧɨɝɨ ɤɨɥɢɱɟɫɬɜɚ ɬɨɜɚɪɚ!';
ɇɟ ɜɞɚɜɚɹɫɶ ɜ ɩɨɞɪɨɛɧɨɫɬɢ, ɦɨɠɧɨ ɨɬɦɟɬɢɬɶ, ɱɬɨ ɢɫɤɥɸɱɟɧɢɹ InterBase ɪɟɲɚɸɬ ɬɟ ɠɟ ɡɚɞɚɱɢ, ɱɬɨ ɢ ɢɫɤɥɸɱɢɬɟɥɶɧɵɟ ɫɢɬɭɚɰɢɢ ɜ Delphi [4], ɧɚɩɪɢɦɟɪ, ɪɟɚɤɰɢɸ ɧɚ ɧɟɩɪɚɜɢɥɶɧɵɣ ɜɜɨɞ ɞɚɧɧɵɯ. ɇɟɤɨɪɪɟɤɬɧɵɟ ɞɚɧɧɵɟ ɜ ɬɚɛɥɢɰɭ ɧɟ ɡɚɩɢɫɵɜɚɸɬɫɹ. ɉɨɥɶɡɨɜɚɬɟɥɸ ɜɵɞɚɟɬɫɹ ɫɨɨɛɳɟɧɢɟ ɨɛ ɨɲɢɛɤɟ, ɭɤɚɡɚɧɧɨɟ ɩɪɢ ɨɩɪɟɞɟɥɟɧɢɢ ɢɫɤɥɸɱɟɧɢɹ.
Ɋɢɫ. 2.1. ɉɨɫɥɟ ɷɬɨɝɨ ɟɦɭ ɨɫɬɚɟɬɫɹ ɥɢɛɨ ɩɨɜɬɨɪɢɬɶ ɜɜɨɞ, ɥɢɛɨ ɨɬɤɚɬɢɬɶ ɬɪɚɧɡɚɤɰɢɸ. Ȼɨɥɟɟ ɩɨɞɪɨɛɧɨ ɨɛ ɢɫɤɥɸɱɟɧɢɹɯ InterBase ɫɦ. ɜ [1]. 2. Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ, ɱɬɨ ɨɛɚ ɩɨɫɥɟɞɧɢɯ ɬɪɢɝɝɟɪɚ ɫɨɡɞɚɸɬɫɹ ɞɥɹ ɨɞɧɨɝɨ ɫɨɛɵɬɢɹ BEFORE INSERT ɢ ɨɬɥɢɱɚɸɬɫɹ ɩɨɪɹɞɤɨɦ ɜɵɩɨɥɧɟɧɢɹ (POSITION), ɩɪɢɱɟɦ ɬɪɢɝɝɟɪ, ɩɪɨɜɟɪɹɸɳɢɣ ɤɨɪɪɟɤɬɧɨɫɬɶ ɜɜɨɞɢɦɵɯ ɞɚɧɧɵɯ, ɜɵɩɨɥɧɹɟɬɫɹ ɩɟɪɜɵɦ. 2.5. ɉɪɟɞɫɬɚɜɥɟɧɢɹ ɉɪɟɞɫɬɚɜɥɟɧɢɟ (ɜɢɞ, ɩɪɨɫɦɨɬɪ, View) – ɷɬɨ ɜɢɪɬɭɚɥɶɧɚɹ ɬɚɛɥɢɰɚ, ɤɨɬɨɪɚɹ ɧɟ ɫɨɯɪɚɧɟɧɚ ɮɢɡɢɱɟɫɤɢ ɜ ɛɚɡɟ ɞɚɧɧɵɯ, ɧɨ ɜɟɞɟɬ ɫɟɛɹ ɤɚɤ «ɪɟɚɥɶɧɚɹ» ɬɚɛɥɢɰɚ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɮɨɪɦɢɪɭɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɨɩɟɪɚɬɨɪɚ SELECT, ɭɤɚɡɚɧɧɨɝɨ ɩɪɢ ɫɨɡɞɚɧɢɢ ɩɪɟɞɫɬɚɜɥɟɧɢɹ. Ɉɛɴɹɜɥɟɧɢɟ ɯɪɚɧɢɬɫɹ ɜ ȻȾ ɧɚ ɫɟɪɜɟɪɟ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɦɨɠɟɬ ɨɬɨɛɪɚɠɚɬɶ ɞɚɧɧɵɟ ɢɡ ɨɞɧɨɣ ɢɥɢ ɛɨɥɟɟ ɬɚɛɥɢɰ ɢɥɢ ɞɪɭɝɢɯ ɩɪɟɞɫɬɚɜɥɟɧɢɣ. ɋɢɧɬɚɤɫɢɫ ɫɨɡɞɚɧɢɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ: CREATE VIEW ɂɦɹɉɪɨɫɦɨɬɪɚ [(ɋɬɨɥɛɟɰ[, ɋɬɨɥɛɟɰ …])] AS <ɨɩɟɪɚɬɨɪ SELECT> [WITH CHECK OPTION]
30
ɇɟɨɛɹɡɚɬɟɥɶɧɵɣ ɩɚɪɚɦɟɬɪ WITH CHECK OPTION ɭɤɚɡɵɜɚɟɬɫɹ, ɟɫɥɢ ɩɪɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ ɧɟ ɞɨɩɭɫɤɚɟɬɫɹ ɜɜɨɞ ɞɚɧɧɵɯ, ɧɟ ɭɞɨɜɥɟɬɜɨɪɹɸɳɢɯ ɭɫɥɨɜɢɸ ɡɚɩɪɨɫɚ. ȿɫɥɢ ɫɩɢɫɨɤ ɫɬɨɥɛɰɨɜ ɨɬɫɭɬɫɬɜɭɟɬ, ɬɨ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɜɨɡɜɪɚɳɚɟɬ ɜɫɟ ɫɬɨɥɛɰɵ, ɩɟɪɟɱɢɫɥɟɧɧɵɟ ɜ ɨɩɟɪɚɬɨɪɟ SELECT. ɋɩɢɫɨɤ ɫɬɨɥɛɰɨɜ ɢɫɩɨɥɶɡɭɟɬɫɹ, ɟɫɥɢ ɬɪɟɛɭɟɬɫɹ ɡɚɦɟɧɢɬɶ ɢɦɟɧɚ ɫɬɨɥɛɰɨɜ ɬɚɛɥɢɰ ɩɫɟɜɞɨɧɢɦɚɦɢ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɨɬɞɟɥɹɟɬ ɩɨɥɶɡɨɜɚɬɟɥɹ ɨɬ ɬɚɛɥɢɰ, ɩɪɟɞɨɫɬɚɜɥɹɹ ɟɦɭ ɬɨɥɶɤɨ ɬɟ ɫɬɨɥɛɰɵ ɢ ɫɬɪɨɤɢ, ɤɨɬɨɪɵɟ ɟɦɭ ɧɭɠɧɵ ɞɥɹ ɪɚɛɨɬɵ ɢ ɤ ɤɨɬɨɪɵɦ ɨɧ ɢɦɟɟɬ ɩɪɚɜɨ ɞɨɫɬɭɩɚ. ɉɪɢ ɷɬɨɦ ɩɨɥɶɡɨɜɚɬɟɥɸ ɧɟɢɡɜɟɫɬɧɨ, ɢɡ ɤɚɤɢɯ ɬɚɛɥɢɰ ɩɪɨɢɫɯɨɞɢɬ ɜɵɛɨɪɤɚ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɬɚɤɠɟ «ɡɚɳɢɳɚɟɬ» ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɨɬ ɩɨɫɥɟɞɫɬɜɢɣ ɧɨɪɦɚɥɢɡɚɰɢɢ. ɇɚɩɪɢɦɟɪ, ɜɧɭɬɪɢ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɩɪɨɢɫɯɨɞɢɬ ɜɵɛɨɪɤɚ ɢɡ ɞɜɭɯ ɫɜɹɡɚɧɧɵɯ ɜɧɭɬɪɟɧɧɢɦ ɫɨɟɞɢɧɟɧɢɟɦ ɬɚɛɥɢɰ, ɧɨ ɩɨɥɶɡɨɜɚɬɟɥɶ ɷɬɨɝɨ ɧɟ ɡɚɦɟɱɚɟɬ ɢ ɪɚɛɨɬɚɟɬ ɫ ɩɪɟɞɫɬɚɜɥɟɧɢɟɦ, ɤɚɤ ɫ ɨɞɧɨɣ ɬɚɛɥɢɰɟɣ. ȿɫɥɢ ɩɨɥɶɡɨɜɚɬɟɥɢ ɪɚɛɨɬɚɸɬ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ ɱɟɪɟɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɢ ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ, ɬɨ ɢɡɦɟɧɟɧɢɹ ɜ ɫɬɪɭɤɬɭɪɟ ȻȾ ɱɚɫɬɨ ɜɨɨɛɳɟ ɦɨɝɭɬ ɧɟ ɩɪɢɜɨɞɢɬɶ ɤ ɩɟɪɟɞɟɥɤɟ ɤɥɢɟɧɬɫɤɢɯ ɩɪɢɥɨɠɟɧɢɣ. ɉɪɨɫɦɨɬɪɵ ɦɨɝɭɬ ɛɵɬɶ ɨɛɧɨɜɥɹɟɦɵɦɢ. ɗɬɨ ɨɡɧɚɱɚɟɬ: ɟɫɥɢ ɩɪɢɦɟɧɢɬɶ ɤ ɧɢɦ ɨɩɟɪɚɬɨɪɵ ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ, ɢɡɦɟɧɟɧɢɹ ɡɚɩɢɫɵɜɚɸɬɫɹ ɜ ɪɟɚɥɶɧɵɟ ɬɚɛɥɢɰɵ. ɋɩɨɫɨɛɧɨɫɬɶ ɤ ɨɛɧɨɜɥɟɧɢɸ ɡɚɜɢɫɢɬ ɨɬ ɯɚɪɚɤɬɟɪɚ ɡɚɩɪɨɫɚ. ɇɟɥɶɡɹ ɨɛɧɨɜɥɹɬɶ ɩɪɟɞɫɬɚɜɥɟɧɢɹ, ɟɫɥɢ ɡɚɩɪɨɫ ɫɨɞɟɪɠɢɬ ɜɵɛɨɪɤɭ ɢɡ ɧɟɫɤɨɥɶɤɢɯ ɬɚɛɥɢɰ, ɩɨɞɡɚɩɪɨɫɵ, ɚɝɪɟɝɚɬɧɵɟ ɮɭɧɤɰɢɢ, ɝɪɭɩɩɢɪɨɜɤɢ, ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ, UDF, ɩɪɟɞɥɨɠɟɧɢɹ DISTINCT, ORDER BY. Ⱦɥɹ ɩɪɟɨɞɨɥɟɧɢɹ ɭɤɚɡɚɧɧɵɯ ɨɝɪɚɧɢɱɟɧɢɣ ɢɫɩɨɥɶɡɭɸɬɫɹ ɬɪɢɝɝɟɪɵ ɧɚ ɩɪɟɞɫɬɚɜɥɟɧɢɹ [1]. 3. ɇɚɩɢɫɚɧɢɟ ɤɥɢɟɧɬɫɤɢɯ ɩɪɢɥɨɠɟɧɢɣ ɇɚɢɛɨɥɟɟ ɷɮɮɟɤɬɢɜɧɵɦɢ ɫɩɨɫɨɛɨɦ ɫɨɡɞɚɧɢɹ ɩɪɢɥɨɠɟɧɢɣ ɹɜɥɹɸɬɫɹ ɩɪɹɦɵɟ ɜɵɡɨɜɵ ɮɭɧɤɰɢɣ API ɤɥɢɟɧɬɚ ɢɡ ɩɪɢɥɨɠɟɧɢɣ ɢɥɢ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɜɫɬɪɨɟɧɧɨɝɨ (Embedded) ɹɡɵɤɚ SQL. Ɉɞɧɚɤɨ ɜ ɩɨɜɫɟɞɧɟɜɧɨɣ ɩɪɚɤɬɢɤɟ ɝɨɪɚɡɞɨ ɭɞɨɛɧɟɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɨɦɩɨɧɟɧɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɟ ɬɟɯɧɨɥɨɝɢɢ, ɨɫɧɨɜɚɧɧɵɟ ɧɚ ɫɬɚɧɞɚɪɬɧɵɯ ɬɟɯɧɨɥɨɝɢɹɯ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ. Ⱦɥɹ ɪɚɡɪɚɛɨɬɱɢɤɚ ɜɚɠɧɨ, ɱɬɨ ɩɨɞɞɟɪɠɤɚ InterBase ɜɫɬɪɨɟɧɚ ɜɨ ɜɫɟ ɫɭɳɟɫɬɜɭɸɳɢɟ ɫɬɚɧɞɚɪɬɵ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ ɫɨ ɫɬɨɪɨɧɵ ɤɥɢɟɧɬɚ – ADO, ADO.NET, ODBC, JDBC, BDE, DbExpress ɢ ɞɪ. ȼ Delphi ɢɦɟɸɬɫɹ ɤɨɦɩɨɧɟɧɬɵ ɞɥɹ ɞɨɫɬɭɩɚ ɱɟɪɟɡ ADO, BDE ɢ DbExpress. ɉɪɚɜɞɚ, ɬɟɯɧɨɥɨɝɢɹ BDE ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɭɫɬɚɪɟɥɚ ɢ ɧɟ ɨɛɟɫɩɟɱɢɜɚɟɬ ɬɪɟɛɭɟɦɨɣ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɢ. Ⱦɥɹ ɞɨɫɬɭɩɚ ɱɟɪɟɡ ADO ɧɟɨɛɯɨɞɢɦɨ ɭɫɬɚɧɨɜɢɬɶ ɜ Windows ADO-ɩɪɨɜɚɣɞɟɪ ɞɥɹ InterBase (ɜɨɡɦɨɠɧɵɟ ɜɚɪɢɚɧɬɵ ɫɦ. ɧɚ ɫɚɣɬɟ www.ibase.ru). ɍɧɢɜɟɪɫɚɥɶɧɚɹ ɤɨɦɩɨɧɟɧɬɧɚɹ ɬɟɯɧɨɥɨɝɢɹ DbExpress, ɨɮɢɰɢɚɥɶɧɨ ɪɟɤɨɦɟɧɞɭɟɦɚɹ Borland, ɩɨɡɜɨɥɹɟɬ ɫɨɡɞɚɜɚɬɶ ɤɨɦɩɚɤɬɧɵɟ ɢ ɛɵɫɬɪɵɟ ɤɪɨɫɫɩɥɚɬɮɨɪɦɟɧɧɵɟ ɩɪɢɥɨɠɟɧɢɹ, ɧɨ ɢɦɟɟɬ ɧɟɤɨɬɨɪɵɟ ɧɟɭɞɨɛɫɬɜɚ ɢ ɨɝɪɚɧɢɱɟɧɢɹ. 31
Ⱦɚɥɟɟ ɦɵ ɛɭɞɟɦ ɪɚɫɫɦɚɬɪɢɜɚɬɶ ɫɩɟɰɢɚɥɢɡɢɪɨɜɚɧɧɵɟ ɤɨɦɩɨɧɟɧɬɵ InterBase Express (IBX), ɩɨɫɬɚɜɥɹɟɦɵɟ ɜ ɫɨɫɬɚɜɟ Delphi ɢ ɭɦɟɸɳɢɟ ɪɚɛɨɬɚɬɶ ɬɨɥɶɤɨ ɫ InterBase. Ⱥɥɶɬɟɪɧɚɬɢɜɧɵɟ ɫɩɟɰɢɚɥɢɡɢɪɨɜɚɧɧɵɟ ɤɨɦɩɨɧɟɧɬɵ FIBPlus ɨɬ ɤɨɦɩɚɧɢɢ Devrace ɛɨɥɟɟ ɮɭɧɤɰɢɨɧɚɥɶɧɵ, ɧɨ ɨɧɢ ɹɜɥɹɸɬɫɹ ɫɚɦɨɫɬɨɹɬɟɥɶɧɵɦ ɩɥɚɬɧɵɦ ɩɪɨɝɪɚɦɦɧɵɦ ɩɪɨɞɭɤɬɨɦ, ɤɨɬɨɪɵɣ ɫɥɟɞɭɟɬ ɩɪɢɨɛɪɟɬɚɬɶ ɨɬɞɟɥɶɧɨ. (ɋ ɩɨɦɨɳɶɸ FIBPlus ɧɚɩɢɫɚɧɚ ɩɪɨɝɪɚɦɦɚ IBExpert.) ɋɬɪɭɤɬɭɪɚ ɢ ɤɨɞ ɩɪɢɥɨɠɟɧɢɹ ɩɪɢ ɪɚɡɥɢɱɧɵɯ ɬɟɯɧɨɥɨɝɢɹɯ ɞɨɫɬɭɩɚ ɨɞɧɨɬɢɩɧɵ, ɬɚɤ ɤɚɤ ɤɨɦɩɨɧɟɧɬɵ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ ɜ Delphi, ɛɭɞɭɱɢ ɩɨɬɨɦɤɚɦɢ ɤɥɚɫɫɚ TDataSet, ɢɦɟɸɬ ɦɧɨɝɨ ɨɛɳɢɯ ɱɟɪɬ ɫɨ ɫɬɚɜɲɢɦɢ ɤɥɚɫɫɢɱɟɫɤɢɦɢ BDE-ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɦɢ ɤɨɦɩɨɧɟɧɬɚɦɢ. ɇɚɢɛɨɥɟɟ ɢɧɜɚɪɢɚɧɬɧɵ ɭɱɚɫɬɤɢ ɤɨɞɚ, ɫɜɹɡɚɧɧɵɟ ɫ ɩɨɢɫɤɨɦ, ɩɪɨɫɦɨɬɪɨɦ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɟɦ ɞɚɧɧɵɯ 3.1. ɋɨɟɞɢɧɟɧɢɟ ɫ ɫɟɪɜɟɪɨɦ Ⱦɥɹ ɭɫɬɚɧɨɜɤɢ ɫɨɟɞɢɧɟɧɢɹ ɩɪɟɞɧɚɡɧɚɱɟɧ ɤɨɦɩɨɧɟɧɬ IBDataBase, ɨɛɹɡɚɬɟɥɶɧɨ ɩɪɢɫɭɬɫɬɜɭɸɳɢɣ ɜ ɩɪɨɝɪɚɦɦɟ. Ʉɨɦɩɨɧɟɧɬ ɫɨɞɟɪɠɢɬ ɩɚɪɚɦɟɬɪɵ ɫɨɟɞɢɧɟɧɢɹ ɫ ɫɟɪɜɟɪɨɦ (ɢɦɹ ɫɟɪɜɟɪɚ, ɩɪɨɬɨɤɨɥ, ɩɭɬɶ ɤ ȻȾ, ɢɦɹ ɢ ɩɚɪɨɥɶ). ɉɚɪɚɦɟɬɪɵ ɭɫɬɚɧɚɜɥɢɜɚɸɬɫɹ ɜ ɨɤɧɟ DataBase Component Editor, ɜɵɡɵɜɚɟɦɨɦ ɩɪɢ ɞɜɨɣɧɨɦ ɳɟɥɱɤɟ ɩɨ ɤɨɦɩɨɧɟɧɬɭ.
Ɋɢɫ. 3.1. ɗɬɢ ɡɧɚɱɟɧɢɹ ɦɨɠɧɨ ɜɜɟɫɬɢ ɬɚɤɠɟ ɩɪɨɝɪɚɦɦɧɨ ɢɥɢ ɫ ɩɨɦɨɳɶɸ ɢɧɫɩɟɤɬɨɪɚ ɨɛɴɟɤɬɨɜ. ɇɚɩɪɢɦɟɪ, ɩɭɬɶ ɤ ɛɚɡɟ ɞɚɧɧɵɯ ɧɚ ɫɟɪɜɟɪɟ 32
c1r214srv:D:\IB\4gr\MyBase\NewSklad.gdb ɯɪɚɧɢɬɫɹ ɜ ɫɜɨɣɫɬɜɟ DataBaseName ɪɚɫɫɦɚɬɪɢɜɚɟɦɨɝɨ ɤɨɦɩɨɧɟɧɬɚ. ɇɚ ɷɬɚɩɟ ɨɬɥɚɞɤɢ ɧɟ ɡɚɛɭɞɶɬɟ ɭɫɬɚɧɨɜɢɬɶ ɫɜɨɣɫɬɜɨ LoginPrompt ɜ False, ɱɬɨ ɥɢɲɢɬ ȼɚɫ ɫɨɦɧɢɬɟɥɶɧɨɝɨ ɭɞɨɜɨɥɶɫɬɜɢɹ ɦɧɨɝɨɤɪɚɬɧɨ ɧɚɛɢɪɚɬɶ ɢɦɹ ɢ ɩɚɪɨɥɶ ɩɪɢ ɡɚɩɭɫɤɚɯ ɩɪɨɝɪɚɦɦɵ. ɇɚ ɡɚɜɟɪɲɚɸɳɟɦ ɷɬɚɩɟ ɪɚɡɪɚɛɨɬɤɢ ɩɪɢ ɩɨɞɝɨɬɨɜɤɟ ɩɪɨɝɪɚɦɦɵ ɤ ɪɚɡɜɟɪɬɵɜɚɧɢɸ, ɧɚɨɛɨɪɨɬ, ɫɥɟɞɭɟɬ ɨɱɢɫɬɢɬɶ ɤɨɦɩɨɧɟɧɬ IBDataBase ɨɬ ɩɚɪɚɦɟɬɪɨɜ ɫɨɟɞɢɧɟɧɢɹ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ, ɩɪɟɞɭɫɦɨɬɪɟɜ ɢɯ ɜɜɨɞ ɜ ɞɢɚɥɨɝɨɜɨɦ ɪɟɠɢɦɟ (ɩɪɢɦɟɪ ɜ ɪɚɡɞɟɥɟ 4). ȼ ɩɪɨɬɢɜɧɨɦ ɫɥɭɱɚɟ ɩɪɢ ɭɫɬɚɧɨɜɤɟ ɩɪɨɝɪɚɦɦɵ ɧɚ ɧɨɜɵɣ ɤɨɦɩɶɸɬɟɪ, ɫɤɨɪɟɟ ɜɫɟɝɨ, ɩɨɬɪɟɛɭɟɬɫɹ ɟɟ ɩɟɪɟɤɨɦɩɢɥɹɰɢɹ. ɇɨ ɫɚɦɨɟ ɝɥɚɜɧɨɟ – ɭɱɟɬɧɨɟ ɢɦɹ ɢ ɩɚɪɨɥɶ, «ɡɚɲɢɬɵɟ» ɜ ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ, ɱɪɟɡɜɵɱɚɣɧɨ ɨɛɥɟɝɱɚɸɬ ɠɢɡɧɶ ɩɨɬɟɧɰɢɚɥɶɧɵɦ ɡɥɨɭɦɵɲɥɟɧɧɢɤɚɦ. 3.2. ɍɩɪɚɜɥɟɧɢɟ ɬɪɚɧɡɚɤɰɢɹɦɢ ɉɪɚɜɢɥɶɧɚɹ ɪɚɛɨɬɚ ɫ ɬɪɚɧɡɚɤɰɢɹɦɢ – ɧɟɨɛɯɨɞɢɦɵɣ ɷɥɟɦɟɧɬ ɥɸɛɨɣ ɩɪɨɝɪɚɦɦɵ, ɪɚɛɨɬɚɸɳɟɣ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ ɜ ɤɥɢɟɧɬ-ɫɟɪɜɟɪɧɨɣ ɫɪɟɞɟ. ȼ Interbase ɬɪɚɧɡɚɤɰɢɹɦɢ ɦɨɠɧɨ ɭɩɪɚɜɥɹɬɶ ɬɨɥɶɤɨ ɢɡ ɤɥɢɟɧɬɫɤɨɣ ɩɪɨɝɪɚɦɦɵ (ɢɥɢ ɢɧɬɟɪɚɤɬɢɜɧɨ), ɜ ɬɪɢɝɝɟɪɚɯ ɢ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪɚɯ ɨɩɟɪɚɬɨɪɵ ɭɩɪɚɜɥɟɧɢɹ ɬɪɚɧɡɚɤɰɢɹɦɢ ɢɫɩɨɥɶɡɨɜɚɬɶ ɧɟɥɶɡɹ. ɇɚɩɨɦɧɢɦ, ɱɬɨ ɬɪɚɧɡɚɤɰɢɟɣ ɧɚɡɵɜɚɟɬɫɹ ɝɪɭɩɩɚ ɨɩɟɪɚɬɨɪɨɜ, ɩɟɪɟɜɨɞɹɳɢɯ ȻȾ ɢɡ ɨɞɧɨɝɨ ɰɟɥɨɫɬɧɨɝɨ ɫɨɫɬɨɹɧɢɹ ɜ ɞɪɭɝɨɟ. Ɍɪɚɧɡɚɤɰɢɹ ɭɞɨɜɥɟɬɜɨɪɹɟɬ ɬɪɟɛɨɜɚɧɢɹɦ ɚɬɨɦɚɪɧɨɫɬɢ, ɢɡɨɥɢɪɨɜɚɧɧɨɫɬɢ, ɫɨɝɥɚɫɨɜɚɧɧɨɫɬɢ ɢ ɞɨɥɝɨɜɟɱɧɨɫɬɢ [1]. ɉɨɫɥɟ ɫɬɚɪɬɚ ɬɪɚɧɡɚɤɰɢɹ ɹɜɥɹɟɬɫɹ ɚɤɬɢɜɧɨɣ. ȿɟ ɦɨɠɧɨ ɡɚɜɟɪɲɢɬɶ (ɢ ɫɞɟɥɚɬɶ ɧɟɚɤɬɢɜɧɨɣ), ɩɨɞɬɜɟɪɞɢɜ (Commit) ɢɥɢ ɨɬɤɚɬɢɜ (Rollback) ɩɪɨɢɡɜɟɞɟɧɧɵɟ ɟɣ ɢɡɦɟɧɟɧɢɹ ɜ ȻȾ ɧɚ ɫɟɪɜɟɪɟ. Ɂɚɦɟɱɚɧɢɟ. ȼ InterBase ɬɪɚɧɡɚɤɰɢɢ ɫɬɪɨɹɬɫɹ ɧɚ ɨɫɧɨɜɟ ɦɧɨɝɨɜɟɪɫɢɨɧɧɨɫɬɢ ɡɚɩɢɫɟɣ. ɉɪɢ ɫɬɚɪɬɟ ɬɪɚɧɡɚɤɰɢɢ, ɦɨɞɢɮɢɰɢɪɭɸɳɟɣ ɞɚɧɧɵɟ, ɫɨɡɞɚɟɬɫɹ ɟɳɟ ɨɞɧɚ ɜɟɪɫɢɹ ɪɟɞɚɤɬɢɪɭɟɦɨɣ ɡɚɩɢɫɢ. ɉɨɫɥɟ ɩɨɞɬɜɟɪɠɞɟɧɢɹ ɷɬɚ ɧɨɜɚɹ ɜɟɪɫɢɹ ɫɬɚɧɨɜɢɬɫɹ ɨɫɧɨɜɧɨɣ (ɚɤɬɭɚɥɶɧɨɣ), ɚ ɩɨɫɥɟ ɨɬɤɚɬɚ ɬɪɚɧɡɚɤɰɢɢ ɚɤɬɭɚɥɶɧɨɣ ɨɫɬɚɟɬɫɹ ɫɬɚɪɚɹ ɜɟɪɫɢɹ. Ɇɧɨɝɨɜɟɪɫɢɨɧɧɨɫɬɶ ɩɨɡɜɨɥɹɟɬ ɭɦɟɧɶɲɢɬɶ ɤɨɥɢɱɟɫɬɜɨ ɛɥɨɤɢɪɨɜɨɤ, ɬɨɪɦɨɡɹɳɢɯ ɪɚɛɨɬɭ ɫɟɪɜɟɪɚ. Ȼɥɨɤɢɪɨɜɤɢ ɩɪɢɦɟɧɹɸɬɫɹ ɬɨɥɶɤɨ ɩɪɢ ɩɨɩɵɬɤɚɯ ɡɚɩɢɫɢ, ɱɬɨɛɵ ɢɡɛɟɠɚɬɶ ɤɨɥɥɢɡɢɢ «ɝɨɧɨɤ» (ɩ. 3.3). ɋɨɝɥɚɫɧɨ ɩɪɢɜɟɞɟɧɧɨɦɭ ɨɩɪɟɞɟɥɟɧɢɸ ɬɪɚɧɡɚɤɰɢɟɣ ɹɜɥɹɟɬɫɹ ɧɟ ɬɨɥɶɤɨ ɝɪɭɩɩɚ ɨɩɟɪɚɰɢɣ, ɧɨ ɢ ɨɬɞɟɥɶɧɵɣ ɨɩɟɪɚɬɨɪ ɹɡɵɤɚ SQL. ɇɚɩɪɢɦɟɪ, ɨɩɟɪɚɬɨɪ, ɜɵɩɨɥɧɹɸɳɢɣ ɜɵɛɨɪɤɭ ɢɡ ɬɚɛɥɢɰɵ. ɇɚɛɨɪɵ ɞɚɧɧɵɯ (ɇȾ) ɜ Delphi ɨɫɧɨɜɚɧɵ ɧɚ ɤɥɢɟɧɬɫɤɢɯ ɤɭɪɫɨɪɚɯ [2], ɜɵɛɢɪɚɸɳɢɯ ɞɚɧɧɵɟ ɢɡ ɬɚɛɥɢɰ. ɉɨɬɨɦɭ ɜɫɟ ɨɩɟɪɚɰɢɢ ɫ ɇȾ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɤɚɤ ɬɪɚɧɡɚɤɰɢɢ. Ⱦɥɹ ɭɩɪɚɜɥɟɧɢɹ ɬɪɚɧɡɚɤɰɢɹɦɢ ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɨɦɩɨɧɟɧɬ IBTransaction, ɹɜɥɹɸɳɢɣɫɹ ɨɛɹɡɚɬɟɥɶɧɵɦ ɜ ɩɪɢɥɨɠɟɧɢɢ. 33
Ʉɨɦɩɨɧɟɧɬ ɢɧɤɚɩɫɭɥɢɪɭɟɬ ɨɩɟɪɚɬɨɪɵ SQL ɭɩɪɚɜɥɟɧɢɹ ɬɪɚɧɡɚɤɰɢɹɦ ɜ InterBase. C ɩɨɦɨɳɶɸ ɷɬɨɝɨ ɤɨɦɩɨɧɟɧɬɚ ɡɚɞɚɸɬɫɹ ɫɜɨɣɫɬɜɚ ɬɪɚɧɡɚɤɰɢɣ (ɭɪɨɜɧɢ ɢɡɨɥɹɰɢɢ, ɪɟɠɢɦ ɞɨɫɬɭɩɚ, ɪɟɠɢɦ ɨɛɪɚɛɨɬɤɢ ɤɨɧɮɥɢɤɬɨɜ ɛɥɨɤɢɪɨɜɨɤ) ɢ ɩɪɨɢɫɯɨɞɢɬ ɭɩɪɚɜɥɟɧɢɟ ɬɪɚɧɡɚɤɰɢɹɦɢ: ɫɬɚɪɬ, ɩɨɞɬɜɟɪɠɞɟɧɢɟ, ɨɬɤɚɬ. ɋɫɵɥɤɚ ɧɚ IBTransaction ɭɤɚɡɵɜɚɟɬɫɹ ɜ ɫɜɨɣɫɬɜɚɯ Transaction: TIBTransaction ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ (IBQuery, IBTable ɢ ɞɪ.). ɗɬɨ ɨɡɧɚɱɚɟɬ ɱɬɨ ɨɩɟɪɚɰɢɢ ɫɨ ɜɫɟɦɢ ɧɚɛɨɪɚɦɢ ɞɚɧɧɵɯ, ɫɫɵɥɚɸɳɢɦɢɫɹ ɧɚ ɨɞɢɧ ɤɨɦɩɨɧɟɧɬ IBTransaction, ɛɭɞɭɬ ɪɚɫɫɦɚɬɪɢɜɚɬɶɫɹ ɨɬɧɨɫɹɳɢɦɢɫɹ ɤ ɨɞɧɨɣ ɬɪɚɧɡɚɤɰɢɢ. ɋɫɵɥɤɢ ɧɚ IBTransaction ɥɭɱɲɟ ɪɚɫɫɬɚɜɥɹɬɶ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ. ɋɧɚɱɚɥɚ ɫɥɟɞɭɟɬ ɫɜɹɡɚɬɶ ɤɨɦɩɨɧɟɧɬ IBDataBase ɫ ɨɛɴɟɤɬɨɦ IBTransaction ɱɟɪɟɡ ɫɜɨɣɫɬɜɨ property DefaultTransaction: TIBTransaction.
Ɍɪɚɧɡɚɤɰɢɹ, ɭɤɚɡɚɧɧɚɹ ɜ ɞɚɧɧɨɦ ɫɜɨɣɫɬɜɟ, ɛɭɞɟɬ ɪɚɫɫɦɚɬɪɢɜɚɬɶɫɹ ɤɚɤ ɬɪɚɧɡɚɤɰɢɹ «ɩɨ ɭɦɨɥɱɚɧɢɸ» ɞɥɹ ɜɫɟɯ ɇȾ, ɢɫɩɨɥɶɡɭɸɳɢɯ ɞɚɧɧɨɟ ɫɨɟɞɢɧɟɧɢɟ. ȿɫɥɢ ɫɜɨɣɫɬɜɨ DefaultTransaction ɧɟ ɩɭɫɬɨ ɢ ɭɤɚɡɵɜɚɟɬ ɧɚ ɤɨɦɩɨɧɟɧɬ-ɬɪɚɧɡɚɤɰɢɸ, ɬɨ ɫɜɨɣɫɬɜɨ Transaction ɜɫɟɯ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɡɚɩɨɥɧɢɬɫɹ ɫɫɵɥɤɨɣ ɧɚ ɷɬɨɬ ɠɟ ɤɨɦɩɨɧɟɧɬ. Ⱦɚɥɟɟ ɷɬɭ ɫɫɵɥɤɭ ɦɨɠɧɨ ɢɡɦɟɧɢɬɶ, ɟɫɥɢ ɩɥɚɧɢɪɭɟɬɫɹ ɧɚɛɨɪɵ ɞɚɧɧɵɯ ɨɬɤɪɵɜɚɬɶ ɜ ɤɨɧɬɟɤɫɬɚɯ ɪɚɡɧɵɯ ɬɪɚɧɡɚɤɰɢɣ. ɋɨɜɟɪɲɟɧɧɨ ɚɧɚɥɨɝɢɱɧɨɝɨ ɪɟɡɭɥɶɬɚɬɚ ɦɨɠɧɨ ɞɨɛɢɬɶɫɹ, ɭɫɬɚɧɨɜɢɜ ɜ ɫɜɨɣɫɬɜɟ property DefaultDatabase: TIBDatabase;
ɫɫɵɥɤɭ ɧɚ ɤɨɦɩɨɧɟɧɬ-ɫɨɟɞɢɧɟɧɢɟ «ɩɨ ɭɦɨɥɱɚɧɢɸ». Ɂɚɦɟɱɚɧɢɟ. ȼ ɩɪɢɥɨɠɟɧɢɢ ɦɨɠɟɬ ɛɵɬɶ ɧɟɫɤɨɥɶɤɨ ɤɨɦɩɨɧɟɧɬɨɜɬɪɚɧɡɚɤɰɢɣ, ɩɨɷɬɨɦɭ ɤɚɠɞɵɣ ɧɚɛɨɪ ɞɚɧɧɵɯ ɦɨɠɟɬ ɫɭɳɟɫɬɜɨɜɚɬɶ ɜ ɤɨɧɬɟɤɫɬɟ ɫɜɨɟɣ ɫɨɛɫɬɜɟɧɧɨɣ, ɧɟɡɚɜɢɫɢɦɨɣ ɨɬ ɞɪɭɝɢɯ ɧɚɛɨɪɨɜ ɬɪɚɧɡɚɤɰɢɢ (ɞɥɹ ɷɬɨɝɨ ɇȾ ɫɥɟɞɭɟɬ ɫɜɹɡɵɜɚɬɶ ɫ ɪɚɡɧɵɦɢ IBTransaction). ɇɨ ɬɚɤ ɩɨɫɬɭɩɚɬɶ ɧɟɰɟɥɟɫɨɨɛɪɚɡɧɨ: ɬɪɚɧɡɚɤɰɢɢ ɭɞɨɛɧɨ ɩɪɢɦɟɧɹɬɶ ɞɥɹ ɫɨɝɥɚɫɨɜɚɧɧɨɝɨ ɢɡɦɟɧɟɧɢɹ ɧɟɫɤɨɥɶɤɢɯ ɇȾ. ȼɨ ɦɧɨɝɢɯ ɫɥɭɱɚɹɯ ɜ ɩɪɢɥɨɠɟɧɢɢ ɩɪɢɫɭɬɫɬɜɭɟɬ ɨɞɢɧ ɤɨɦɩɨɧɟɧɬ-ɬɪɚɧɡɚɤɰɢɹ ɞɥɹ ɜɫɟɯ ɇȾ. ɂɧɨɝɞɚ ɛɵɜɚɟɬ ɩɨɥɟɡɧɨ ɪɚɡɞɟɥɢɬɶ ɧɚɛɨɪɵ ɞɚɧɧɵɯ ɧɚ ɮɭɧɤɰɢɨɧɚɥɶɧɵɟ ɝɪɭɩɩɵ, ɢ ɞɥɹ ɤɚɠɞɨɣ ɝɪɭɩɩɵ ɨɩɪɟɞɟɥɢɬɶ ɫɜɨɣ ɤɨɦɩɨɧɟɧɬ-ɬɪɚɧɡɚɤɰɢɸ ɫɨ ɫɩɟɰɢɮɢɱɟɫɤɢɦɢ ɭɪɨɜɧɟɦ ɢɡɨɥɹɰɢɢ ɢ ɪɟɠɢɦɨɦ ɛɥɨɤɢɪɨɜɨɤ. ɋɬɚɪɬɭɟɬ ɬɪɚɧɡɚɤɰɢɹ ɜɵɡɨɜɨɦ ɦɟɬɨɞɚ StartTransaction ɢɥɢ ɭɫɬɚɧɨɜɤɨɣ ɫɜɨɣɫɬɜɚ ɤɨɦɩɨɧɟɧɬɚ TIBTransaction Active := True. ȿɫɥɢ ɷɬɨɝɨ ɧɟ ɞɟɥɚɬɶ, ɬɨ ɡɚɩɭɫɤ ɬɪɚɧɡɚɤɰɢɢ ɩɪɨɢɡɨɣɞɟɬ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɪɢ ɚɤɬɢɜɢɡɚɰɢɢ ɫɨɟɞɢɧɟɧɢɹ, ɩɪɨɢɫɯɨɞɹɳɟɣ ɩɪɢ ɨɬɤɪɵɬɢɢ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ, ɫɜɹɡɚɧɧɵɯ ɫ ɤɨɦɩɨɧɟɧɬɨɦ IBTransaction, ɧɚɩɪɢɦɟɪ, ɩɪɢ ɜɵɡɨɜɟ tbCust.Open. 34
ȼɥɨɠɟɧɧɵɟ ɬɪɚɧɡɚɤɰɢɢ ɧɟ ɞɨɩɭɫɤɚɸɬɫɹ. ɉɨɷɬɨɦɭ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɞɟɣɫɬɜɢɣ if Not tIB.Active then tIB.StartTransaction; // ɋɬɚɪɬ ɬɪɚɧɡɚɤɰɢɢ tCustomers.Open // Ɉɬɤɪɵɬɢɟ ɇȾ
ɩɪɚɜɢɥɶɧɚ, ɚ tCustomers.Open // Ɉɬɤɪɵɬɢɟ ɇȾ ɢ ɫɬɚɪɬ ɬɪɚɧɡɚɤɰɢɢ, // ɟɫɥɢ ɨɧɚ ɧɟ ɚɤɬɢɜɧɚ tIB.StartTransaction; // ɋɬɚɪɬ ɬɪɚɧɡɚɤɰɢɢ
ɩɪɢɜɟɞɟɬ ɤ ɨɲɢɛɤɟ ɫ ɫɨɨɛɳɟɧɢɟɦ “Transaction is active”. ɋɥɟɞɭɟɬ ɨɛɹɡɚɬɟɥɶɧɨ ɩɪɨɜɟɪɹɬɶ, ɧɟ ɡɚɩɭɳɟɧɚ ɥɢ ɪɚɧɟɟ ɬɪɚɧɡɚɤɰɢɹ ɞɪɭɝɢɦɢ ɫɩɨɫɨɛɚɦɢ. Ⱦɥɹ ɷɬɨɣ ɰɟɥɢ ɫɥɭɠɢɬ ɫɜɨɣɫɬɜɨ ɤɨɦɩɨɧɟɧɬɚ IBTransaction property InTransaction: Boolean
ɢɥɢ ɪɚɫɫɦɨɬɪɟɧɧɨɟ ɪɚɧɟɟ ɫɜɨɣɫɬɜɨ Active. ɉɪɨɜɟɪɢɜ ɟɝɨ ɡɧɚɱɟɧɢɟ, ɦɨɠɧɨ ɫɢɝɧɚɥɢɡɢɪɨɜɚɬɶ ɨɛ ɚɤɬɢɜɧɨɫɬɢ ɬɪɚɧɡɚɤɰɢɣ ɫɨɨɛɳɟɧɢɟɦ ɢ ɩɪɟɞɥɨɠɢɬɶ ɩɨɥɶɡɨɜɚɬɟɥɸ ɡɚɜɟɪɲɢɬɶ ɬɪɚɧɡɚɤɰɢɸ ɟɟ ɩɨɞɬɜɟɪɠɞɟɧɢɟɦ ɢɥɢ ɨɬɤɚɬɨɦ ɢɥɢ ɡɚɩɭɫɬɢɬɶ ɧɨɜɭɸ ɬɪɚɧɡɚɤɰɢɸ. ɋɭɳɟɫɬɜɭɟɬ ɞɜɚ ɦɟɬɨɞɚ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɣ – ɹɜɧɵɣ ɢ ɧɟɹɜɧɵɣ. əɜɧɵɣ ɦɟɬɨɞ ɢɫɩɨɥɶɡɭɟɬɫɹ ɩɨ ɭɦɨɥɱɚɧɢɸ. ɉɪɢ ɹɜɧɨɦ ɦɟɬɨɞɟ ɬɪɚɧɡɚɤɰɢɹ ɡɚɜɟɪɲɚɟɬɫɹ ɦɟɬɨɞɚɦɢ Commit, RollBack, CommitRetaining, RollBackRetainig ɤɨɦɩɨɧɟɧɬɚ IBTransaction. Ɇɟɬɨɞ Commit ɩɨɞɬɜɟɪɠɞɚɟɬ ɬɪɚɧɡɚɤɰɢɸ, ɚ ɦɟɬɨɞ RollBack ɨɬɤɚɬɵɜɚɟɬ. ɉɪɢ ɢɯ ɜɵɡɨɜɟ ɜɫɟ ɫɜɹɡɚɧɧɵɟ ɫ ɞɚɧɧɵɦ ɤɨɦɩɨɧɟɧɬɨɦ IBTransaction ɧɚɛɨɪɵ ɞɚɧɧɵɯ ɡɚɤɪɵɜɚɸɬɫɹ (Close), ɚ ɩɪɢ ɢɯ ɧɨɜɨɦ ɨɬɤɪɵɬɢɢ ɡɚɩɭɫɤɚɟɬɫɹ ɧɨɜɚɹ ɬɪɚɧɡɚɤɰɢɹ. Ɂɚɤɪɵɬɢɟ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ ɱɚɫɬɨ ɛɵɜɚɟɬ ɧɟɭɞɨɛɧɨ, ɬɚɤ ɤɚɤ, ɜɨ-ɩɟɪɜɵɯ, ɞɥɹ ɩɨɜɬɨɪɧɨɝɨ ɨɬɤɪɵɬɢɹ ɧɚɞɨ ɩɟɪɟɞɚɬɶ ɡɚɩɪɨɫ ɫɟɪɜɟɪɭ ɧɚ ɩɨɥɭɱɟɧɢɟ ɞɚɧɧɵɯ, ɢ ɜɨ-ɜɬɨɪɵɯ, ɬɟɪɹɟɬɫɹ ɭɤɚɡɚɬɟɥɶ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ (ɫɨɯɪɚɧɢɬɶ ɟɝɨ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɡɚɤɥɚɞɨɤ BookMark). ɑɬɨɛɵ ɧɟ ɩɟɪɟɨɬɤɪɵɜɚɬɶ ɇȾ, ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɸɬ ɦɟɬɨɞɵ CommitRetaining ɢ RollBackRetainig, ɪɚɛɨɬɚɸɳɢɟ ɚɧɚɥɨɝɢɱɧɨ ɦɟɬɨɞɚɦ Commit ɢ RollBack, ɧɨ ɧɟ ɡɚɜɟɪɲɚɸɳɢɟ ɬɪɚɧɡɚɤɰɢɸ: ɞɚɧɧɵɟ ɮɢɤɫɢɪɭɸɬɫɹ ɢɥɢ ɨɬɤɚɬɵɜɚɸɬɫɹ, ɬɪɚɧɡɚɤɰɢɹ ɨɫɬɚɟɬɫɹ ɚɤɬɢɜɧɨɣ, ɧɚɛɨɪɵ ɞɚɧɧɵɯ ɧɟ ɡɚɤɪɵɜɚɸɬɫɹ. ɇɚɱɢɧɚɸɳɢɣ ɩɪɨɝɪɚɦɦɢɫɬ, ɧɟ ɩɨɞɨɡɪɟɜɚɹ, ɱɬɨ ɬɪɚɧɡɚɤɰɢɹ ɫɬɚɪɬɭɟɬ ɩɪɢ ɨɬɤɪɵɬɢɢ ɇȾ, ɫɱɢɬɚɟɬ, ɱɬɨ ɟɫɥɢ StartTransaction ɨɧ ɧɟ ɜɵɡɵɜɚɟɬ, ɬɨ ɢ ɬɪɚɧɡɚɤɰɢɢ ɨɧ ɧɟ ɢɫɩɨɥɶɡɭɟɬ, ɢ ɩɨɷɬɨɦɭ ɧɟɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɜɵɡɵɜɚɬɶ Commit (ɢɥɢ ɞɪɭɝɢɟ ɦɟɬɨɞɵ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ). Ʉ ɫɟɪɶɟɡɧɵɦ ɨɲɢɛɤɚɦ ɷɬɨ, ɤɚɤ ɩɪɚɜɢɥɨ, ɧɟ ɩɪɢɜɨɞɢɬ, ɧɨ ɦɟɥɤɢɟ ɧɟɩɪɢɹɬɧɨɫɬɢ ɜɨɡɦɨɠɧɵ. ȼ ɨɬɫɭɬɫɬɜɢɟ Commit ɩɨɩɵɬɤɚ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ ɩɪɨɢɡɨɣɞɟɬ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɪɢ ɪɚɡɪɵɜɟ ɫɨɟɞɢɧɟɧɢɹ, ɩɪɨɢɫɯɨɞɹɳɟɦ ɩɟɪɟɞ ɡɚɜɟɪɲɟɧɢɟɦ ɩɪɨɝɪɚɦɦɵ. Ɂɚɬɹɧɭɜɲɚɹɫɹ ɬɪɚɧɡɚɤɰɢɹ ɧɟɢɡɛɟɠɧɨ ɩɨɪɨɠɞɚɟɬ ɩɪɨɛɥɟɦɵ ɩɪɢ 35
ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɣ ɪɚɛɨɬɟ, ɚ ɟɟ ɧɟɭɞɚɱɧɨɟ ɩɨɞɬɜɟɪɠɞɟɧɢɟ ɩɪɢ ɡɚɤɪɵɬɢɢ ɩɪɨɝɪɚɦɦɵ ɭɠɟ ɬɪɭɞɧɟɟ ɢɫɩɪɚɜɢɬɶ. ȿɫɥɢ ɠɟ ɩɪɨɝɪɚɦɦɚ «ɜɵɥɟɬɟɥɚ», ɧɟ ɞɨɠɞɚɜɲɢɫɶ ɡɚɜɟɪɲɟɧɢɹ, ɬɨ ɢɡɦɟɧɟɧɢɹ ɛɭɞɭɬ ɨɬɤɚɬɚɧɵ, ɬ. ɟ. ɩɨɬɟɪɹɧɵ. ɉɨɞɨɛɧɵɟ ɨɲɢɛɤɢ ɫɨɜɟɪɲɚɸɬ ɬɚɤɠɟ ɩɪɨɝɪɚɦɦɢɫɬɵ, ɢɦɟɸɳɢɟ ɨɩɵɬ ɪɚɛɨɬɵ ɜ BDE ɢɥɢ ADO. ȼ ɭɩɨɦɹɧɭɬɵɯ ɬɟɯɧɨɥɨɝɢɹɯ, ɜ ɨɬɥɢɱɢɟ ɨɬ ɪɚɫɫɦɚɬɪɢɜɚɟɦɨɣ, ɬɪɚɧɡɚɤɰɢɸ ɜɵɡɵɜɚɟɬ ɦɟɬɨɞ Post, ɟɫɥɢ ɟɟ ɪɚɦɤɢ ɧɟ ɭɤɚɡɚɧɵ ɹɜɧɨ ɦɟɬɨɞɚɦɢ StartTransaction … Commit. ɉɪɢ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɣ ɪɚɛɨɬɟ ɬɪɚɧɡɚɤɰɢɹ, ɨɛɧɨɜɥɹɸɳɚɹ ɞɚɧɧɵɟ, ɞɨɥɠɧɚ ɛɵɬɶ ɤɨɪɨɬɤɨɣ ɜɨ ɜɪɟɦɟɧɢ. Ⱦɚɠɟ ɩɪɢ ɛɥɚɝɨɩɪɢɹɬɧɨɦ ɬɟɱɟɧɢɢ ɡɚɬɹɧɭɜɲɟɣɫɹ ɬɪɚɧɡɚɤɰɢɢ ɫɥɢɲɤɨɦ ɱɚɫɬɨ ɩɪɨɢɫɯɨɞɹɬ ɤɨɧɮɥɢɤɬɵ ɢɡ-ɡɚ ɛɥɨɤɢɪɨɜɨɤ ɪɟɞɚɤɬɢɪɭɟɦɵɯ ɡɚɩɢɫɟɣ, ɱɢɬɚɸɬɫɹ ɭɫɬɚɪɟɜɲɢɟ (ɧɟɚɤɬɭɚɥɶɧɵɟ) ɡɚɩɢɫɢ, ɫɭɳɟɫɬɜɨɜɚɜɲɢɟ ɧɚ ɦɨɦɟɧɬ ɫɬɚɪɬɚ ɬɪɚɧɡɚɤɰɢɢ (ɩ. 3.3), ɚ ɨɬɫɥɟɠɢɜɚɧɢɟ ɜɟɪɫɢɣ ɡɚɩɢɫɟɣ, ɩɨɪɨɠɞɚɟɦɵɯ ɬɪɚɧɡɚɤɰɢɟɣ, ɡɚɦɟɞɥɹɟɬ ɪɚɛɨɬɭ ɫɟɪɜɟɪɚ. Ɂɚɦɟɱɚɧɢɟ. ȼɵɡɨɜ ɦɟɬɨɞɚ ExecSql ɤɨɦɩɨɧɟɧɬɨɜ TIBQuery ɢɥɢ TIBStoredProc, ɫɨɞɟɪɠɚɳɢɯ ɨɩɟɪɚɬɨɪ ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ, ɬɚɤɠɟ ɫɬɚɪɬɭɟɬ ɬɪɚɧɡɚɤɰɢɸ, ɟɫɥɢ ɨɧɚ ɧɟ ɛɵɥɚ ɚɤɬɢɜɧɚ, ɧɨ ɧɟ ɡɚɜɟɪɲɚɟɬ ɟɟ. ɉɨɷɬɨɦɭ ɜɵɡɨɜ Commit ɡɞɟɫɶ ɬɚɤɠɟ ɧɟɨɛɯɨɞɢɦ. ɉɪɢ ɧɟɹɜɧɨɦ ɡɚɜɟɪɲɟɧɢɢ ɬɪɚɧɡɚɤɰɢɹ ɩɟɪɟɫɬɚɟɬ ɛɵɬɶ ɚɤɬɢɜɧɨɣ (ɩɨɞɬɜɟɪɠɞɚɟɬɫɹ ɢɥɢ ɨɬɤɚɬɵɜɚɟɬɫɹ) ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɨɫɥɟ ɡɚɤɪɵɬɢɹ ɩɨɫɥɟɞɧɟɝɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ, ɫɜɹɡɚɧɧɨɝɨ ɫ ɤɨɦɩɨɧɟɧɬɨɦ IBTransaction. Ɇɟɬɨɞɵ Commit ɢ ɚɧɚɥɨɝɢɱɧɵɟ ɜɵɡɵɜɚɬɶ ɭɠɟ ɧɟɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ. Ɇɟɬɨɞ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ ɡɚɞɚɟɬɫɹ ɜ ɤɨɦɩɨɧɟɧɬɟ IBTransaction ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜɚ property AutoStopAction: TAutoStopAction;
Ɂɧɚɱɟɧɢɟ
saNone ɨɡɧɚɱɚɟɬ ɹɜɧɨɟ ɡɚɜɟɪɲɟɧɢɟ (ɡɚɞɚɧɨ ɩɨ ɭɦɨɥɱɚɧɢɸ); saRollback – ɧɟɹɜɧɵɣ ɨɬɤɚɬ ɩɪɢ ɡɚɤɪɵɬɢɢ ɇȾ; saCommit – ɧɟɹɜɧɨɟ ɩɨɞɬɜɟɪɠɞɟɧɢɟ ɩɪɢ ɡɚɤɪɵɬɢɢ ɇȾ; saRollbackRetaining – ɬɪɚɧɡɚɤɰɢɹ ɧɟ ɡɚɜɟɪɲɚɟɬɫɹ ɩɪɢ ɡɚɤɪɵɬɢɢ ɇȾ, ɧɨ ɜɫɟ ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ ɧɟ ɫɨɯɪɚɧɹɸɬɫɹ; saCommitRetaining – ɬɪɚɧɡɚɤɰɢɹ ɧɟ ɡɚɜɟɪɲɚɟɬɫɹ ɩɪɢ ɡɚɤɪɵɬɢɢ ɇȾ, ɧɨ ɜɫɟ ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ ɫɨɯɪɚɧɹɸɬɫɹ. 3.3. ɉɚɪɚɦɟɬɪɵ ɬɪɚɧɡɚɤɰɢɣ
ɉɟɪɟɞ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɬɪɚɧɡɚɤɰɢɢ ɧɟɨɛɯɨɞɢɦɨ ɧɚɫɬɪɨɢɬɶ ɟɟ ɩɚɪɚɦɟɬɪɵ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɜɵɩɨɥɧɹɟɦɨɣ ɡɚɞɚɱɟɣ. Ʉ ɩɚɪɚɦɟɬɪɚɦ ɬɪɚɧɡɚɤɰɢɣ ɨɬɧɨɫɹɬɫɹ: ɭɪɨɜɧɢ ɢɡɨɥɹɰɢɢ, ɪɟɠɢɦɵ ɞɨɫɬɭɩɚ, ɪɟɠɢɦɵ ɨɛɪɚɛɨɬɤɢ ɤɨɧɮɥɢɤɬɨɜ ɛɥɨɤɢɪɨɜɨɤ, ɪɟɠɢɦ ɛɥɨɤɢɪɨɜɤɢ ɬɚɛɥɢɰ. ɐɟɥɶ ɧɚɫɬɪɨɣɤɢ ɩɚɪɚɦɟɬɪɨɜ – ɨɩɪɟɞɟɥɢɬɶ ɩɨɜɟɞɟɧɢɟ ɬɪɚɧɡɚɤɰɢɢ ɩɪɢ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɣ ɪɚɛɨɬɟ. Ɉɫɧɨɜɧɵɦɢ ɩɪɨɛɥɟɦɚɦɢ, ɤɨɬɨɪɵɟ ɜɨɡɧɢ36
ɤɚɸɬ ɩɪɢ ɨɛɪɚɳɟɧɢɢ ɤ ɞɚɧɧɵɦ ɫɨ ɫɬɨɪɨɧɵ ɧɟɫɤɨɥɶɤɢɯ ɩɨɥɶɡɨɜɚɬɟɥɟɣ ɜ ɤɥɢɟɧɬ-ɫɟɪɜɟɪɧɨɣ ɫɪɟɞɟ, ɹɜɥɹɸɬɫɹ: ɧɟɫɨɝɥɚɫɨɜɚɧɧɨɟ ɱɬɟɧɢɟ, ɩɨɬɟɪɹɧɧɨɟ ɨɛɧɨɜɥɟɧɢɟ (ɤɨɥɥɢɡɢɹ «ɝɨɧɨɤ»), ɤɨɥɥɢɡɢɹ ɜɡɚɢɦɧɨɣ ɛɥɨɤɢɪɨɜɤɢ («ɬɭɩɢɤ»). 3.3.1. ɍɪɨɜɧɢ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ ɉɪɨɛɥɟɦɚ ɧɟɫɨɝɥɚɫɨɜɚɧɧɨɝɨ ɱɬɟɧɢɹ, ɡɚɤɥɸɱɚɸɳɚɹɫɹ ɜ ɩɨɥɭɱɟɧɢɢ ɧɟɩɪɟɞɫɤɚɡɭɟɦɵɯ ɢɥɢ ɧɟɞɨɫɬɨɜɟɪɧɵɯ ɪɟɡɭɥɶɬɚɬɨɜ ɩɪɢ ɱɬɟɧɢɢ ɞɚɧɧɵɯ, ɪɟɲɚɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɡɚɞɚɧɢɹ ɭɪɨɜɧɹ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ. ȼ ɢɞɟɚɥɟ, ɤɚɠɞɚɹ ɬɪɚɧɡɚɤɰɢɹ ɞɨɥɠɧɚ ɜɢɞɟɬɶ ɡɚɩɢɫɢ ɬɚɤ, ɤɚɤ ɛɭɞɬɨ ɧɢɤɚɤɢɟ ɞɪɭɝɢɟ ɬɪɚɧɡɚɤɰɢɢ ɞɚɧɧɵɟ ɧɟ ɦɟɧɹɸɬ. ɉɨɥɧɨɫɬɶɸ ɷɬɨɝɨ ɦɨɠɧɨ ɞɨɛɢɬɶɫɹ ɬɨɥɶɤɨ ɛɥɨɤɢɪɨɜɤɨɣ ɬɚɛɥɢɰ ɩɪɢ ɱɬɟɧɢɢ ɞɚɧɧɵɯ: ɞɪɭɝɢɟ ɬɪɚɧɡɚɤɰɢɢ ɧɟ ɫɦɨɝɭɬ ɢɡɦɟɧɹɬɶ ɞɚɧɧɵɟ, ɱɢɬɚɟɦɵɟ ɤɚɤɨɣ-ɥɢɛɨ ɬɪɚɧɡɚɤɰɢɟɣ. ɇɨ ɩɨ ɫɨɨɛɪɚɠɟɧɢɹɦ ɷɮɮɟɤɬɢɜɧɨɫɬɢ ɞɟɥɚɬɶ ɷɬɨ ɧɟ ɫɥɟɞɭɟɬ – ɬɪɚɧɡɚɤɰɢɢ ɝɨɪɚɡɞɨ ɱɚɳɟ ɱɢɬɚɸɬ, ɱɟɦ ɩɢɲɭɬ. ɉɨɷɬɨɦɭ ɛɥɨɤɢɪɨɜɤɢ ɢɫɩɨɥɶɡɭɸɬɫɹ ɜ ɨɫɧɨɜɧɨɦ ɩɪɢ ɡɚɩɢɫɢ, ɚ ɩɪɢ ɱɬɟɧɢɢ ɩɪɢɦɟɧɹɸɬɫɹ ɤɨɦɩɪɨɦɢɫɫɧɵɟ ɜɚɪɢɚɧɬɵ, ɧɚɡɵɜɚɟɦɵɟ ɭɪɨɜɧɹɦɢ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɢ. ȼ ɫɬɚɧɞɚɪɬɟ ANSI SQL-92 ɨɩɪɟɞɟɥɟɧɵ 4 ɭɪɨɜɧɹ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ: x Dirty Read – «ɝɪɹɡɧɨɟ» ɱɬɟɧɢɟ. Ɍɪɚɧɡɚɤɰɢɹ ɦɨɠɟɬ ɱɢɬɚɬɶ ɧɟ ɩɨɞɬɜɟɪɠɞɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ, ɫɞɟɥɚɧɧɵɟ ɜ ɞɪɭɝɢɯ ɬɪɚɧɡɚɤɰɢɹɯ. Ɏɚɤɬɢɱɟɫɤɢ ɨɡɧɚɱɚɟɬ ɨɬɫɭɬɫɬɜɢɟ ɢɡɨɥɹɰɢɢ ɢ ɦɨɠɟɬ ɩɪɢɜɨɞɢɬɶ ɤ ɱɬɟɧɢɸ ɧɟɞɨɫɬɨɜɟɪɧɵɯ ɞɚɧɧɵɯ. ɇɚɩɪɢɦɟɪ, ɬɪɚɧɡɚɤɰɢɹ Ⱥ ɡɚɩɢɫɚɥɚ ɞɚɧɧɵɟ, ɧɨ ɧɟ ɩɨɞɬɜɟɪɞɢɥɚ ɢɯ. Ⱦɚɥɟɟ ɬɟ ɠɟ ɫɚɦɵɟ ɞɚɧɧɵɟ ɱɢɬɚɟɬ ɬɪɚɧɡɚɤɰɢɹ Ȼ, ɜɵɩɨɥɧɹɟɬ ɧɚ ɢɯ ɨɫɧɨɜɟ ɤɚɤɢɟ-ɬɨ ɞɟɣɫɬɜɢɹ, ɧɨ ɜ ɷɬɨ ɜɪɟɦɹ ɬɪɚɧɡɚɤɰɢɹ Ⱥ ɨɬɤɚɬɵɜɚɟɬɫɹ. ȼ ɪɟɡɭɥɶɬɚɬɟ ɬɪɚɧɡɚɤɰɢɹ Ȼ ɢɫɩɨɥɶɡɭɟɬ ɧɟɞɨɫɬɨɜɟɪɧɵɟ ɞɚɧɧɵɟ, ɤɨɬɨɪɵɯ ɧɟɬ ɜ ɛɚɡɟ. x
Read Committed – ɩɨɞɬɜɟɪɠɞɟɧɧɨɟ ɱɬɟɧɢɟ (ɧɚɢɛɨɥɟɟ ɩɪɢɟɦɥɟɦɵɣ ɤɨɦɩɪɨɦɢɫɫ). Ɍɪɚɧɡɚɤɰɢɹ ɦɨɠɟɬ ɱɢɬɚɬɶ ɬɨɥɶɤɨ ɬɟ ɢɡɦɟɧɟɧɢɹ, ɤɨɬɨɪɵɟ ɛɵɥɢ ɩɨɞɬɜɟɪɠɞɟɧɵ ɞɪɭɝɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ. Ɉɞɧɚɤɨ ɩɪɢ ɩɨɜɬɨɪɧɨɦ ɱɬɟɧɢɢ ɞɚɧɧɵɯ ɜ ɬɟɱɟɧɢɟ ɨɞɧɨɣ ɬɪɚɧɡɚɤɰɢɢ ɦɨɝɭɬ ɩɨɥɭɱɚɬɶɫɹ ɪɚɡɧɵɟ ɪɟɡɭɥɶɬɚɬɵ. ɇɚɩɪɢɦɟɪ, ɟɫɥɢ ɩɨɫɥɟ ɫɬɚɪɬɚ ɬɪɚɧɡɚɤɰɢɢ A ɤɨɧɤɭɪɢɪɭɸɳɚɹ ɬɪɚɧɡɚɤɰɢɹ Ȼ ɢɡɦɟɧɢɥɚ ɢ ɩɨɞɬɜɟɪɞɢɥɚ ɞɚɧɧɵɟ, ɚ ɬɪɚɧɡɚɤɰɢɹ Ⱥ ɟɳɟ ɪɚɡ ɢɯ ɩɪɨɱɢɬɚɥɚ.
x
Repeatable Read – ɩɨɜɬɨɪɹɟɦɨɟ ɱɬɟɧɢɟ. Ɍɪɚɧɡɚɤɰɢɹ ɜɢɞɢɬ ɬɨɥɶɤɨ ɬɟ ɩɨɞɬɜɟɪɠɞɟɧɧɵɟ ɞɚɧɧɵɟ, ɤɨɬɨɪɵɟ ɫɭɳɟɫɬɜɨɜɚɥɢ ɧɚ ɦɨɦɟɧɬ ɟɟ ɫɬɚɪɬɚ. Ɇɨɠɟɬ ɜɢɞɟɬɶ «ɮɚɧɬɨɦɵ» – ɜɧɨɜɶ ɜɫɬɚɜɥɟɧɧɵɟ ɞɪɭɝɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ ɫɬɪɨɤɢ.
x
Serialized – ɫɟɪɢɚɥɢɡɭɟɦɨɫɬɶ. ɇɚɢɛɨɥɟɟ ɠɟɫɬɤɢɣ ɭɪɨɜɟɧɶ ɢɡɨɥɹɰɢɢ. Ɍɪɚɧɡɚɤɰɢɹ ɜɵɩɨɥɧɹɸɬɫɹ ɬɚɤ, ɤɚɤ ɛɭɞɬɨ ɧɢɤɚɤɢɯ ɞɪɭɝɢɯ ɬɪɚɧɡɚɤɰɢɣ ɜ ɷɬɨɬ ɦɨɦɟɧɬ ɧɟ ɫɭɳɟɫɬɜɭɟɬ. 37
InterBase ɩɨɞɞɟɪɠɢɜɚɟɬ ɩɟɪɟɱɢɫɥɟɧɧɵɟ ɭɪɨɜɧɢ ɜ ɧɟɫɤɨɥɶɤɨ ɢɡɦɟɧɟɧɧɨɦ ɜɢɞɟ: x READ COMMITTED RECORD_VERSION; x READ COMMITTED NO RECORD_VERSION; x SNAPSHOT; x SNAPSHOT TABLE STABILITY. «Ƚɪɹɡɧɨɟ» ɱɬɟɧɢɟ ɜ InterBase ɧɟ ɞɨɩɭɫɤɚɟɬɫɹ. ɉɟɪɜɵɟ ɞɜɚ ɭɪɨɜɧɹ ɩɪɢɛɥɢɡɢɬɟɥɶɧɨ ɫɨɨɬɜɟɬɫɬɜɭɸɬ Read Committed, ɧɨ ɞɨɩɨɥɧɢɬɟɥɶɧɨ ɪɟɝɭɥɢɪɭɸɬɫɹ ɞɜɭɦɹ ɧɟɨɛɹɡɚɬɟɥɶɧɵɦɢ ɩɚɪɚɦɟɬɪɚɦɢ [2]. RECORD VERSION (ɩɪɢɧɢɦɚɟɬɫɹ ɩɨ ɭɦɨɥɱɚɧɢɸ) ɱɢɬɚɟɬ ɫɚɦɭɸ ɩɨɫɥɟɞɧɸɸ ɩɨɞɬɜɟɪɠɞɟɧɧɭɸ ɜɟɪɫɢɸ ɫɬɪɨɤɢ, ɞɚɠɟ ɟɫɥɢ ɟɫɬɶ ɛɨɥɟɟ ɩɨɡɞɧɹɹ, ɧɨ ɧɟɩɨɞɬɜɟɪɠɞɟɧɧɚɹ ɜɟɪɫɢɹ. NO RECORD VERSION ɱɢɬɚɟɬ ɬɨɥɶɤɨ ɫɚɦɭɸ ɩɨɫɥɟɞɧɸɸ ɜɟɪɫɢɸ ɡɚɩɢɫɢ, ɞɨɫɬɭɩ ɤ ɨɫɬɚɥɶɧɵɦ ɜɟɪɫɢɹɦ ɡɚɩɪɟɳɟɧ. ȿɫɥɢ ɡɚɞɚɧɚ ɨɩɰɢɹ WAIT, ɬɨ ɬɪɚɧɡɚɤɰɢɹ ɠɞɟɬ, ɩɨɤɚ ɫɚɦɚɹ ɩɨɫɥɟɞɧɹɹ ɜɟɪɫɢɹ ɫɬɪɨɤɢ ɧɟ ɛɭɞɟɬ ɩɨɞɬɜɟɪɠɞɟɧɚ ɢɥɢ ɨɬɦɟɧɟɧɚ ɦɨɞɢɮɢɰɢɪɨɜɚɜɲɟɣ ɟɟ ɬɪɚɧɡɚɤɰɢɟɣ. ɍɪɨɜɟɧɶ SNAPSHOT – ɭɫɢɥɟɧɧɵɣ Repeatable Read, ɩɪɢɛɥɢɠɚɸɳɢɣɫɹ ɩɨ ɫɬɪɨɝɨɫɬɢ ɤ Serialized [2]. Ⱦɟɣɫɬɜɭɟɬ ɩɨ ɭɦɨɥɱɚɧɢɸ. Ȼɥɨɤɢɪɨɜɤɢ ɧɟ ɢɫɩɨɥɶɡɭɸɬɫɹ. ɍɪɨɜɟɧɶ SNAPSHOT TABLE STABILITY ɜ ɞɨɩɨɥɧɟɧɢɟ ɤ SNAPSHOT ɛɥɨɤɢɪɭɟɬ ɬɚɛɥɢɰɭ ɧɚ ɡɚɩɢɫɶ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɜ InterBase ɱɢɬɚɸɳɚɹ ɬɪɚɧɡɚɤɰɢɹ ɧɟ ɛɥɨɤɢɪɭɟɬ ɨɛɧɨɜɥɟɧɢɟ ɫɨ ɫɬɨɪɨɧɵ ɨɫɬɚɥɶɧɵɯ ɬɪɚɧɡɚɤɰɢɣ (ɡɚ ɢɫɤɥɸɱɟɧɢɟɦ SNAPSHOT TABLE STABILITY). ȼɫɟ ɭɪɨɜɧɢ ɢɡɨɥɹɰɢɢ ɢɦɟɸɬ ɞɨɩɨɥɧɢɬɟɥɶɧɵɟ ɪɟɠɢɦɵ ɞɨɫɬɭɩɚ: ɬɨɥɶɤɨ ɧɚ ɱɬɟɧɢɟ (READ ONLY) ɢɥɢ ɧɚ ɱɬɟɧɢɟ ɢ ɡɚɩɢɫɶ (READ WRITE). Ɍɪɚɧɡɚɤɰɢɢ ɬɨɥɶɤɨ ɧɚ ɱɬɟɧɢɟ ɜɵɩɨɥɧɹɸɬɫɹ ɛɵɫɬɪɟɟ, ɩɨɬɨɦɭ ɱɬɨ ɫɟɪɜɟɪɭ ɧɟ ɬɪɟɛɭɟɬɫɹ ɨɬɫɥɟɠɢɜɚɬɶ ɜɨɡɦɨɠɧɵɟ ɢɡɦɟɧɟɧɢɹ ɜ ȻȾ ɞɥɹ ɨɛɧɚɪɭɠɟɧɢɹ ɤɨɧɮɥɢɤɬɨɜ ɫ ɞɪɭɝɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ. ɉɨ ɭɦɨɥɱɚɧɢɸ ɭɫɬɚɧɨɜɥɟɧ ɪɟɠɢɦ READ WRITE.
3.3.2. Ȼɥɨɤɢɪɨɜɤɢ ȼ InterBase ɛɥɨɤɢɪɨɜɤɢ, ɜ ɨɫɧɨɜɧɨɦ, ɢɫɩɨɥɶɡɭɸɬɫɹ ɞɥɹ ɪɟɲɟɧɢɹ ɩɪɨɛɥɟɦɵ ɩɨɬɟɪɹɧɧɨɝɨ ɨɛɧɨɜɥɟɧɢɹ. ɗɬɚ ɩɪɨɛɥɟɦɚ ɜɨɡɧɢɤɚɟɬ ɩɪɢ ɨɞɧɨɜɪɟɦɟɧɧɨɦ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ ɨɞɧɨɣ ɡɚɩɢɫɢ ɧɟɫɤɨɥɶɤɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ ɢ ɩɪɢɜɨɞɢɬ ɤ ɤɨɥɥɢɡɢɢ «ɝɨɧɨɤ». ɇɚɩɪɢɦɟɪ, ɧɚ ɫɤɥɚɞɟ ɛɵɥɨ 10 ɟɞɢɧɢɰ ɬɨɜɚɪɚ. Ɍɪɚɧɡɚɤɰɢɹ Ⱥ ɤɭɩɢɥɚ 2 ɟɞɢɧɢɰɵ ɬɨɜɚɪɚ, ɧɨ ɟɳɟ ɧɟ ɩɨɞɬɜɟɪɞɢɥɚ ɡɚɩɢɫɶ. ȼ ɷɬɨ ɜɪɟɦɹ ɬɪɚɧɡɚɤɰɢɹ Ȼ ɤɭɩɢɥɚ 5 ɟɞɢɧɢɰ. ȿɫɥɢ ɩɨɫɥɟɞɧɟɣ ɩɨɞɬɜɟɪɞɢɬ ɡɚɤɚɡ Ⱥ, ɬɨ ɢɡɦɟɧɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ Ȼ ɛɭɞɭɬ ɭɬɟɪɹɧɵ ɢ ɧɚ ɫɤɥɚɞɟ ɨɫɬɚɧɟɬɫɹ 8 ɲɬɭɤ, ɚ ɟɫɥɢ ɩɨɫɥɟɞɧɟɣ ɩɨɞɬɜɟɪɞɢɬ Ȼ – ɬɨ 5. Ɍɚɤɢɟ ɫɢɬɭɚɰɢɢ ɧɟɞɨɩɭɫɬɢɦɵ, ɬɚɤ ɤɚɤ ɧɚ ɫɚɦɨɦ ɞɟɥɟ ɨɫɬɚɬɨɤ ɞɨɥɠɟɧ ɛɵɬɶ ɪɚɜɟɧ 10 – 5 – 2 = 3. Ɇɧɨɝɨɜɟɪɫɢ38
ɨɧɧɨɫɬɶ InterBase ɡɞɟɫɶ ɧɟ ɫɩɚɫɚɟɬ. ȼɵɯɨɞ ɨɞɢɧ – ɧɟ ɪɚɡɪɟɲɚɬɶ ɬɪɚɧɡɚɤɰɢɹɦ ɩɚɪɚɥɥɟɥɶɧɨ ɢɡɦɟɧɹɬɶ ɨɞɧɭ ɢ ɬɭ ɠɟ ɡɚɩɢɫɶ. Ⱦɨɩɭɫɤɚɟɬɫɹ ɬɨɥɶɤɨ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɟ ɪɟɞɚɤɬɢɪɨɜɚɧɢɟ ɞɚɧɧɵɯ. ɗɬɨ ɨɡɧɚɱɚɟɬ, ɱɬɨ ɩɪɢ ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ (ɬ. ɟ. ɩɪɢ ɜɵɩɨɥɧɟɧɢɢ ɡɚɩɪɨɫɨɜ INSERT, UPDATE, DELETE) ɡɚɩɢɫɶ ɛɥɨɤɢɪɭɟɬɫɹ ɢ ɤɨɧɤɭɪɢɪɭɸɳɚɹ ɩɢɲɭɳɚɹ ɬɪɚɧɡɚɤɰɢɹ ɨɠɢɞɚɟɬ ɫɜɨɟɣ ɨɱɟɪɟɞɢ, ɩɨɤɚ ɩɟɪɜɚɹ ɬɪɚɧɡɚɤɰɢɹ ɧɟ ɡɚɜɟɪɲɢɬɫɹ. Ɂɚɦɟɱɚɧɢɟ. ȼ ɧɟɤɨɬɨɪɵɯ ɞɪɭɝɢɯ ɫɟɪɜɟɪɚɯ ȻȾ, ɧɟ ɩɨɞɞɟɪɠɢɜɚɸɳɢɯ ɦɧɨɝɨɜɟɪɫɢɨɧɧɨɫɬɶ ɡɚɩɢɫɟɣ, ɧɚɩɪɢɦɟɪ SQL Server 2000, ɛɥɨɤɢɪɨɜɤɢ ɢɫɩɨɥɶɡɭɸɬɫɹ ɬɚɤɠɟ ɢ ɞɥɹ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ. ɉɪɢ ɱɬɟɧɢɢ ɡɚɩɢɫɶ ɛɥɨɤɢɪɭɟɬɫɹ, ɩɪɢ ɷɬɨɦ ɜɫɟ ɨɫɬɚɥɶɧɵɟ ɬɪɚɧɡɚɤɰɢɢ ɧɟ ɦɨɝɭɬ ɟɟ ɢɡɦɟɧɢɬɶ ɢ ɠɞɭɬ, ɩɨɤɚ ɡɚɩɢɫɶ ɧɟ ɛɭɞɟɬ ɩɨɞɬɜɟɪɠɞɟɧɚ, ɱɬɨ ɫɧɢɠɚɟɬ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɶ ɫɟɪɜɟɪɚ. ȼ ɦɧɨɝɨɜɟɪɫɢɨɧɧɨɣ ɚɪɯɢɬɟɤɬɭɪɟ ɱɢɬɚɸɳɢɟ ɬɪɚɧɡɚɤɰɢɢ ɨɛɵɱɧɨ ɧɟ ɛɥɨɤɢɪɭɸɬ ɩɢɲɭɳɢɟ. ɉɢɲɭɳɢɟ ɬɪɚɧɡɚɤɰɢɢ ɬɚɤɠɟ ɧɟ ɛɥɨɤɢɪɭɸɬ ɱɢɬɚɸɳɢɯ, ɩɨɫɥɟɞɧɢɟ ɫɩɨɤɨɣɧɨ ɱɢɬɚɸɬ ɞɪɭɝɭɸ ɩɨɞɬɜɟɪɠɞɟɧɧɭɸ ɜɟɪɫɢɸ ɡɚɩɢɫɢ. ɂ ɯɨɬɹ ɩɨɞɞɟɪɠɤɚ ɦɧɨɝɨɜɟɪɫɢɨɧɧɨɫɬɢ ɧɟ ɨɛɯɨɞɢɬɫɹ ɛɟɡ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ ɜɪɟɦɟɧɧɵɯ ɡɚɬɪɚɬ, ɞɚɧɧɵɣ ɩɨɞɯɨɞ ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɩɪɢɡɧɚɧ ɜ ɰɟɥɨɦ ɛɨɥɟɟ ɷɮɮɟɤɬɢɜɧɵɦ ɢ ɢɫɩɨɥɶɡɭɟɬɫɹ (ɜ ɪɚɡɧɵɯ ɪɟɚɥɢɡɚɰɢɹɯ) ɜ SQL Server 2005 ɢ Oracle. ȼ InterBase ɫɭɳɟɫɬɜɭɸɬ ɞɜɚ ɪɟɠɢɦɚ ɨɛɪɚɛɨɬɤɢ ɤɨɧɮɥɢɤɬɨɜ ɛɥɨɤɢɪɨɜɨɤ WAIT (ɫ ɨɠɢɞɚɧɢɟɦ) ɢ NO WAIT (ɛɟɡ ɨɠɢɞɚɧɢɹ). ȿɫɥɢ ɬɪɚɧɡɚɤɰɢɹ ɫɬɚɪɬɭɟɬ ɜ ɪɟɠɢɦɟ WAIT (ɩɨ ɭɦɨɥɱɚɧɢɸ) ɢ ɩɪɢ ɜɵɩɨɥɧɟɧɢɢ ɨɩɟɪɚɰɢɢ ɨɛɧɚɪɭɠɢɜɚɟɬɫɹ ɤɨɧɮɥɢɤɬ, ɬɨ ɨɩɟɪɚɰɢɹ ɩɪɢɨɫɬɚɧɚɜɥɢɜɚɟɬɫɹ ɞɨ ɪɚɡɪɟɲɟɧɢɹ ɤɨɧɮɥɢɤɬɚ (ɧɚɩɪɢɦɟɪ, ɨɬɤɚɬɚ ɤɨɧɤɭɪɢɪɭɸɳɟɣ ɬɪɚɧɡɚɤɰɢɢ). ȼ ɫɥɭɱɚɟ ɛɨɥɟɟ ɫɥɨɠɧɨɣ ɫɢɬɭɚɰɢɢ ɜɡɚɢɦɨɛɥɨɤɢɪɨɜɤɢ ɞɜɭɯ ɨɠɢɞɚɸɳɢɯ ɬɪɚɧɡɚɤɰɢɣ (ɤɨɥɥɢɡɢɢ «ɬɭɩɢɤɚ») ɫɟɪɜɟɪ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɨɛɧɚɪɭɠɢɬ ɷɬɭ ɫɢɬɭɚɰɢɸ ɢ ɪɚɡɛɥɨɤɢɪɭɟɬ ɨɞɧɭ ɢɡ ɬɪɚɧɡɚɤɰɢɣ ɱɟɪɟɡ ɧɟɤɨɬɨɪɵɣ ɢɧɬɟɪɜɚɥ ɜɪɟɦɟɧɢ, ɪɚɜɧɵɣ ɩɨ ɭɦɨɥɱɚɧɢɸ 10 ɫɟɤɭɧɞɚɦ. ɇɚɩɨɦɧɢɦ ɤɨɥɥɢɡɢɸ ɬɭɩɢɤɚ (Deadlock). Ɍɪɚɧɡɚɤɰɢɹ Ⱥ ɛɥɨɤɢɪɭɟɬ ɡɚɩɢɫɶ 1 ɢ ɨɠɢɞɚɟɬ, ɤɨɝɞɚ ɨɫɜɨɛɨɞɢɬɫɹ ɡɚɩɢɫɶ 2. Ɂɚɩɢɫɶ 2 ɛɥɨɤɢɪɭɟɬɫɹ ɬɪɚɧɡɚɤɰɢɟɣ Ȼ, ɨɠɢɞɚɸɳɟɣ ɨɫɜɨɛɨɠɞɟɧɢɹ ɡɚɩɢɫɢ 1. ȼ ɪɟɡɭɥɶɬɚɬɟ ɨɛɟ ɬɪɚɧɡɚɤɰɢɢ «ɡɚɜɢɫɚɸɬ». ȼ ɪɟɠɢɦɟ NO WAIT ɫɨɨɛɳɟɧɢɟ ɨ ɤɨɧɮɥɢɤɬɟ ɜɵɞɚɟɬɫɹ ɩɪɢɥɨɠɟɧɢɸ ɧɟɦɟɞɥɟɧɧɨ (ɜɨɡɧɢɤɚɟɬ ɨɲɢɛɤɚ), ɚ ɨɩɟɪɚɰɢɹ, ɤɨɬɨɪɚɹ ɩɪɢɜɟɥɚ ɤ ɤɨɧɮɥɢɤɬɭ, ɨɬɦɟɧɹɟɬɫɹ. ɉɨɞ ɤɨɧɮɥɢɤɬɨɦ ɡɞɟɫɶ ɩɨɧɢɦɚɟɬɫɹ ɩɨɩɵɬɤɚ ɢɡɦɟɧɟɧɢɹ ɨɞɧɨɣ ɢ ɬɨɣ ɠɟ ɡɚɩɢɫɢ ɧɟɫɤɨɥɶɤɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ. ɇɚɩɪɢɦɟɪ, ɬɪɚɧɡɚɤɰɢɹ A ɢɡɦɟɧɢɥɚ ɡɚɩɢɫɶ, ɧɨ ɟɳɟ ɧɟ ɩɨɞɬɜɟɪɞɢɥɚ ɟɟ. Ɍɪɚɧɡɚɤɰɢɹ Ȼ ɩɵɬɚɟɬɫɹ ɢɡɦɟɧɢɬɶ ɢɥɢ ɭɞɚɥɢɬɶ ɷɬɭ ɠɟ ɡɚɩɢɫɶ. ȼ ɪɟɠɢɦɟ NO WAIT ɜ ɬɪɚɧɡɚɤɰɢɢ Ȼ ɩɪɨɢɫɯɨɞɢɬ ɧɟɦɟɞɥɟɧɧɚɹ ɜɵɞɚɱɚ ɨɲɢɛɤɢ. ȼ ɪɟɠɢɦɟ WAIT ɬɪɚɧɡɚɤɰɢɹ Ȼ ɩɟɪɟɯɨɞɢɬ ɜ ɫɨɫɬɨɹɧɢɟ ɨɠɢɞɚɧɢɹ ɢ ɨɲɢɛɤɚ ɜɨɡɧɢɤɧɟɬ, ɟɫɥɢ Ⱥ ɩɨɞɬɜɟɪɞɢɬ ɢɡɦɟɧɟɧɢɹ. ȿɫɥɢ ɬɪɚɧɡɚɤɰɢɢ Ⱥ ɨɬɤɚɬɢɬɫɹ, ɬɨ Ȼ ɫɦɨɠɟɬ ɩɨɞɬɜɟɪɞɢɬɶ ɫɜɨɢ ɢɡɦɟɧɟɧɢɹ. ȼɨɡɧɢɤɚɟɬ ɜɨɩɪɨɫ: ɩɨɱɟɦɭ Ȼ ɠɞɟɬ ɢɦɟɧɧɨ ɨɬɤɚɬɚ Ⱥ? ɇɟɥɶɡɹ ɥɢ ɨɬɪɟɞɚɤɬɢɪɨɜɚɬɶ ɡɚɩɢɫɶ ɩɨɫɥɟ ɩɪɢɦɟɧɟɧɢɹ Ⱥ? ɇɟɥɶɡɹ, ɬɚɤ ɤɚɤ ɩɪɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ 39
ɬɪɚɧɡɚɤɰɢɹ Ȼ ɞɨɥɠɧɚ ɡɚɧɨɜɨ ɧɚɣɬɢ ɢ ɩɟɪɟɱɢɬɚɬɶ ɢɡɦɟɧɢɜɲɭɸ ɡɚɩɢɫɶ. ɇɚɩɪɢɦɟɪ, ɟɫɥɢ ɧɭɠɧɚɹ ɡɚɩɢɫɶ ɨɤɚɡɚɥɚɫɶ ɭɞɚɥɟɧɚ ɬɪɚɧɡɚɤɰɢɟɣ Ⱥ ɢɥɢ ɩɨɦɟɧɹɥɚ ɡɧɚɱɟɧɢɹ ɤɥɸɱɟɜɵɯ ɩɨɥɟɣ, ɩɨ ɤɨɬɨɪɵɦ Ȼ ɩɪɨɢɡɜɨɞɢɥɚ ɩɨɢɫɤ. Ʉɨɧɮɥɢɤɬɵ ɜɨɡɧɢɤɚɸɬ ɬɚɤɠɟ ɩɪɢ ɜɫɬɚɜɤɟ ɡɚɩɢɫɟɣ. ɇɚɩɪɢɦɟɪ, ɬɪɚɧɡɚɤɰɢɹ Ⱥ ɜɫɬɚɜɢɥɚ ɡɚɩɢɫɶ, ɧɨ ɧɟ ɩɨɞɬɜɟɪɞɢɥɚ ɟɟ. Ɍɪɚɧɡɚɤɰɢɹ Ȼ ɩɵɬɚɟɬɫɹ ɜɫɬɚɜɢɬɶ ɡɚɩɢɫɶ ɫ ɬɟɦ ɠɟ ɡɧɚɱɟɧɢɟɦ ɩɟɪɜɢɱɧɨɝɨ ɤɥɸɱɚ. Ɉɲɢɛɤɚ ɜɵɞɚɟɬɫɹ ɩɨ ɬɚɤɨɦɭ ɠɟ ɚɥɝɨɪɢɬɦɭ, ɱɬɨ ɢ ɩɪɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ ɡɚɩɢɫɟɣ. ȼ ɨɛɨɢɯ ɫɥɭɱɚɹɯ ɨɲɢɛɤɢ ɜɨɡɧɢɤɚɸɬ ɜ ɬɪɚɧɡɚɤɰɢɢ Ȼ, ɤɨɬɨɪɚɹ ɢɡɦɟɧɹɟɬ ɞɚɧɧɵɟ ɩɨɡɞɧɟɟ. Ɉɲɢɛɤɢ ɞɨɥɠɧɵ ɛɵɬɶ «ɨɬɥɨɜɥɟɧɵ» ɧɚ ɭɪɨɜɧɟ ɤɥɢɟɧɬɫɤɨɝɨ ɩɪɢɥɨɠɟɧɢɹ ɫ ɩɨɦɨɳɶɸ ɤɨɧɫɬɪɭɤɰɢɢ ɨɛɪɚɛɨɬɤɢ ɢɫɤɥɸɱɢɬɟɥɶɧɵɯ ɫɢɬɭɚɰɢɣ try … except … end. ȼ ɤɨɧɰɟ ɫɟɤɰɢɢ try ɜɵɡɵɜɚɟɬɫɹ ɦɟɬɨɞ Commit ɤɨɦɩɨɧɟɧɬɚ IBTransaction, ɜ ɫɟɤɰɢɢ Except – ɦɟɬɨɞ RollBack. ɉɪɢɦɟɪɧɵɣ ɚɥɝɨɪɢɬɦ ɡɚɩɭɫɤɚ ɬɪɚɧɡɚɤɰɢɢ ɞɥɹ ɫɥɭɱɚɹ ɨɬɩɭɫɤɚ ɬɨɜɚɪɚ ɫɨ ɫɤɥɚɞɚ: if not ibtSklad.Active then ibtSklad.StartTransaction; // ɇɚɱɚɥɨ ɬɪɚɧɡɚɤɰɢɢ iqProducts.Open; iqOrders.Open; try ... // ȼɫɬɚɜɢɬɶ ɧɨɜɵɣ ɡɚɤɚɡ iqOrders.Post; ... // ɍɦɟɧɶɲɢɬɶ ɨɫɬɚɬɨɤ iqProductsRest.Value:=Ostatok-Otpusk; iqProducts.Post; ibtSklad.Commit; // Ɏɢɤɫɚɰɢɹ ɬɪɚɧɡɚɤɰɢɢ except ibtSklad.RollBack; // Ɉɬɤɚɬ ɬɪɚɧɡɚɤɰɢɢ ShowMessage('Ɉɲɢɛɤɚ ɬɪɚɧɡɚɤɰɢɢ!'); end;
Ɂɚɦɟɱɚɧɢɟ. Ɋɚɡɥɢɱɚɸɬ ɨɩɬɢɦɢɫɬɢɱɟɫɤɭɸ ɢ ɩɟɫɫɢɦɢɫɬɢɱɟɫɤɭɸ ɫɬɪɚɬɟɝɢɸ ɛɥɨɤɢɪɨɜɨɤ [3] . ɉɪɢ ɨɩɬɢɦɢɫɬɢɱɟɫɤɨɣ ɛɥɨɤɢɪɨɜɤɟ ɩɪɟɞɩɨɥɚɝɚɟɬɫɹ, ɱɬɨ ɤɨɧɮɥɢɤɬ, ɬ. ɟ. ɩɨɩɵɬɤɚ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɨɞɧɨɣ ɢ ɬɨɣ ɡɚɩɢɫɢ ɧɟɫɤɨɥɶɤɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ, ɦɚɥɨɜɟɪɨɹɬɟɧ. ɉɪɢ ɩɟɫɫɢɦɢɫɬɢɱɟɫɤɨɣ ɛɥɨɤɢɪɨɜɤɟ ɫɱɢɬɚɟɬɫɹ, ɱɬɨ ɤɨɧɮɥɢɤɬ ɧɟɢɡɛɟɠɟɧ, ɩɨɷɬɨɦɭ ɛɥɨɤɢɪɨɜɤɚ ɧɚɥɚɝɚɟɬɫɹ ɧɚ ɛɨɥɶɲɢɣ ɩɟɪɢɨɞ ɜɪɟɦɟɧɢ (ɨɛɵɱɧɨ ɡɚɩɢɫɢ ɛɥɨɤɢɪɭɸɬɫɹ ɭɠɟ ɩɪɢ ɢɯ ɱɬɟɧɢɢ), ɱɬɨ ɡɚɦɟɞɥɹɟɬ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɭɸ ɪɚɛɨɬɭ. Ɉɩɬɢɦɢɫɬɢɱɟɫɤɚɹ ɛɥɨɤɢɪɨɜɤɚ ɧɚɥɚɝɚɟɬɫɹ ɧɚ ɡɚɩɢɫɢ ɥɢɲɶ ɩɪɢ ɧɚɱɚɥɟ ɢɯ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ. ɇɟɞɨɫɬɚɬɤɨɦ ɨɩɬɢɦɢɫɬɢɱɟɫɤɨɣ ɛɥɨɤɢɪɨɜɤɢ ɹɜɥɹɟɬɫɹ ɧɟɨɛɯɨɞɢɦɨɫɬɶ ɩɨɜɬɨɪɧɨɝɨ ɜɵɩɨɥɧɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ, ɟɫɥɢ ɤɨɧɮɥɢɤɬ ɜɫɟ-ɬɚɤɢ ɩɪɨɢɡɨɲɟɥ. Ʉɚɤ ȼɵ ɭɠɟ ɩɨɧɹɥɢ, ɜ InterBase ɩɪɢ ɛɥɨɤɢɪɨɜɤɟ ɡɚɩɢɫɟɣ ɢɫɩɨɥɶɡɭɟɬɫɹ ɨɩɬɢɦɢɫɬɢɱɟɫɤɚɹ ɫɬɪɚɬɟɝɢɹ. Ɋɟɠɢɦɵ ɛɥɨɤɢɪɨɜɤɢ ɬɚɛɥɢɰ, ɩɨɡɜɨɥɹɸɳɢɟ ɛɥɨɤɢɪɨɜɚɬɶ ɧɟ ɨɬɞɟɥɶɧɵɟ ɡɚɩɢɫɢ, ɚ ɬɚɛɥɢɰɵ ɜ ɰɟɥɨɦ, ɢɫɩɨɥɶɡɭɸɬɫɹ ɪɟɠɟ, ɨɧɢ ɩɨɞɪɨɛɧɨ ɨɩɢɫɚɧɵ ɜ [2], ɡɞɟɫɶ ɦɵ ɢɯ ɪɚɫɫɦɚɬɪɢɜɚɬɶ ɧɟ ɛɭɞɟɦ. 40
3.3.3. ɇɚɫɬɪɨɣɤɚ ɩɚɪɚɦɟɬɪɨɜ ɬɪɚɧɡɚɤɰɢɣ ȼɫɟ ɪɚɫɫɦɨɬɪɟɧɧɵɟ ɜɵɲɟ ɪɟɠɢɦɵ ɪɚɛɨɬɵ ɬɪɚɧɡɚɤɰɢɢ ɭɤɚɡɵɜɚɸɬɫɹ ɩɪɢ ɟɟ ɨɩɪɟɞɟɥɟɧɢɢ ɤɨɦɚɧɞɨɣ ɹɡɵɤɚ SQL SET TRANSACTION. Ʉɨɦɚɧɞɚ SET TRANSACTION ɬɚɤɠɟ ɫɬɚɪɬɭɟɬ ɬɪɚɧɡɚɤɰɢɸ. Ɉɞɧɚɤɨ ɟɟ ɦɨɠɧɨ ɩɪɢɦɟɧɹɬɶ ɬɨɥɶɤɨ ɜɨ ɜɫɬɪɨɟɧɧɨɦ ɹɡɵɤɟ SQL ɜ ɩɪɨɝɪɚɦɦɚɯ (ɱɚɳɟ ɧɚɩɢɫɚɧɧɵɯ ɧɚ ɹɡɵɤɟ C), ɨɛɪɚɛɚɬɵɜɚɟɦɵɯ ɫɩɟɰɢɚɥɶɧɵɦ ɩɪɟɩɪɨɰɟɫɫɨɪɨɦ gpre. Ⱦɥɹ ɩɪɨɝɪɚɦɦ, ɧɚɩɢɫɚɧɧɵɯ ɧɚ Delphi, ɧɚɫɬɪɨɣɤɢ ɩɚɪɚɦɟɬɪɨɜ ɬɪɚɧɡɚɤɰɢɣ ɜɵɩɨɥɧɹɬɫɹ ɫ ɩɨɦɨɳɶɸ ɤɨɦɩɨɧɟɧɬɚ IBTransaction. Ⱦɜɨɣɧɨɣ ɳɟɥɱɨɤ ɩɨ ɤɨɦɩɨɧɟɧɬɭ ɨɬɤɪɵɜɚɟɬ ɪɟɞɚɤɬɨɪ ɬɪɚɧɡɚɤɰɢɣ (ɪɢɫ. 3.2). Ɂɞɟɫɶ ɜ ɨɤɧɟ Settings ɞɥɹ ɤɚɠɞɨɝɨ ɭɪɨɜɧɹ ɢɡɨɥɹɰɢɢ ɦɨɠɧɨ ɞɨɩɢɫɚɬɶ ɞɨɩɨɥɧɢɬɟɥɶɧɵɟ ɩɚɪɚɦɟɬɪɵ, ɤɨɬɨɪɵɟ ɛɭɞɭɬ ɯɪɚɧɢɬɶɫɹ ɜ ɫɜɨɣɫɬɜɟ Params: TStrings. Ʉɚɠɞɵɣ ɩɚɪɚɦɟɬɪ, ɩɪɟɞɫɬɚɜɥɟɧɧɵɣ ɤɨɧɫɬɚɧɬɨɣ, ɡɞɟɫɶ ɞɨɥɠɟɧ ɡɚɩɢɫɵɜɚɬɶɫɹ ɜ ɨɬɞɟɥɶɧɨɣ ɫɬɪɨɤɟ. ɍɪɨɜɧɢ ɢɡɨɥɹɰɢɢ ɨɛɨɡɧɚɱɚɸɬɫɹ ɤɨɧɫɬɚɧɬɚɦɢ Delphi: concurrency – ɭɪɨɜɟɧɶ SNAPSHOT; consistency – ɭɪɨɜɟɧɶ SNAPSHOT TABLE STABILITY; read_committed – ɭɪɨɜɟɧɶ READ COMMITTED. ȼɦɟɫɬɟ ɫ ɩɨɫɥɟɞɧɟɣ ɤɨɧɫɬɚɧɬɨɣ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ Rec_version ɢ No_Rec_version. Ⱦɥɹ ɨɛɨɡɧɚɱɟɧɢɹ ɪɟɠɢɦɨɜ ɞɨɫɬɭɩɚ ɫɥɭɠɚɬ ɤɨɧɫɬɚɧɬɵ: Read – ɪɟɠɢɦ READ ONLY; Write – ɪɟɠɢɦ READ WRITE.
Ɋɢɫ. 3.2. Ⱦɥɹ ɛɨɥɶɲɢɧɫɬɜɚ ɫɥɭɱɚɟɜ ɨɩɬɢɦɚɥɶɧɵɦ ɹɜɥɹɟɬɫɹ ɜɚɪɢɚɧɬ, ɩɪɟɞɫɬɚɜɥɟɧɧɵɣ ɧɚ ɪɢɫ. 3.2, ɫɨ ɫɥɟɞɭɸɳɢɦ ɧɚɛɨɪɨɦ ɩɚɪɚɦɟɬɪɨɜ: Read_commited, Rec_version, nowait. ɂɦɟɧɧɨ ɬɚɤɨɣ ɭɪɨɜɟɧɶ ɢɡɨɥɹɰɢɢ ɩɨɡɜɨɥɹɟɬ ɜɢɞɟɬɶ ɢɡɦɟɧɟɧɢɹ, ɩɪɨɢɡɜɨɞɢɦɵɟ ɞɪɭɝɢɦɢ ɬɪɚɧɡɚɤɰɢɹɦɢ (ɧɨ ɧɟ ɪɚɧɶɲɟ ɢɯ ɩɨɞɬɜɟɪɠɞɟɧɢɹ), ɧɟ ɡɚɝɪɭɠɚɬɶ ɫɟɪɜɟɪ ɞɥɢɬɟɥɶɧɵɦ ɤɨɩɢɪɨɜɚɧɢɟɦ ɫɬɚɪɵɯ ɜɟɪɫɢɣ (ɯɚɪɚɤɬɟɪɧɨɝɨ ɞɥɹ SNAPSHOT) ɢ ɦɢɧɢɦɚɥɶɧɨ ɤɨɧɮɥɢɤɬɨɜɚɬɶ ɩɪɢ ɨɛɧɨɜɥɟɧɢɢ ɢɥɢ ɭɞɚɥɟɧɢɢ ɞɚɧɧɵɯ. Ɋɟɠɢɦ ɞɨɫɬɭɩɚ read write ɡɞɟɫɶ ɧɟ ɭɤɚɡɚɧ, ɩɨɷɬɨɦɭ ɩɨ ɭɦɨɥɱɚɧɢɸ ɩɪɟɞɩɨɥɚɝɚɟɬɫɹ write. 41
ȿɫɥɢ ɠɟ ɧɢɱɟɝɨ ɧɟ ɭɤɚɡɵɜɚɬɶ ɜ IBTransaction.Params, ɬɨ ɩɨ ɭɦɨɥɱɚɧɢɸ ɛɭɞɟɬ ɞɟɣɫɬɜɨɜɚɬɶ ɭɪɨɜɟɧɶ SNAPSHOT ɫ ɩɚɪɚɦɟɬɪɨɦ WAIT. ɗɬɨ ɨɡɧɚɱɚɟɬ, ɱɬɨ ɬɪɚɧɡɚɤɰɢɹ ɫɬɚɪɬɭɟɬ ɜ ɪɟɠɢɦɟ ɛɨɥɟɟ ɠɟɫɬɤɨɣ ɢɡɨɥɹɰɢɢ ɢ, ɜɨɡɦɨɠɧɨ, ɛɭɞɟɬ «ɡɚɜɢɫɚɬɶ» ɩɪɢ ɤɨɧɮɥɢɤɬɚɯ ɨɛɧɨɜɥɟɧɢɹ ɡɚɩɢɫɟɣ. ɗɬɨɬ ɪɟɠɢɦ ɦɨɠɟɬ ɨɤɚɡɚɬɶɫɹ ɩɨɞɯɨɞɹɳɢɦ ɞɥɹ ɞɥɢɬɟɥɶɧɵɯ ɩɟɪɟɫɱɟɬɨɜ, ɤɨɝɞɚ ɩɪɨɢɡɜɨɞɢɬɫɹ ɧɟɫɤɨɥɶɤɨ ɩɪɨɯɨɞɨɜ ɩɨ ɨɞɧɨɣ ɢ ɬɨɣ ɠɟ ɬɚɛɥɢɰɟ ɩɪɢ ɧɟɛɨɥɶɲɨɦ ɤɨɥɢɱɟɫɬɜɟ ɨɛɧɨɜɥɟɧɢɣ ɢɥɢ ɭɞɚɥɟɧɢɣ, ɧɨ ɢ ɡɞɟɫɶ ɥɭɱɲɟ ɭɤɚɡɚɬɶ NOWAIT. ȿɫɥɢ ɠɟ ɩɪɢ ɷɬɨɦ ɜɨɨɛɳɟ ɧɟ ɬɪɟɛɭɟɬɫɹ ɧɢɤɚɤɢɯ ɦɨɞɢɮɢɤɚɰɢɣ ɞɚɧɧɵɯ (ɧɚɩɪɢɦɟɪ, ɦɵ ɮɨɪɦɢɪɭɟɦ ɨɬɱɟɬ), ɬɨ ɠɟɥɚɬɟɥɶɧɨ ɟɳɟ ɭɤɚɡɚɬɶ ɩɚɪɚɦɟɬɪ read, ɨɛɨɡɧɚɱɚɸɳɢɣ ɪɟɠɢɦ READ ONLY (ɬɨɥɶɤɨ ɞɥɹ ɱɬɟɧɢɹ). ɉɚɪɚɦɟɬɪɵ ɬɚɤɨɣ ɬɪɚɧɡɚɤɰɢɢ ɛɭɞɭɬ ɫɥɟɞɭɸɳɢɦɢ: Read, concurrency, nowait. ȿɫɥɢ ɬɪɚɧɡɚɤɰɢɹ ɫ ɩɚɪɚɦɟɬɪɚɦɢ Write, concurrency, nowait ɨɫɭɳɟɫɬɜɥɹɟɬ ɪɟɞɚɤɬɢɪɨɜɚɧɢɟ ɞɚɧɧɵɯ, ɬɨ ɨɧɚ ɞɨɥɠɧɚ ɛɵɬɶ ɦɚɤɫɢɦɚɥɶɧɨ ɤɨɪɨɬɤɨɣ (ɬ. ɟ. ɛɵɫɬɪɨɣ) [1]. Ɍɟɯɧɢɱɟɫɤɢ ɷɬɨ ɦɨɠɧɨ ɪɟɚɥɢɡɨɜɚɬɶ ɡɚɩɭɫɤɨɦ ɬɪɚɧɡɚɤɰɢɢ ɩɨɫɥɟ ɜɜɨɞɚ ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɢɯ ɞɚɧɧɵɯ, ɩɪɢɱɟɦ ɜ ɫɚɦɨɣ ɬɪɚɧɡɚɤɰɢɢ ɥɭɱɲɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ (ɤɨɦɩɨɧɟɧɬ IBStoredProc, ɩ. 3.5). Ɉɫɧɨɜɧɨɣ ɜɵɜɨɞ ɨɱɟɜɢɞɟɧ: ɧɚɛɨɪɵ ɞɚɧɧɵɯ, ɜɵɩɨɥɧɹɸɳɢɟ ɞɢɚɦɟɬɪɚɥɶɧɨ ɩɪɨɬɢɜɨɩɨɥɨɠɧɵɟ ɮɭɧɤɰɢɢ ɜ ɩɪɢɥɨɠɟɧɢɢ, ɫɥɟɞɭɟɬ ɫɜɹɡɵɜɚɬɶ ɫ ɪɚɡɧɵɦɢ ɤɨɦɩɨɧɟɧɬɚɦɢ IBTransaction, ɧɚɫɬɪɨɟɧɧɵɦɢ ɫɩɟɰɢɮɢɱɧɵɦ ɨɛɪɚɡɨɦ. Ʉɨɦɩɨɧɟɧɬ IBTransaction ɹɜɥɹɟɬɫɹ ɨɱɟɧɶ ɜɚɠɧɵɦ ɜ ɤɥɢɟɧɬɫɟɪɜɟɪɧɵɯ ɩɪɨɝɪɚɦɦɚɯ. Ʉ ɫɨɠɚɥɟɧɢɸ, ɪɚɛɨɬɚ ɫ ɧɢɦ ɩɥɨɯɨ ɨɫɜɟɳɟɧɚ ɜ ɥɢɬɟɪɚɬɭɪɟ ɢ ɜɵɡɵɜɚɟɬ ɦɧɨɝɨɱɢɫɥɟɧɧɵɟ ɜɨɩɪɨɫɵ ɧɚɱɢɧɚɸɳɢɯ ɩɪɨɝɪɚɦɦɢɫɬɨɜ. «ɇɟɞɨɝɨɜɨɪɤɢ» ɢ ɧɟɬɨɱɧɨɫɬɢ ɜɫɬɪɟɱɚɸɬɫɹ ɤɚɤ ɜɨ ɜɫɬɪɨɟɧɧɨɣ ɜ Delphi ɞɨɤɭɦɟɧɬɚɰɢɢ, ɬɚɤ ɢ ɜ ɫɟɪɶɟɡɧɵɯ ɤɧɢɝɚɯ [1, 2]. Ɉɬɜɟɬɢɬɶ ɧɚ ɦɧɨɝɢɟ ɜɨɩɪɨɫɵ ɧɚɦ ɩɨɦɨɠɟɬ ɫɥɟɞɭɸɳɚɹ ɥɚɛɨɪɚɬɨɪɧɚɹ ɪɚɛɨɬɚ.
42
3.4. Ʌɚɛɨɪɚɬɨɪɧɚɹ ɪɚɛɨɬɚ ɐɟɥɶ ɪɚɛɨɬɵ – ɩɪɨɞɟɦɨɧɫɬɪɢɪɨɜɚɬɶ ɜɡɚɢɦɨɞɟɣɫɬɜɢɟ ɬɪɚɧɡɚɤɰɢɣ ɩɪɢ ɪɚɡɥɢɱɧɵɯ ɫɩɨɫɨɛɚɯ ɭɩɪɚɜɥɟɧɢɹ.
Ɋɢɫ. 3.3. ȼ ɧɨɜɨɦ ɩɪɨɟɤɬɟ ɪɚɫɩɨɥɨɠɢɦ ɧɚ ɮɨɪɦɟ ɤɨɦɩɨɧɟɧɬ ɫɨɟɞɢɧɟɧɢɹ IBDataBase, ɬɪɚɧɡɚɤɰɢɢ IBTransaction, ɩɨ ɞɜɚ ɤɨɦɩɨɧɟɧɬɚ TIBTable, TDataSource ɢ TDBGrid, ɞɜɚ TLabel, TComboBox ɢ ɤɧɨɩɤɢ TButton, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɚ ɪɢɫ. 3.3. ɇɚɫɬɪɨɢɦ IBTransaction ɢ IBDataBase. IBTransaction: ɋɜɨɣɫɬɜɨ
Ɂɧɚɱɟɧɢɟ
Name ibt AutoStopAction saNone DefaultDataBase ibc
Ʉɨɦɦɟɧɬɚɪɢɣ – əɜɧɨɟ ɡɚɜɟɪɲɟɧɢɟ ɂɦɹ ɤɨɦɩɨɧɟɧɬɚ-ɫɨɟɞɢɧɟɧɢɹ
ȼ ɪɟɞɚɤɬɨɪɟ ɬɪɚɧɡɚɤɰɢɣ ɜɵɛɢɪɚɟɦ ɪɟɠɢɦ Read Committed. Ɉɫɬɚɥɶɧɵɟ ɩɚɪɚɦɟɬɪɵ ɨɫɬɚɜɥɹɟɦ ɛɟɡ ɢɡɦɟɧɟɧɢɹ (ɪɢɫ. 3.4).
43
Ɋɢɫ.3.4. IBDataBase: ɋɜɨɣɫɬɜɨ
Ʉɨɦɦɟɧɬɚɪɢɣ – Connected false ɋɨɟɞɢɧɟɧɢɟ ɡɚɤɪɵɬɨ LoginPromt false ɍɱɟɬɧɵɟ ɞɚɧɧɵɟ ɩɨɥɶɡɨɜɚɬɟɥɹ ɧɟ ɡɚɩɪɚɲɢɜɚɸɬɫɹ, ɨɧɢ «ɡɚɲɢɬɵ» ɜ ɤɨɦɩɨɧɟɧɬ SQLDialect 3 Ⱦɨɥɠɟɧ ɫɨɜɩɚɞɚɬɶ ɫ ɜɟɪɫɢɟɣ, ɭɤɚɡɚɧɧɨɣ ɩɪɢ ɫɨɡɞɚɧɢɢ ȻȾ ȼ ɪɟɞɚɤɬɨɪɟ ɫɨɟɞɢɧɟɧɢɹ ɭɤɚɡɵɜɚɟɦ ɩɭɬɶ ɤ ɛɚɡɟ ɞɚɧɧɵɯ (ɜ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɪɚɫɩɨɥɨɠɟɧɢɹ ɫɟɪɜɟɪɚ) ɢ ɭɱɟɬɧɵɟ ɞɚɧɧɵɟ ɩɨɥɶɡɨɜɚɬɟɥɹ (ɩ. 2.1). Ɇɨɠɧɨ ɩɨɞɤɥɸɱɢɬɶ ɩɪɨɢɡɜɨɥɶɧɭɸ ɛɚɡɭ ɞɚɧɧɵɯ, ɧɨ ɦɵ ɩɨɞɤɥɸɱɢɦ ɛɚɡɭ, ɪɚɫɫɦɨɬɪɟɧɧɭɸ ɜ ɩɪɟɞɵɞɭɳɢɯ ɪɚɡɞɟɥɚɯ. ɋɜɹɠɟɦ ɇȾ tCust ɫ ɬɚɛɥɢɰɟɣ Customers. Name
Ɂɧɚɱɟɧɢɟ
ibc
ɋɜɨɣɫɬɜɨ Name DataBase TableName Active
Ɂɧɚɱɟɧɢɟ tCust ibc Customers False
Ⱥɧɚɥɨɝɢɱɧɨ, ɇȾ tOrders ɧɚɫɬɪɨɢɦ ɧɚ ɬɚɛɥɢɰɭ Orders. ɋɜɨɣɫɬɜɚ Transaction ɭ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ ɧɟ ɦɟɧɹɟɦ, ɧɨ ɭɛɟɞɢɦɫɹ, ɱɬɨ ɜ ɧɢɯ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɨɞɫɬɚɜɥɟɧɵ ɡɧɚɱɟɧɢɟ ibt. «ɋɟɬɤɢ» DBGrid, ɤɚɤ ɨɛɵɱɧɨ, ɫɜɹɠɟɦ ɫ ɤɨɦɩɨɧɟɧɬɚɦɢ TDataSource (ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜɚ DataSource), ɚ ɩɨɫɥɟɞɧɢɟ ɱɟɪɟɡ ɫɜɨɣɫɬɜɚ DataSet – ɫ ɧɚɛɨɪɚɦɢ ɞɚɧɧɵɯ. ɋɜɨɣɫɬɜɨ Items ɤɨɦɩɨɧɟɧɬɚ cb: TComboBox ɡɚɩɨɥɧɢɦ ɫɥɟɞɭɸɳɢɦɢ ɫɬɪɨɤɚɦɢ: əɜɧɨɟ ɇɟɹɜɧɵɣ Commit ɇɟɹɜɧɵɣ Rollback
44
ɇɟɹɜɧɵɣ CommitRetaining ɇɟɹɜɧɵɣ RollBackRetaining
ɋɨɡɞɚɞɢɦ ɨɛɪɚɛɨɬɱɢɤɢ ɫɨɛɵɬɢɣ ɞɥɹ ɤɧɨɩɨɤ. Ɉɧɢ ɞɨɫɬɚɬɨɱɧɨ ɩɪɨɫɬɵ, ɧɨ ɛɭɞɶɬɟ ɜɧɢɦɚɬɟɥɶɧɵ ɢ ɫɥɟɞɢɬɟ ɡɚ ɫɢɫɬɟɦɨɣ ɢɦɟɧɨɜɚɧɢɹ ɤɨɦɩɨɧɟɧɬɨɜ. ɉɟɪɜɵɣ ɨɛɪɚɛɨɬɱɢɤ – ɭɧɢɜɟɪɫɚɥɶɧɵɣ ɢ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɨɜɦɟɫɬɧɨ ɤɧɨɩɤɚɦɢ tCustOpen, tCustClose, tOrdersOpen, tOrdersClose. procedure TMainForm.tCustOpenClick(Sender: TObject); begin // ȿɫɥɢ ɳɟɥɤɧɭɥɢ ɩɨ ɤɧɨɩɤɟ if Sender is TButton then // ɚɧɚɥɢɡɢɪɭɟɦ ɢɦɟɧɚ ɤɧɨɩɨɤ if (sender as TButton).Name='tCustOpen' then begin // ȿɫɥɢ ɇȾ ɨɬɤɪɵɬ, ɨɛɧɨɜɥɹɟɦ ɞɚɧɧɵɟ ɛɟɡ ɩɟɪɟɨɬɤɪɵɬɢɹ, if tCust.Active then tCust.Refresh else// ɢɧɚɱɟ – ɨɬɤɪɵɜɚɟɦ ɇȾ tCust.Open; end else if (sender as TButton).Name='tCustClose' then tCust.Close // Ɂɚɤɪɵɜɚɟɦ ɇȾ else if (sender as TButton).Name='tOrdersOpen' then begin if tOrders.Active then tOrders.Refresh else tOrders.Open; end else if (sender as TButton).Name='tOrdersClose' then tOrders.close; // ɋɢɝɧɚɥɢɡɢɪɭɟɦ ɨɛ ɚɤɬɢɜɧɨɫɬɢ ɬɪɚɧɡɚɤɰɢɢ Label2.Caption:=BoolToStr(ibt.Active, True); end; // OnClick ɤɧɨɩɤɢ bCommit procedure TMainForm.bCommitClick(Sender: TObject); begin if ibt.Active then ibt.Commit; // ɉɨɞɬɜɟɪɠɞɟɧɢɟ ɬɪɚɧɡɚɤɰɢɢ Label2.Caption:=BoolToStr(ibt.Active, True); end; // OnClick ɤɧɨɩɤɢ bRollBack procedure TMainForm.bRollBackClick(Sender: TObject); begin if ibt.Active then ibt.RollBack; // Ɉɬɤɚɬ ɬɪɚɧɡɚɤɰɢɢ Label2.Caption:=BoolToStr(ibt.Active, True); end; // OnClick ɤɧɨɩɤɢ bStart procedure TMainForm.bStartClick(Sender: TObject); begin
45
if not ibt.Active then ibt.StartTransaction; // ɋɬɚɪɬ ɬɪɚɧɡɚɤɰɢɢ Label2.Caption:=BoolToStr(ibt.Active, True); end; // OnClick ɤɧɨɩɤɢ bCmtRtn (ɬ. ɟ. CommitRetaining) procedure TMainForm.bCmtRtnClick(Sender: TObject); begin if ibt.Active then ibt.CommitRetaining; Label2.Caption:=BoolToStr(ibt.Active, True); end; // OnClick ɤɧɨɩɤɢ bRlbRtn procedure TMainForm.bRlbRtnClick(Sender: TObject); begin if ibt.Active then ibt.RollBackRetaining; Label2.Caption := BoolToStr(ibt.Active, True); end; procedure TMainForm.bDisConnectClick(Sender: TObject); begin ibc.Connected := False; // Ɉɬɫɨɟɞɢɧɟɧɢɟ ɨɬ ɫɟɪɜɟɪɚ Label2.Caption := BoolToStr(ibt.Active, True); end;
Ɉɛɪɚɛɨɬɱɢɤ ɫɨɛɵɬɢɹ OnChange, ɩɪɨɢɫɯɨɞɹɳɟɝɨ ɩɪɢ ɜɵɛɨɪɟ ɷɥɟɦɟɧɬɚ ɢɡ ɤɨɦɛɢɧɢɪɨɜɚɧɧɨɝɨ ɫɩɢɫɤɚ cb, ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɡɚɞɚɧɢɹ ɫɩɨɫɨɛɚ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ: procedure TMainForm.cbChange(Sender: TObject); begin case cb.ItemIndex of 0: ibt.AutoStopAction:=saNone; 1: ibt.AutoStopAction:=saCommit; 2: ibt.AutoStopAction:=saRollBack; 3: ibt.AutoStopAction:=saCommitRetaining; 4: ibt.AutoStopAction:=saRollBackRetaining; end; end;
ȼ ɫɥɟɞɭɸɳɢɯ ɨɛɪɚɛɨɬɱɢɤɚɯ ɮɨɪɦɢɪɭɟɬɫɹ ɫɩɢɫɨɤ ɩɚɪɚɦɟɬɪɨɜ ɬɪɚɧɡɚɤɰɢɢ: procedure TMainForm.bAddClick(Sender: TObject); begin if lSource.ItemIndex>=0 then lDest.Items.Add(lSource.Items[lSource.ItemIndex]) end; procedure TMainForm.bDelClick(Sender: TObject); begin if lDest.ItemIndex>=0 then lDest.Items.Delete(ldest.ItemIndex) end;
46
procedure TMainForm.bApplyClick(Sender: TObject); begin // ɋɩɢɫɨɤ ɩɚɪɚɦɟɬɪɨɜ ɩɟɪɟɞɚɟɬɫɹ ɬɪɚɧɡɚɤɰɢɢ ibt.Params:=lDest.Items; end; procedure TForm1.FormCreate(Sender: TObject); begin // ɋɩɢɫɨɤ ɡɚɩɨɥɧɹɟɬɫɹ ɩɚɪɚɦɟɬɪɚɦɢ, ɡɚɞɚɧɧɵɦɢ ɧɚ ɷɬɚɩɟ ɜɢɡ. ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ lDest.Items:=ibt.Params; end;
Ɂɚɩɭɫɬɢɬɟ ɩɪɨɝɪɚɦɦɭ ɧɚ ɜɵɩɨɥɧɟɧɢɟ. ɉɨ ɭɦɨɥɱɚɧɢɸ ɭɫɬɚɧɨɜɥɟɧ ɪɟɠɢɦ ɹɜɧɨɝɨ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɢ. ɇɚɠɦɢɬɟ ɤɧɨɩɤɢ «ɋɨɟɞɢɧɟɧɢɟ» ɢ «ɋɬɚɪɬ ɬɪɚɧɡɚɤɰɢɢ». ɉɨɫɥɟ ɧɚɠɚɬɢɹ ɩɨɫɥɟɞɧɟɣ ɤɧɨɩɤɢ ɩɨɹɜɢɬɫɹ ɫɨɨɛɳɟɧɢɟ «Ⱥɤɬɢɜɧɨɫɬɶ ɬɪɚɧɡɚɤɰɢɢ: True». Ɉɬɤɪɨɣɬɟ ɇȾ «Customers». ɂɡɦɟɧɢɬɟ ɮɚɦɢɥɢɸ «ɂɜɚɧɨɜ» ɧɚ «ɂɜɚɧɨɜɫɤɢɣ». ɉɪɢ ɩɟɪɟɯɨɞɟ ɧɚ ɫɥɟɞɭɸɳɭɸ ɡɚɩɢɫɶ ɜɵɡɨɜɟɬɫɹ ɦɟɬɨɞ Post, ɩɟɪɟɫɵɥɚɸɳɢɣ ɢɡɦɟɧɟɧɢɹ ɧɚ ɫɟɪɜɟɪ. ɑɬɨɛɵ ɩɨɜɬɨɪɧɨ ɜɵɛɪɚɬɶ ɞɚɧɧɵɟ ɫ ɫɟɪɜɟɪɚ, ɟɳɟ ɪɚɡ ɧɚɠɦɢɬɟ ɤɧɨɩɤɭ «Ɉɬɤɪɵɬɶ» – ɜɵɡɨɜɟɬɫɹ ɦɟɬɨɞ Refresh. ɍɜɢɞɢɬɟ ɧɨɜɭɸ ɮɚɦɢɥɢɸ «ɂɜɚɧɨɜɫɤɢɣ», ɬ. ɟ. ɧɚɲɢ ɢɡɦɟɧɟɧɢɹ ɜ ȻȾ ɨɬɪɚɡɢɥɢɫɶ. ɇɚɠɦɢɬɟ ɤɧɨɩɤɭ «RollBack». ɇɚɛɨɪ ɞɚɧɧɵɯ ɡɚɤɪɨɟɬɫɹ ɢ ɩɨɹɜɢɬɫɹ ɫɨɨɛɳɟɧɢɟ ɨ ɧɟɚɤɬɢɜɧɨɫɬɢ ɬɪɚɧɡɚɤɰɢɢ. Ɉɬɤɪɨɣɬɟ ɇȾ. ɉɨɹɜɢɬɫɹ ɩɪɟɠɧɹɹ ɮɚɦɢɥɢɹ «ɂɜɚɧɨɜ» – ɬɪɚɧɡɚɤɰɢɹ ɨɬɤɚɬɚɧɚ. ȼɧɨɜɶ ɩɪɨɞɟɥɚɟɦ ɬɟ ɠɟ ɫɚɦɵɟ ɨɩɟɪɚɰɢɢ ɫ ɮɚɦɢɥɢɟɣ, ɧɨ ɧɚɠɦɟɦ «Commit». Ɍɪɚɧɡɚɤɰɢɹ ɛɭɞɟɬ ɡɚɮɢɤɫɢɪɨɜɚɧɚ, ɢ ɩɨɫɥɟ ɩɨɜɬɨɪɧɨɝɨ ɨɬɤɪɵɬɢɹ ɦɵ ɭɜɢɞɢɦ ɢɡɦɟɧɟɧɧɭɸ ɮɚɦɢɥɢɸ. Ɍɟɩɟɪɶ ɩɨɩɵɬɚɟɦɫɹ ɧɟ ɡɚɜɟɪɲɚɬɶ ɬɪɚɧɡɚɤɰɢɸ, ɚ ɡɚɤɪɨɟɦ ɫɨɟɞɢɧɟɧɢɟ (ɤɧɨɩɤɚ «Disconnect») ɢɥɢ ɡɚɜɟɪɲɢɦ ɩɪɨɝɪɚɦɦɭ. ɍɛɟɞɢɦɫɹ, ɱɬɨ ɮɚɦɢɥɢɹ ɜɫɟ ɪɚɜɧɨ ɛɭɞɟɬ ɢɡɦɟɧɟɧɚ, ɧɨ, ɪɚɡɭɦɟɟɬɫɹ, ɷɬɨ – ɧɟ ɥɭɱɲɢɣ ɜɚɪɢɚɧɬ. ɂɡɦɟɧɢɦ ɮɚɦɢɥɢɸ ɜ ɬɚɛɥɢɰɟ «Customers» ɢ ɤɨɥɢɱɟɫɬɜɨ ɡɚɤɚɡɨɜ ɜ ɬɚɛɥɢɰɟ «Orders». ɇɚɠɚɬɢɟ «Commit» ɩɪɢɜɟɞɟɬ ɤ ɮɢɤɫɚɰɢɢ ɢɡɦɟɧɟɧɢɣ ɜ ɨɛɟɢɯ ɬɚɛɥɢɰɚɯ. ɇɟɭɞɢɜɢɬɟɥɶɧɨ, ɬɚɤ ɤɚɤ ɞɟɣɫɬɜɢɹ ɫ ɷɬɢɦɢ ɬɚɛɥɢɰɚɦɢ ɦɵ ɨɬɧɟɫɥɢ ɤ ɨɞɧɨɣ ɬɪɚɧɡɚɤɰɢɢ, ɫɜɹɡɚɜ ɢɯ ɫ ɨɞɧɢɦ ɤɨɦɩɨɧɟɧɬɨɦ ibt: TIBTransaction. ɂɡɦɟɧɢɦ ɮɚɦɢɥɢɸ, ɧɨ ɢɫɩɨɥɶɡɭɟɦ ɤɧɨɩɤɢ «CommitRetainig» ɢ «RollBackRetaining». ɉɨɫɥɟɞɫɬɜɢɹ ɛɭɞɭɬ ɚɧɚɥɨɝɢɱɧɵ, ɧɨ ɩɨɜɬɨɪɧɨ ɨɬɤɪɵɜɚɬɶ ɇȾ ɭɠɟ ɧɟ ɩɨɧɚɞɨɛɢɬɫɹ. ɉɨɫɥɟ ɜɵɡɨɜɚ ɷɬɢɯ ɦɟɬɨɞɨɜ ɬɪɚɧɡɚɤɰɢɹ ɨɫɬɚɟɬɫɹ ɚɤɬɢɜɧɨɣ. Ɉɬɤɪɨɟɦ ɇȾ, ɧɟ ɧɚɠɚɜ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ «ɋɬɚɪɬ ɬɪɚɧɡɚɤɰɢɢ». Ɍɪɚɧɡɚɤɰɢɹ ɜɫɟ ɪɚɜɧɨ ɫɬɚɪɬɭɟɬ, ɢ ɩɨɹɜɢɬɫɹ ɫɨɨɛɳɟɧɢɟ ɨɛ ɟɟ ɚɤɬɢɜɧɨɫɬɢ. ɂɡɦɟɧɢɦ ɮɚɦɢɥɢɸ, ɧɨ ɡɚɜɟɪɲɚɬɶ ɬɪɚɧɡɚɤɰɢɸ ɧɟ ɛɭɞɟɦ. Ɂɚɩɭɫɬɢɦ ɟɳɟ ɨɞɢɧ ɷɤɡɟɦɩɥɹɪ ɬɨɣ ɠɟ ɫɚɦɨɣ ɩɪɨɝɪɚɦɦɵ ɢɥɢ ɭɬɢɥɢɬɭ IBExpert. ɉɪɢ 47
ɨɬɤɪɵɬɢɢ ɬɚɛɥɢɰɵ ɷɬɢ ɩɪɨɝɪɚɦɦɵ ɧɟ ɭɜɢɞɹɬ ɢɡɦɟɧɟɧɧɨɣ ɮɚɦɢɥɢɢ – ɷɬɨɝɨ ɧɟ ɩɨɡɜɨɥɢɬ ɫɞɟɥɚɬɶ ɭɪɨɜɟɧɶ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ. ȿɫɥɢ ɠɟ ɜ ɩɟɪɜɨɦ ɷɤɡɟɦɩɥɹɪɟ ɩɪɨɝɪɚɦɦɵ ɫɞɟɥɚɬɶ Commit, ɚ ɜɨ ɜɬɨɪɨɦ – ɩɟɪɟɨɬɤɪɵɬɶ ɧɚɛɨɪ ɞɚɧɧɵɯ, ɬɨ ɜɬɨɪɚɹ ɩɪɨɝɪɚɦɦɚ (ɬ. ɟ. ɜɬɨɪɚɹ ɬɪɚɧɡɚɤɰɢɹ) ɭɜɢɞɢɬ ɢɡɦɟɧɟɧɧɵɟ ɞɚɧɧɵɟ – ɭɪɨɜɟɧɶ Read Commited ɷɬɨ ɩɨɡɜɨɥɹɟɬ. ɋɞɟɥɚɣɬɟ ɬɨ ɠɟ ɫɚɦɨɟ, ɱɬɨ ɜ ɩɪɟɞɵɞɭɳɟɦ ɚɛɡɚɰɟ, ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɩɨɦɟɧɹɜ ɭɪɨɜɟɧɶ ɢɡɨɥɹɰɢɢ ɧɚ SNAPSHOT. Ɍɨɝɞɚ ɜɬɨɪɚɹ ɩɪɨɝɪɚɦɦɚ ɧɢɤɨɝɞɚ ɧɟ ɭɜɢɞɢɬ ɮɚɦɢɥɢɸ «ɂɜɚɧɨɜɫɤɢɣ», ɟɫɥɢ ɩɪɢ ɟɟ ɫɬɚɪɬɟ ɜ ɬɚɛɥɢɰɟ ɛɵɥɨ ɡɚɩɢɫɚɧɨ «ɂɜɚɧɨɜ». ɂɡɦɟɧɢɬɟ ɡɚɩɢɫɶ ɫ ɩɨɦɨɳɶɸ ɩɟɪɜɨɣ ɩɪɨɝɪɚɦɦɵ ɢ, ɧɟ ɡɚɜɟɪɲɚɹ ɬɪɚɧɡɚɤɰɢɢ, ɩɨɩɵɬɚɣɬɟɫɶ ɷɬɨ ɫɞɟɥɚɬɶ ɬɚɤɠɟ ɫ ɩɨɦɨɳɶɸ ɜɬɨɪɨɣ ɩɪɨɝɪɚɦɦɵ. Ⱦɥɹ ɷɬɨɝɨ ɜɵɣɞɢɬɟ ɢɡ ɪɟɞɚɤɬɢɪɭɟɦɨɣ ɹɱɟɣɤɢ «ɫɟɬɤɢ». ɉɨɹɜɢɬɫɹ ɫɨɨɛɳɟɧɢɟ ɨɛ ɨɲɢɛɤɟ (ɪɢɫ. 3.5).
Ɋɢɫ. 3.5. Ⱦɚɧɧɨɟ ɫɨɨɛɳɟɧɢɟ ɫɜɢɞɟɬɟɥɶɫɬɜɭɟɬ ɨ ɧɟɜɨɡɦɨɠɧɨɫɬɢ ɩɚɪɚɥɥɟɥɶɧɨɝɨ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɨɞɧɨɣ ɡɚɩɢɫɢ ɞɜɭɦɹ ɬɪɚɧɡɚɤɰɢɹɦɢ. ȿɫɥɢ ɠɟ ɩɟɪɜɭɸ ɬɪɚɧɡɚɤɰɢɸ ɡɚɜɟɪɲɢɬɶ (Commit), ɬɨ ɜɬɨɪɚɹ ɩɨɥɭɱɢɬ ɞɨɫɬɭɩ ɤ ɪɟɞɚɤɬɢɪɨɜɚɧɢɸ ɡɚɩɢɫɢ. Ɂɚɦɟɬɢɦ, ɱɬɨ ɬɟɪɦɢɧ «Deadlock» (ɜɡɚɢɦɧɚɹ ɛɥɨɤɢɪɨɜɤɚ, ɬɭɩɢɤ) ɡɞɟɫɶ ɧɟ ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɫɢɬɭɚɰɢɢ. ɉɪɨɢɡɨɲɥɚ ɥɢɲɶ ɩɨɩɵɬɤɚ ɨɞɧɨɜɪɟɦɟɧɧɨɝɨ ɢɡɦɟɧɟɧɢɹ ɡɚɩɢɫɢ, ɱɬɨ ɱɪɟɜɚɬɨ ɤɨɥɥɢɡɢɟɣ «ɝɨɧɨɤ». Ʉɨɥɥɢɡɢɢ ɬɭɩɢɤɨɜ ɫɟɪɜɟɪ ɬɚɤɠɟ ɫɩɨɫɨɛɟɧ ɪɚɡɪɟɲɚɬɶ, ɧɨ ɜɨɡɧɢɤɚɸɬ ɨɧɢ ɝɨɪɚɡɞɨ ɪɟɠɟ. ɉɪɨɞɟɥɚɣɬɟ ɬɨ ɠɟ ɫɚɦɨɟ, ɡɚɦɟɧɢɜ ɩɚɪɚɦɟɬɪ nowait ɧɚ wait. ȼɬɨɪɨɟ ɩɪɢɥɨɠɟɧɢɟ «ɡɚɜɢɫɧɟɬ» ɩɪɢ ɩɨɩɵɬɤɟ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɢ ɩɪɨɞɨɥɠɢɬ ɫɜɨɸ ɪɚɛɨɬɭ ɬɨɥɶɤɨ ɩɨɫɥɟ ɡɚɜɟɪɲɟɧɢɹ ɩɟɪɜɨɣ ɬɪɚɧɡɚɤɰɢɢ. ɂɫɫɥɟɞɭɟɦ ɜɥɢɹɧɢɟ ɫɩɨɫɨɛɚ ɡɚɜɟɪɲɟɧɢɹ ɬɪɚɧɡɚɤɰɢɣ. ȼɵɛɟɪɢɬɟ ɜ ɤɨɦɛɢɧɢɪɨɜɚɧɧɨɦ ɫɩɢɫɤɟ ɫɩɨɫɨɛ ɭɩɪɚɜɥɟɧɢɹ «ɇɟɹɜɧɵɣ Commit». Ɂɚɩɭɫɬɢɬɟ ɬɪɚɧɡɚɤɰɢɸ, ɨɬɤɪɵɜ ɇȾ «Ɂɚɤɚɡɱɢɤɢ», ɨɬɤɪɨɣɬɟ ɬɚɤɠɟ ɜɬɨɪɨɣ ɇȾ «Ɂɚɤɚɡɵ». Ɂɚɤɪɨɣɬɟ ɩɟɪɜɵɣ ɇȾ. Ɍɪɚɧɡɚɤɰɢɹ ɨɫɬɚɟɬɫɹ ɚɤɬɢɜɧɨɣ. Ɉɧɚ ɡɚɜɟɪɲɢɬɫɹ ɬɨɥɶɤɨ ɩɨɫɥɟ ɡɚɤɪɵɬɢɹ ɜɬɨɪɨɝɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ «Ɂɚɤɚɡɵ», ɫɜɹɡɚɧɧɨɝɨ ɫ ɞɚɧɧɨɣ ɬɪɚɧɡɚɤɰɢɟɣ. ȼɵɡɵɜɚɬɶ Commit ɧɟ ɬɪɟɛɭɟɬɫɹ, ɧɨ ɟɫɥɢ ɟɝɨ ɜɵɡɜɚɬɶ, ɬɨ ɬɪɚɧɡɚɤɰɢɹ ɬɚɤɠɟ ɛɭɞɟɬ ɡɚɜɟɪɲɟɧɚ. ɂɡɦɟɧɢɦ ɤɚɤɭɸ-ɧɢɛɭɞɶ ɡɚɩɢɫɶ, ɜɵɡɨɜɟɦ RollBack ɢ ɭɛɟɞɢɦɫɹ, ɱɬɨ ɨɧ ɧɟ ɩɪɢɜɨɞɢɬ ɤ ɨɬɤɚɬɭ ɬɪɚɧɡɚɤɰɢɢ – ɩɪɢ ɩɨɜɬɨɪɧɨɦ ɨɬɤɪɵɬɢɢ ɦɵ ɩɨɥɭɱɢɦ ɢɡɦɟɧɟɧɧɵɟ ɞɚɧɧɵɟ. Ⱦɥɹ ɨɬɤɚɬɚ ɬɪɚɧɡɚɤɰɢɢ ɡɞɟɫɶ ɩɨɦɨɠɟɬ ɦɟɬɨɞ RollBackRetaining, ɩɨɫɥɟ ɟɝɨ ɜɵɡɨɜɚ ɢ ɩɟɪɟɨɬɤɪɵɬɢɹ ɇȾ ɦɵ ɩɨɥɭɱɢɦ ɡɚɩɢɫɶ, ɧɟ ɢɡɦɟɧɢɜɲɭɸ ɡɧɚɱɟɧɢɹ ɩɨɥɟɣ. 48
ȼɵɜɨɞɵ 1. əɜɧɨɟ ɡɚɜɟɪɲɟɧɢɟ ɬɪɚɧɡɚɤɰɢɢ (ɤɨɝɞɚ ɜ ɫɜɨɣɫɬɜɟ AutoStopAction ɤɨɦɩɨɧɟɧɬɚ TIBTransaction ɭɤɚɡɚɧɨ saNone) ɹɜɥɹɟɬɫɹ ɫɩɨɫɨɛɨɦ, ɢɫɩɨɥɶɡɭɟɦɵɦ ɩɨ ɭɦɨɥɱɚɧɢɸ. 2. ɉɨɞɬɜɟɪɠɞɟɧɢɟ ɬɪɚɧɡɚɤɰɢɢ ɩɪɢ ɹɜɧɨɦ ɡɚɜɟɪɲɟɧɢɢ ɩɪɨɢɫɯɨɞɢɬ ɩɪɢ ɜɵɡɨɜɟ ɦɟɬɨɞɚ Commit ɢɥɢ ɩɪɢ ɨɬɫɨɟɞɢɧɟɧɢɢ ɨɬ ɛɚɡɵ ɞɚɧɧɵɯ (ɧɚɩɪɢɦɟɪ, ɩɪɢ ɡɚɜɟɪɲɟɧɢɢ ɩɪɨɝɪɚɦɦɵ). 3. Ɇɟɬɨɞ Rollback ɨɬɤɚɬɵɜɚɟɬ ɬɪɚɧɡɚɤɰɢɸ ɬɨɥɶɤɨ ɩɪɢ ɹɜɧɨɦ ɡɚɜɟɪɲɟɧɢɢ ɬɪɚɧɡɚɤɰɢɹɦɢ. 4. ɉɪɢ ɧɟɹɜɧɨɦ ɡɚɜɟɪɲɟɧɢɢ ɬɪɚɧɡɚɤɰɢɹɦɢ ɟɟ ɩɨɞɬɜɟɪɠɞɟɧɢɟ ɩɪɨɢɡɨɣɞɟɬ ɥɢɛɨ ɩɪɢ ɜɵɡɨɜɟ Commit, ɥɢɛɨ ɩɪɢ ɡɚɤɪɵɬɢɢ ɜɫɟɯ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ, ɫɜɹɡɚɧɧɵɯ ɫ ɬɪɚɧɡɚɤɰɢɟɣ. 5. Ⱦɥɹ ɧɟɹɜɧɨɝɨ ɨɬɤɚɬɚ ɬɪɚɧɡɚɤɰɢɢ ɦɨɠɧɨ ɜ ɫɜɨɣɫɬɜɟ AutoStopAction ɭɤɚɡɚɬɶ saRollBack ɢɥɢ saRollBackRetaining. Ɍɨɝɞɚ ɬɪɚɧɡɚɤɰɢɹ ɨɬɤɚɬɢɬɫɹ ɩɪɢ ɡɚɤɪɵɬɢɢ ɜɫɟɯ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ, ɫɜɹɡɚɧɧɵɯ ɫ ɬɪɚɧɡɚɤɰɢɟɣ. 6. ȿɫɥɢ ɜ ɫɜɨɣɫɬɜɟ AutoStopAction ɭɤɚɡɚɧɨ saCommit, ɬɨ ɨɬɤɚɬɢɬɶ ɬɪɚɧɡɚɤɰɢɸ ɦɨɠɧɨ ɬɨɥɶɤɨ ɦɟɬɨɞɨɦ RollBackRetaining, ɧɟ ɡɚɤɪɵɜɚɸɳɢɦ ɧɚɛɨɪ ɞɚɧɧɵɯ. Ⱦɥɹ ɭɝɥɭɛɥɟɧɧɨɝɨ ɢɡɭɱɟɧɢɹ ɦɚɬɟɪɢɚɥɚ ɩɨ ɜɡɚɢɦɨɞɟɣɫɬɜɢɸ ɬɪɚɧɡɚɤɰɢɣ ɧɟɨɛɯɨɞɢɦɨ ɨɛɪɚɬɢɬɫɹ ɤ ɫɩɟɰɢɚɥɶɧɵɦ ɫɬɚɬɶɹɦ, ɨɩɭɛɥɢɤɨɜɚɧɧɵɦ ɜ Internet ɩɨ ɚɞɪɟɫɚɦ www.ibase.ru, www.interbase-world.com, www.sql.ru. 3.5. Ʉɨɦɩɨɧɟɧɬɵ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ 3.5.1. TIBTable Ʉɨɦɩɨɧɟɧɬ TIBTable ɨɬɨɛɪɚɠɚɟɬ ɜ ɩɚɦɹɬɢ ɤɥɢɟɧɬɫɤɨɣ ɦɚɲɢɧɵ ɬɚɛɥɢɰɭ ɫ ɞɚɧɧɵɦɢ ɢ, ɩɨɞɨɛɧɨ ɜɫɟɦ ɤɨɦɩɨɧɟɧɬɚɦ-ɩɨɬɨɦɤɚɦ TDataSet, ɫɬɪɨɢɬɫɹ ɧɚ ɨɫɧɨɜɟ ɞɜɭɧɚɩɪɚɜɥɟɧɧɨɝɨ ɤɥɢɟɧɬɫɤɨɝɨ ɤɭɪɫɨɪɚ. Ʉɨɦɩɨɧɟɧɬ ɩɪɢ ɨɬɤɪɵɬɢɢ ɧɚɛɨɪɚ ɞɚɧɧɵɯ ɧɟɹɜɧɨ ɜɵɡɵɜɚɟɬ ɨɩɟɪɚɬɨɪ SELECT * FROM Ɍɚɛɥɢɰɚ, ɱɬɨ ɩɪɢɜɨɞɢɬ ɤ ɤɨɩɢɪɨɜɚɧɢɸ ɜɫɟɯ ɡɚɩɢɫɟɣ ɢɡ ɬɚɛɥɢɰɵ ɧɚ ɤɥɢɟɧɬɫɤɢɣ ɤɨɦɩɶɸɬɟɪ. ɉɨɷɬɨɦɭ ɞɥɹ ɛɨɥɶɲɢɯ ɬɚɛɥɢɰ ɷɬɨɬ ɤɨɦɩɨɧɟɧɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɧɟ ɪɟɤɨɦɟɧɞɭɟɬɫɹ. ɉɪɟɞɩɨɱɬɢɬɟɥɶɧɟɟ ɤɨɦɩɨɧɟɧɬɵ TIBQuery, IBDataSet, ɜ ɤɨɬɨɪɵɟ ɨɩɟɪɚɬɨɪ SELECT «ɡɚɲɢɜɚɟɬɫɹ» ɹɜɧɨ ɢ, ɫɥɟɞɨɜɚɬɟɥɶɧɨ, ɢɦɟɟɬɫɹ ɜɨɡɦɨɠɧɨɫɬɶ ɨɝɪɚɧɢɱɢɬɶ ɜɵɛɨɪɤɭ ɫ ɩɨɦɨɳɶɸ ɤɨɧɫɬɪɭɤɰɢɢ SELECT...FROM...WHERE... . Ʉɨɦɩɨɧɟɧɬ ɩɪɢɝɨɞɟɧ ɞɥɹ ɨɬɨɛɪɚɠɟɧɢɹ ɧɟ ɬɨɥɶɤɨ ɬɚɛɥɢɰ, ɧɨ ɢ ɩɪɟɞɫɬɚɜɥɟɧɢɣ (View). ɂɦɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɭɤɚɡɵɜɚɟɬɫɹ ɜɦɟɫɬɨ ɢɦɟɧɢ ɬɚɛɥɢɰɵ 49
ɜ ɫɜɨɣɫɬɜɟ TableName ɤɨɦɩɨɧɟɧɬɚ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɨɛɵɱɧɨ ɫɨɞɟɪɠɢɬ ɡɚɩɪɨɫ ɧɚ ɜɵɛɨɪɤɭ ɢɡ ɨɞɧɨɣ ɢɥɢ ɧɟɫɤɨɥɶɤɢɯ ɫɜɹɡɚɧɧɵɯ ɬɚɛɥɢɰ, ɨɝɪɚɧɢɱɟɧɧɭɸ ɩɨ ɫɬɪɨɤɚɦ ɢ ɫɬɨɥɛɰɚɦ. Ɇɟɬɨɞ Open ɨɬɤɪɵɜɚɟɬ ɧɚɛɨɪ ɞɚɧɧɵɯ ɢ ɡɚɩɨɥɧɹɟɬ ɟɝɨ ɢɧɮɨɪɦɚɰɢɟɣ ɢɡ ɬɚɛɥɢɰ. Ɇɟɬɨɞ Close ɡɚɤɪɵɜɚɟɬ ɢ ɨɱɢɳɚɟɬ ɧɚɛɨɪ ɞɚɧɧɵɯ. Ɇɟɬɨɞ Refresh ɨɛɧɨɜɥɹɟɬ ɧɚɛɨɪ ɞɚɧɧɵɯ, ɨɛɟɫɩɟɱɢɜɚɹ ɩɨɥɭɱɟɧɢɟ ɫɜɟɠɢɯ ɜɟɪɫɢɣ ɡɚɩɢɫɟɣ. Refresh ɜɵɩɨɥɧɹɟɬɫɹ ɧɚɞ ɨɬɤɪɵɬɵɦ ɧɚɛɨɪɨɦ ɞɚɧɧɵɯ ɢ ɩɨɷɬɨɦɭ ɪɚɛɨɬɚɟɬ ɛɵɫɬɪɟɟ, ɱɟɦ ɤɨɦɛɢɧɚɰɢɹ ɦɟɬɨɞɨɜ Close ɢ Open, ɧɢɤɨɝɞɚ ɧɟ ɜɵɡɵɜɚɟɬ ɩɨɜɬɨɪɧɨɝɨ ɫɬɚɪɬɚ ɬɪɚɧɡɚɤɰɢɢ, ɧɨ, ɤ ɫɨɠɚɥɟɧɢɸ, ɜɫɟ ɪɚɜɧɨ ɧɟ ɝɚɪɚɧɬɢɪɭɟɬ ɫɨɯɪɚɧɟɧɢɟ ɭɤɚɡɚɬɟɥɹ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ. Ɉɫɧɨɜɧɵɟ ɫɜɨɣɫɬɜɚ ɢ ɦɟɬɨɞɵ ɤɨɦɩɨɧɟɧɬɚ ɫɨɜɩɚɞɚɸɬ ɫ ɤɨɦɩɨɧɟɧɬɨɦ TTable, ɨɫɧɨɜɚɧɧɵɦ ɧɚ ɬɟɯɧɨɥɨɝɢɢ BDE ɢ ɯɨɪɨɲɨ ɨɩɢɫɚɧɧɵɦ ɜ ɞɨɫɬɭɩɧɨɣ ɥɢɬɟɪɚɬɭɪɟ. ɇɚɱɢɧɚɹ ɫ ɜɟɪɫɢɢ Delphi 7, ɢɫɩɪɚɜɥɟɧɚ ɞɨɫɚɞɧɚɹ ɨɲɢɛɤɚ ɩɪɢ ɪɚɛɨɬɟ ɫ ɮɢɥɶɬɪɚɦɢ. 3.5.2. TIBQuery ɇɚɛɨɪ ɞɚɧɧɵɯ ɮɨɪɦɢɪɭɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɨɩɟɪɚɬɨɪɚ SELECT, ɤɨɬɨɪɵɣ ɡɚɩɢɫɵɜɚɟɬɫɹ ɜ ɫɜɨɣɫɬɜɨ SQL: TStrings. ɇɚɛɨɪ ɞɚɧɧɵɯ, ɜɨɡɜɪɚɳɚɟɦɵɣ TIBQuery, ɜɫɟɝɞɚ, ɧɟɡɚɜɢɫɢɦɨ ɨɬ ɬɢɩɚ ɡɚɩɪɨɫɚ, ɢɦɟɟɬ ɡɧɚɱɟɧɢɟ ɫɜɨɣɫɬɜɚ ReadOnly, ɪɚɜɧɨɟ True, ɱɬɨ ɩɪɟɩɹɬɫɬɜɭɟɬ ɟɝɨ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨɦɭ ɪɟɞɚɤɬɢɪɨɜɚɧɢɸ. Ⱦɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ, ɜɨɡɜɪɚɳɚɟɦɵɯ TIBQuery, ɩɨɫɥɟɞɧɢɣ ɧɚɞɨ ɨɛɹɡɚɬɟɥɶɧɨ ɫɜɹɡɵɜɚɬɶ ɫ ɤɨɦɩɨɧɟɧɬɨɦ TIBUpdateSQL, ɧɟɡɚɜɢɫɢɦɨ ɨɬ ɬɨɝɨ, ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɷɲɢɪɨɜɚɧɢɟ ɢɡɦɟɧɟɧɢɣ ɢɥɢ ɧɟɬ. Ʉɨɦɩɨɧɟɧɬ TIBUpdateSQL ɪɚɡɦɟɳɚɟɬɫɹ ɜ ɦɨɞɭɥɟ ɞɚɧɧɵɯ. ɂɦɹ ɷɤɡɟɦɩɥɹɪɚ TIBUpdateSQL ɭɤɚɡɵɜɚɟɬɫɹ ɜ ɫɜɨɣɫɬɜɟ UpdateObject ɤɨɦɩɨɧɟɧɬɚ TIBQuery. Ⱦɚɥɟɟ ɜ Update SQL Editor ɧɟɨɛɯɨɞɢɦɨ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɫɝɟɧɟɪɢɪɨɜɚɬɶ ɢɥɢ ɜɪɭɱɧɭɸ ɩɪɨɩɢɫɚɬɶ ɦɨɞɢɮɢɰɢɪɭɸɳɢɟ SQL-ɡɚɩɪɨɫɵ. ȿɫɥɢ ɤɨɦɩɨɧɟɧɬ ɫɨɞɟɪɠɢɬ ɨɩɟɪɚɬɨɪ ɜɵɛɨɪɤɢ SELECT, ɬɨ ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɞɚɧɧɵɯ ɢɫɩɨɥɶɡɭɟɬɫɹ ɦɟɬɨɞ Open: TIBQuery1.Open;
ȿɫɥɢ ɤɨɦɩɨɧɟɧɬ ɫɨɞɟɪɠɢɬ ɨɩɟɪɚɬɨɪ SQL ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ, ɬɨ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɬɨɪɚ ɫɥɟɞɭɟɬ ɜɵɡɜɚɬɶ ɦɟɬɨɞ ExecSql: TIBQuery1.ExecSql;
3.5.3. TIBDataSet Ⱦɚɧɧɵɣ ɤɨɦɩɨɧɟɧɬ ɨɛɴɟɞɢɧɹɟɬ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ IBTable, IBQuery ɢ IBUpdateSQL, ɹɜɥɹɹɫɶ ɧɚɢɛɨɥɟɟ «ɩɪɨɞɜɢɧɭɬɵɦ». Ɍɟɤɫɬ SQLɡɚɩɪɨɫɚ ɯɪɚɧɢɬɫɹ ɜ ɫɜɨɣɫɬɜɟ SelectSQL ɬɢɩɚ TStrings (ɩɪɢɱɟɦ, ɮɨɪ50
ɦɢɪɭɟɬɫɹ ɨɧ ɭɞɨɛɧɵɦ ɪɟɞɚɤɬɨɪɨɦ). ȼɨɡɦɨɠɧɨɫɬɢ IBUpdateSQL ɨɛɟɫɩɟɱɢɜɚɸɬɫɹ ɪɟɞɚɤɬɨɪɨɦ ɧɚɛɨɪɚ ɞɚɧɧɵɯ, ɜɵɡɵɜɚɟɦɵɦ ɜ ɤɨɧɬɟɤɫɬɧɨɦ ɦɟɧɸ ɢ ɪɚɛɨɬɚɸɳɟɦ ɬɚɤ ɠɟ, ɤɚɤ ɜ ɨɛɵɱɧɨɦ UpdateSQL. SQL-ɨɩɟɪɚɬɨɪɵ ɦɨɞɢɮɢɤɚɰɢɢ ɇȾ ɡɚɩɢɫɵɜɚɸɬɫɹ ɜ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɟ ɫɜɨɣɫɬɜɚ InsertSQL, ModifySQL, DeleteSQL. ɂɧɬɟɪɟɫɧɨɣ ɨɫɨɛɟɧɧɨɫɬɶɸ ɤɨɦɩɨɧɟɧɬɨɜ IBQuery ɢ IBDataSet ɹɜɥɹɟɬɫɹ ɜɨɡɦɨɠɧɨɫɬɶ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨɝɨ ɜɵɡɨɜɚ ɝɟɧɟɪɚɬɨɪɚ ɞɥɹ ɡɚɩɨɥɧɟɧɢɹ ɩɟɪɜɢɱɧɨɝɨ ɤɥɸɱɟɜɨɝɨ ɩɨɥɹ. Ɂɞɟɫɶ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɜɨɣɫɬɜɨ property GeneratorField: TIBGeneratorField,
ɜ ɤɨɬɨɪɨɟ ɫɥɟɞɭɟɬ ɡɚɩɢɫɚɬɶ ɢɦɹ ɤɥɸɱɟɜɨɝɨ ɩɨɥɹ ɢ ɢɦɹ ɝɟɧɟɪɚɬɨɪɚ (ɷɬɨ ɭɞɨɛɧɟɟ ɫɞɟɥɚɬɶ ɫ ɩɨɦɨɳɶɸ ɢɧɫɩɟɤɬɨɪ ɨɛɴɟɤɬɨɜ). ȿɫɥɢ ɞɥɹ ɞɚɧɧɨɣ ɰɟɥɢ ɨɩɪɟɞɟɥɟɧ ɬɚɤɠɟ ɢ ɬɪɢɝɝɟɪ, ɬɨ ɨɧ ɩɟɪɟɩɢɲɟɬ ɜɫɬɚɜɥɟɧɧɨɟ ɡɧɚɱɟɧɢɟ. Ɇɟɬɨɞɢɤɚ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɤɨɦɩɨɧɟɧɬɚ ɢɡɥɨɠɟɧɚ ɜ ɪɚɡɞɟɥɟ 4 «ɉɪɢɦɟɪ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ». Ɂɚɦɟɱɚɧɢɟ. ȼɨ ɦɧɨɝɢɯ ɩɪɢɥɨɠɟɧɢɹɯ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɥɟɞɭɸɳɢɣ ɩɪɢɟɦ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɞɚɧɧɵɯ. Ɂɧɚɱɟɧɢɹ ɜɜɨɞɹɬɫɹ ɫ ɩɨɦɨɳɶɸ ɤɨɦɩɨɧɟɧɬɨɜ, ɱɭɜɫɬɜɢɬɟɥɶɧɵɯ ɤ ɞɚɧɧɵɦ (DBGrid, DBEdit, DBLookUpComboBox ɢ ɞɪ. [4, 5]). Ⱦɥɹ ɩɟɪɟɫɵɥɤɢ ɡɧɚɱɟɧɢɣ ɧɚ ɫɟɪɜɟɪ ɢɫɩɨɥɶɡɭɟɬɫɹ ɦɟɬɨɞ Post ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ (IBTable, IBQuery, IBDataSet), ɞɚɥɟɟ ɬɪɚɧɡɚɤɰɢɹ ɩɨɞɬɜɟɪɠɞɚɟɬɫɹ. ɋɥɟɞɭɟɬ ɩɨɦɧɢɬɶ, ɱɬɨ ɜ ɞɚɧɧɨɦ ɫɥɭɱɚɟ ɬɪɚɧɡɚɤɰɢɹ ɦɨɠɟɬ ɛɵɬɶ «ɡɚɬɹɧɭɜɲɟɣɫɹ» ɜɨ ɜɪɟɦɟɧɢ, ɬɚɤ ɤɚɤ ɩɨɥɶɡɨɜɚɬɟɥɶ (ɫɚɦɨɟ ɫɥɚɛɨɟ ɢ ɧɟɬɨɪɨɩɥɢɜɨɟ ɡɜɟɧɨ) ɜɜɨɞɢɬ ɞɚɧɧɵɟ ɭɠɟ ɩɨɫɥɟ ɫɬɚɪɬɚ ɬɪɚɧɡɚɤɰɢɢ ɢ ɨɬɤɪɵɬɢɹ ɇȾ ɢ ɦɨɠɟɬ ɷɬɨ ɞɟɥɚɬɶ ɬɨɦɢɬɟɥɶɧɨ ɞɨɥɝɨ, ɩɟɪɢɨɞɢɱɟɫɤɢ ɜɵɡɵɜɚɹ Post. ɉɨɷɬɨɦɭ, ɜɨ ɢɡɛɟɠɚɧɢɟ ɩɪɨɛɥɟɦ ɩɪɢ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɣ ɪɚɛɨɬɟ, ɩɚɪɚɦɟɬɪɵ ɬɪɚɧɡɚɤɰɢɢ ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɧɟ ɞɨɥɠɧɵ ɛɵɬɶ ɠɟɫɬɱɟ, ɱɟɦ Read_commited Rec_version Nowait.
3.5.4. TIBStoredProc Ⱦɚɧɧɵɣ ɤɨɦɩɨɧɟɧɬ ɜ ɨɫɧɨɜɧɨɦ ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɨɪɝɚɧɢɡɚɰɢɢ «ɛɵɫɬɪɵɯ» ɬɪɚɧɡɚɤɰɢɣ ɩɨ ɦɨɞɢɮɢɤɚɰɢɢ ɞɚɧɧɵɯ. Ʉɪɨɦɟ ɬɨɝɨ, ɨɧ ɦɨɠɟɬ ɩɪɢɦɟɧɹɬɶɫɹ ɞɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɯɪɚɧɢɦɵɦ ɩɪɨɰɟɞɭɪɚɦ, ɜɨɡɜɪɚɳɚɸɳɢɦ ɨɞɢɧ ɷɤɡɟɦɩɥɹɪ ɩɚɪɚɦɟɬɪɨɜ. Ʉɨɦɩɨɧɟɧɬ ɞɨɥɠɟɧ ɛɵɬɶ ɫɜɹɡɚɧ ɫ TIBDateBase ɢ TIBTransaction (ɩ. 3.2–3.3). ɂɦɹ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ ɨɩɪɟɞɟɥɹɟɬɫɹ ɫɜɨɣɫɬɜɨɦ property StoredProcName: String;
Ⱦɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɜɯɨɞɧɵɦ ɢ ɜɵɯɨɞɧɵɦ ɩɚɪɚɦɟɬɪɨɜ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɜɨɣɫɬɜɨ property Params: TParams;
Ɇɟɬɨɞ function ParamByName(const Value: string): TParam;
51
ɩɨɡɜɨɥɹɟɬ ɨɛɪɚɬɢɬɶɫɹ ɤ ɩɚɪɚɦɟɬɪɭ ɩɨ ɟɝɨ ɢɦɟɧɢ, ɭɤɚɡɚɧɧɨɦɭ ɜ ɚɪɝɭɦɟɧɬɟ Value. Ɇɟɬɨɞ ExecProc ɜɵɩɨɥɧɹɟɬ ɯɪɚɧɢɦɭɸ ɩɪɨɰɟɞɭɪɭ. ȼ ɤɚɱɟɫɬɜɟ ɩɪɢɦɟɪɚ ɧɚɩɢɲɟɦ ɯɪɚɧɢɦɭɸ ɩɪɨɰɟɞɭɪɭ, ɞɨɛɚɜɥɹɸɳɭɸ ɬɨɜɚɪ ɧɚ ɫɤɥɚɞ. ɉɪɨɰɟɞɭɪɚ ɧɟ ɜɨɡɜɪɚɳɚɟɬ ɩɚɪɚɦɟɬɪɨɜ. CREATE PROCEDURE Add_Product (NewName varchar(20), NewPrice decimal(10,2), newRest integer) /* ȼɯɨɞɧɵɦɢ ɩɚɪɚɦɟɬɪɚɦɢ ɹɜɥɹɸɬɫɹ ɧɚɡɜɚɧɢɟ ɬɨɜɚɪɚ, */ /* ɰɟɧɚ, ɤɨɥɢɱɟɫɬɜɨ */ AS DECLARE cnt integer; BEGIN /* ɉɨɢɫɤ ɬɨɜɚɪɚ */ SELECT Count(*) FROM Products WHERE ProductName=:NewName into :cnt; IF (Cnt = 0) THEN /* ȿɫɥɢ ɧɟɬ ɬɚɤɨɝɨ, ɞɨɛɚɜɢɬɶ */ INSERT INTO Products (ProductName, Price, Rest) VALUES(:NewName, :NewPrice, :newRest); ELSE /* ɂɧɚɱɟ ɭɜɟɥɢɱɢɬɶ ɤɨɥɢɱɟɫɬɜɨ */ UPDATE Products SET Rest=Rest+ :NewRest WHERE ProductName=:NewName; END Ⱦɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɏɉ ɧɚɫɬɪɨɣɬɟ ɤɨɦɩɨɧɟɧɬ spAddProduct: TIBStoredProc ɧɚ ɫɨɟɞɢɧɟɧɢɟ ɫ ȻȾ, ɫɜɹɠɢɬɟ ɫ ɬɪɚɧɡɚɤɰɢɟɣ ɢ ɭɤɚɠɢɬɟ ɜ ɫɨɨɬ-
ɜɟɬɫɬɜɭɸɳɟɦ ɫɜɨɣɫɬɜɟ ɢɦɹ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ. Ɍɢɩɨɜɚɹ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɞɟɣɫɬɜɢɣ: if not ibtSklad.Active then Ibt.StartTransaction; with spAddProduct do begin try Params[0].AsString := eProdName.Text; // Ɉɛɪɚɳɚɟɦɫɹ ɤ ɩɚɪɚɦɟɬɪɚɦ ɩɨ ɩɨɪɹɞɤɨɜɨɦɭ ɧɨɦɟɪɭ. // Ɇɨɠɧɨ ɬɚɤɠɟ ɩɨ ɢɦɟɧɢ: // ParamByName(‘NewName’).AsString:=eProdName.Text; Params[1].AsString := StrToFloat(ePrice.Text); Params[2].AsString := StrToInt(eRest.Text); Prepare; // ɉɨɞɝɨɬɨɜɤɚ ɏɉ ɤ ɜɵɩɨɥɧɟɧɢɸ ExecProc; // ȼɵɩɨɥɧɟɧɢɟ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ Ibt.Commit; except // Ɂɞɟɫɶ ɛɭɞɭɬ «ɨɬɥɨɜɥɟɧɵ» ɢ ɤɨɧɮɥɢɤɬɵ, ɢ ɨɲɢɛɤɢ ɜɜɨɞɚ MessageDlg('Ɉɲɢɛɤɚ ɡɚɩɢɫɢ!', mtError, [mbOk],0); Ibt.RollBack; end; end;
Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ, ɱɬɨ ɞɚɧɧɵɟ ɜ ɤɨɦɩɨɧɟɧɬɵ TEdit ɜɜɟɞɟɧɵ ɞɨ ɫɬɚɪɬɚ ɬɪɚɧɡɚɤɰɢɢ. 52
ɉɨɦɢɦɨ ɩɟɪɟɱɢɫɥɟɧɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ, ɜ ɩɪɨɝɪɚɦɦɚɯ ɦɨɝɭɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɬɚɤɠɟ ɫɥɟɞɭɸɳɢɟ [5]. Ʉɨɦɩɨɧɟɧɬ ɩɪɟɞɧɚɡɧɚɱɟɧ ɞɥɹ ɛɵɫɬɪɨɝɨ ɜɵɩɨɥɧɟɧɢɹ SQL-ɡɚɩɪɨɫɨɜ. ȼ ɨɬɥɢɱɢɟ ɨɬ ɪɚɫɫɦɨɬɪɟɧɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ, ɹɜɥɹɸɳɢɯɫɹ ɩɨɬɨɦɤɚɦɢ TDataSet, ɨɧ ɩɪɨɢɫɯɨɞɢɬ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɨɬ Tɋomponent, ɧɟ ɭɦɟɟɬ ɨɬɨɛɪɚɠɚɬɶɫɹ ɜ ɜɢɡɭɚɥɶɧɵɯ ɤɨɦɩɨɧɟɧɬɚɯ ɢ ɢɫɩɨɥɶɡɭɟɬ ɨɞɧɨɧɚɩɪɚɜɥɟɧɧɵɣ ɤɭɪɫɨɪ. ɉɟɪɟɦɟɳɟɧɢɟ ɩɨ ɧɚɛɨɪɭ ɞɚɧɧɵɯ, ɜɨɡɜɪɚɳɚɟɦɨɦɭ ɤɨɦɩɨɧɟɧɬɨɦ, ɩɪɨɢɫɯɨɞɢɬ ɬɨɥɶɤɨ ɜ ɨɞɧɨɦ ɧɚɩɪɚɜɥɟɧɢɢ – ɜɧɢɡ, ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɦɟɬɨɞɚ Next. ȼɵɩɨɥɧɹɟɬɫɹ ɡɚɩɪɨɫ ɜɵɡɨɜɨɦ ɦɟɬɨɞɚ ExecQuery. TIBEvents ɉɨɡɜɨɥɹɟɬ ɪɟɝɢɫɬɪɢɪɨɜɚɬɶ ɢ ɫɢɧɯɪɨɧɧɨ ɨɛɪɚɛɚɬɵɜɚɬɶ ɫɨɨɛɳɟɧɢɹ ɨ ɫɨɛɵɬɢɹɯ, ɝɟɧɟɪɢɪɭɟɦɵɯ ɫɟɪɜɟɪɨɦ TIBDataȼɨɡɜɪɚɳɚɟɬ ɢɧɮɨɪɦɚɰɢɸ ɨ ɩɨɞɤɥɸɱɟɧɧɨɣ ɛɚɡɟ baseInfo ɞɚɧɧɵɯ InterBase (ɤɨɥɢɱɟɫɬɜɨ ɜɵɞɟɥɟɧɧɵɯ ɤɷɲɛɭɮɟɪɨɜ, ɤɨɥɢɱɟɫɬɜɨ ɩɪɨɱɢɬɚɧɧɵɯ ɢ ɡɚɩɢɫɚɧɧɵɯ ɫɬɪɚɧɢɰ ɢ ɬ. ɞ.) TIBSQLMonitor Ɉɫɭɳɟɫɬɜɥɹɟɬ ɦɨɧɢɬɨɪɢɧɝ ɞɢɧɚɦɢɱɟɫɤɢɯ SQLɨɩɟɪɚɬɨɪɨɜ, ɩɟɪɟɞɚɜɚɟɦɵɯ ɧɚ InterBase-ɫɟɪɜɟɪ TIBSQL
3.6. Ɍɪɚɧɡɚɤɰɢɢ ɢ ɤɷɲɢɪɨɜɚɧɧɵɟ ɢɡɦɟɧɟɧɢɹ Ʉɷɲɢɪɨɜɚɧɢɟ ɢɡɦɟɧɟɧɢɣ (Ʉɂ) ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɫɨɡɞɚɧɢɢ ɧɚ ɤɥɢɟɧɬɫɤɨɣ ɦɚɲɢɧɟ ɞɨɩɨɥɧɢɬɟɥɶɧɨɝɨ ɛɭɮɟɪɚ (ɤɷɲɚ), ɜ ɤɨɬɨɪɨɦ ɯɪɚɧɹɬɫɹ ɢɡɦɟɧɹɟɦɵɟ ɡɚɩɢɫɢ. ȼɫɟ ɢɡɦɟɧɟɧɢɹ ɡɚɧɨɫɹɬɫɹ ɜ ɛɭɮɟɪ, ɚ ɜ ȻȾ ɩɟɪɟɧɨɫɹɬɫɹ «ɩɚɤɟɬɨɦ» – ɮɢɤɫɢɪɭɸɬɫɹ – ɩɪɢ ɜɵɡɨɜɟ ɦɟɬɨɞɚ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ ApplyUpdates. ɉɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɤɷɲ ɦɨɠɟɬ ɛɵɬɶ ɨɱɢɳɟɧ ɨɬ ɭɠɟ ɡɚɮɢɤɫɢɪɨɜɚɧɧɵɯ ɢɡɦɟɧɟɧɢɣ – ɦɟɬɨɞ CommitUpdates – ɢɥɢ ɨɱɢɳɟɧ ɛɟɡ ɮɢɤɫɚɰɢɢ ɢɡɦɟɧɟɧɢɣ – ɦɟɬɨɞ CancelUpdates. ȿɫɥɢ ɧɟɨɛɯɨɞɢɦɨ ɩɟɪɟɞɚɬɶ ɧɚ ɫɟɪɜɟɪ Ʉɂ ɫɪɚɡɭ ɧɟɫɤɨɥɶɤɢɯ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ, ɬɨ ɭɞɨɛɧɟɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɨɞɧɨɢɦɟɧɧɵɣ ɦɟɬɨɞ ɤɨɦɩɨɧɟɧɬɚ TIBDataBase: procedure ApplyUpdates(const DataSets: array of TDataSet); ɇɚɩɪɢɦɟɪ, IbDB.ApplyUpdates([idsOrders, iqProducts]);
Ʉɷɲɢɪɨɜɚɧɢɟ ɢɡɦɟɧɟɧɢɣ ɜɟɫɶɦɚ ɩɨɥɟɡɧɨ, ɬɚɤ ɤɚɤ ɭɦɟɧɶɲɚɟɬ ɫɟɬɟɜɨɣ ɬɪɚɮɢɤ ɢ ɩɨɦɨɝɚɟɬ ɪɟɞɚɤɬɢɪɨɜɚɬɶ ɡɚɩɪɨɫɵ «read only». 53
Ʉɷɲɢɪɨɜɚɧɢɟ ɢɡɦɟɧɟɧɢɣ ɦɨɠɧɨ ɨɪɝɚɧɢɡɨɜɚɬɶ ɫ ɩɨɦɨɳɶɸ ɤɨɦɩɨɧɟɧɬɨɜ TIBDataSet, TIBTable, TIBQuery. Ⱦɥɹ ɩɟɪɟɜɨɞɚ ɇȾ ɜ ɪɟɠɢɦ ɤɷɲɢɪɨɜɚɧɧɵɯ ɢɡɦɟɧɟɧɢɣ ɜ ɤɨɦɩɨɧɟɧɬɚɯ TIBDataSet, TIBTable, TIBQuery ɧɟɨɛɯɨɞɢɦɨ ɭɫɬɚɧɨɜɢɬɶ ɫɜɨɣɫɬɜɨ CachedUpdates ɜ True (ɩɨ ɭɦɨɥɱɚɧɢɸ ɨɧɨ ɪɚɜɧɨ False). Ʉɨɦɩɨɧɟɧɬ TIBQuery ɞɨɩɨɥɧɢɬɟɥɶɧɨ ɧɟɨɛɯɨɞɢɦɨ ɫɜɹɡɚɬɶ ɫ TIBUpdateSQL [5]. ȼɚɠɧɨ ɩɨɦɧɢɬɶ, ɱɬɨ ɜ ɪɟɠɢɦɟ ɤɷɲɢɪɨɜɚɧɧɵɯ ɢɡɦɟɧɟɧɢɣ ɦɟɬɨɞ Post ɫɨɯɪɚɧɹɟɬ ɜɜɟɞɟɧɧɵɟ ɡɧɚɱɟɧɢɹ ɬɨɥɶɤɨ ɜ ɧɚɛɨɪɟ ɞɚɧɧɵɯ ɧɚ ɤɥɢɟɧɬɟ, ɧɚ ɫɟɪɜɟɪ ɷɬɢ ɢɡɦɟɧɟɧɢɹ ɧɟ ɩɨɩɚɞɭɬ, ɩɨɤɚ ɧɟ ɛɭɞɟɬ ɜɵɡɜɚɧ ɦɟɬɨɞ ApplyUpdates. ɗɬɨɬ ɮɚɤɬ ɬɚɤɠɟ ɜɥɢɹɟɬ ɢ ɧɚ ɜɡɚɢɦɨɞɟɣɫɬɜɢɟ ɬɪɚɧɡɚɤɰɢɣ. Ⱦɥɹ ɩɪɢɦɟɪɚ ɜɢɞɨɢɡɦɟɧɢɦ ɩɪɨɟɤɬ ɢɡ ɪɚɫɫɦɨɬɪɟɧɧɵɣ ɪɚɧɟɟ ɥɚɛɨɪɚɬɨɪɧɨɣ ɪɚɛɨɬɵ, ɭɫɬɚɧɨɜɢɜ ɭ ɬɚɛɥɢɰ ɫɜɨɣɫɬɜɨ CachedUpdates ɜ True ɢ ɞɨɛɚɜɢɜ ɟɳɟ ɨɞɧɭ ɤɧɨɩɤɭ, ɜɵɡɵɜɚɸɳɭɸ ApplyUpdates. Ɂɚɩɭɫɬɢɦ ɞɜɚ ɷɤɡɟɦɩɥɹɪɚ ɷɬɨɣ ɩɪɨɝɪɚɦɦɵ. ɍɛɟɞɢɦɫɹ, ɱɬɨ ɜɵɡɨɜ ɦɟɬɨɞɚ Post ɩɪɢ ɨɞɧɨɜɪɟɦɟɧɧɨɦ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ «ɫɟɬɤɢ» ɜ ɞɜɭɯ ɩɪɨɝɪɚɦɦɚɯ ɭɠɟ ɧɟ ɩɪɢɜɨɞɢɬ ɤ ɤɨɧɮɥɢɤɬɚɦ ɨɛɧɨɜɥɟɧɢɹ. Ⱦɟɣɫɬɜɢɬɟɥɶɧɨ, ɩɨɜɨɞɨɜ ɞɥɹ ɤɨɧɮɥɢɤɬɨɜ ɧɟɬ, ɬɚɤ ɤɚɤ ɧɟɬ ɢɡɦɟɧɟɧɢɣ ɜ ɬɚɛɥɢɰɚɯ ɧɚ ɫɟɪɜɟɪɟ. Ʉɨɧɮɥɢɤɬɵ ɜɨɡɧɢɤɧɭɬ ɬɨɥɶɤɨ, ɟɫɥɢ ɜ ɨɞɧɨɣ ɢɡ ɩɪɨɝɪɚɦɦ ɜɵɡɜɚɧ ɦɟɬɨɞ ApplyUpdates. Ɉɬɫɸɞɚ ɫɥɟɞɭɟɬ, ɱɬɨ ApplyUpdates ɧɟɨɛɯɨɞɢɦɨ ɜɵɡɵɜɚɬɶ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɩɟɪɟɞ ɮɢɤɫɚɰɢɟɣ ɬɪɚɧɡɚɤɰɢɢ (Commit). Ɍɨɝɞɚ ɱɚɫɬɶ ɬɪɚɧɡɚɤɰɢɢ, ɫɜɹɡɚɧɧɚɹ ɫ ɪɟɞɚɤɬɢɪɨɜɚɧɢɟɦ, ɧɟ ɛɭɞɟɬ «ɡɚɬɹɧɭɜɲɟɣɫɹ» ɜɨ ɜɪɟɦɟɧɢ, ɢ ɜɟɪɨɹɬɧɨɫɬɶ ɤɨɧɮɥɢɤɬɨɜ ɭɦɟɧɶɲɢɬɫɹ (ɡɚɦɟɱɚɧɢɟ ɤ ɩ. 3.5.3). ȼ ɫɥɭɱɚɟ ɤɷɲɢɪɨɜɚɧɧɵɯ ɢɡɦɟɧɟɧɢɣ ɬɢɩɢɱɧɚɹ ɬɪɚɧɡɚɤɰɢɹ ɢɦɟɟɬ ɜɢɞ: if not ibt.Active then ibt.StartTransaction; // ɇɚɱɚɥɨ ɬɪɚɧɡɚɤɰɢɢ try idsOrders.Open; idsProducts.Open; // ɂɡɦɟɧɟɧɢɟ ɞɚɧɧɵɯ … idsOrders.Post; idsProducts.Post; IbDB.ApplyUpdates([idsOrders, idsProducts]); ibt.Commit; // ɉɪɢɦɟɧɟɧɢɟ ɬɪɚɧɡɚɤɰɢɢ except ibt.RollBack; // Ɉɬɤɚɬ ɬɪɚɧɡɚɤɰɢɢ // Ⱦɚɥɟɟ ɩɪɨɢɫɯɨɞɢɬ ɨɬɦɟɧɚ ɢɡɦɟɧɟɧɢɣ. // ȿɫɥɢ ɨɲɢɛɤɚ ɢɡ-ɡɚ ɤɨɧɮɥɢɤɬɚ, ɬɨ ɥɭɱɲɟ ɢɯ ɧɟ ɨɬɦɟɧɹɬɶ, // ɱɬɨɛɵ ɫɧɨɜɚ ɧɟ ɜɜɨɞɢɬɶ ɞɚɧɧɵɟ ɩɟɪɟɞ ɩɨɜɬɨɪɧɵɦ ɜɵɡɨɜɨɦ // Commit idsOrders.CancelUdates; idsProducts.CancelUpdates; ShowMessage('Ɉɲɢɛɤɚ ɬɪɚɧɡɚɤɰɢɢ!'); end;
54
Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɟɫɥɢ ɩɪɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ ɬɚɛɥɢɰ ɢɫɩɨɥɶɡɭɟɬɫɹ ɩɨɞɯɨɞ, ɨɫɧɨɜɚɧɧɵɣ ɧɚ ɧɚɛɨɪɚɯ ɞɚɧɧɵɯ ɢ ɤɨɦɩɨɧɟɧɬɚɯ, ɱɭɜɫɬɜɢɬɟɥɶɧɵɯ ɤ ɞɚɧɧɵɦ, ɬɨ ɦɟɯɚɧɢɡɦ Ʉɂ ɦɨɠɟɬ ɭɥɭɱɲɢɬɶ ɦɧɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɭɸ ɪɚɛɨɬɭ ɡɚ ɫɱɟɬ ɫɨɤɪɚɳɟɧɢɹ ɬɪɚɮɢɤɚ ɜ ɫɟɬɢ ɢ ɭɦɟɧɶɲɟɧɢɹ ɩɪɨɞɨɥɠɢɬɟɥɶɧɨɫɬɢ ɛɥɨɤɢɪɨɜɨɤ ɩɪɢ ɡɚɩɢɫɢ. ȼ ɱɚɫɬɧɨɫɬɢ, Ʉɂ ɭɞɨɛɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɩɪɢ ɨɪɝɚɧɢɡɚɰɢɢ ɬɨɪɝɨɜɥɢ ɜ Internet-ɦɚɝɚɡɢɧɚɯ ɢ ɜ ɞɪɭɝɢɯ ɫɢɬɭɚɰɢɹɯ, ɤɨɝɞɚ ɬɪɟɛɭɟɬɫɹ ɞɥɢɬɟɥɶɧɚɹ ɪɚɛɨɬɚ ɫ ɤɥɢɟɧɬɨɦ ɩɨ ɮɨɪɦɢɪɨɜɚɧɢɸ ɡɚɤɚɡɚ. ȿɫɥɢ ɠɟ ɬɪɟɛɭɟɬɫɹ ɨɩɟɪɚɬɢɜɧɚɹ ɡɚɩɢɫɶ ɜ ȻȾ ɜ ɫɢɫɬɟɦɚɯ ɫ ɨɝɪɚɧɢɱɟɧɧɵɦɢ ɪɟɫɭɪɫɚɦɢ, ɧɚɩɪɢɦɟɪ ɩɪɢ ɛɪɨɧɢɪɨɜɚɧɢɢ ɚɜɢɚɛɢɥɟɬɨɜ, ɥɭɱɲɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɯɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ. ɉɪɢɦɟɱɚɧɢɟ. Ʉɨɧɰɟɩɰɢɹ ɤɷɲɢɪɨɜɚɧɧɵɯ ɢɡɦɟɧɟɧɢɣ ɩɨɥɭɱɢɥɚ ɥɨɝɢɱɟɫɤɨɟ ɩɪɨɞɨɥɠɟɧɢɟ ɜ ɬɟɯɧɨɥɨɝɢɢ ADO.NET ɮɢɪɦɵ Microsoft [3]. Ɉɛɴɟɤɬ ɤɥɚɫɫɚ DataSet ɜ ADO.NET, ɹɜɥɹɸɳɢɣɫɹ «ɫɥɟɩɤɨɦ» ɮɪɚɝɦɟɧɬɚ ɛɚɡɵ ɞɚɧɧɵɯ ɫɨ ɜɫɟɦɢ ɪɟɥɹɰɢɨɧɧɵɦɢ ɫɜɹɡɹɦɢ ɢ ɨɝɪɚɧɢɱɟɧɢɹɦɢ, ɞɚɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɪɚɛɨɬɵ ɫ ɧɚɛɨɪɚɦɢ ɞɚɧɧɵɯ ɜɨɨɛɳɟ ɩɪɢ ɨɬɫɭɬɫɬɜɢɢ ɫɨɟɞɢɧɟɧɢɹ ɫ ɫɟɪɜɟɪɨɦ! ɉɨ ɨɤɨɧɱɚɧɢɢ ɪɚɛɨɬɵ ɢɡɦɟɧɟɧɢɹ ɩɟɪɟɧɨɫɹɬɫɹ ɧɚ ɫɟɪɜɟɪ. Ɋɚɡɭɦɟɟɬɫɹ, ɜ ADO.NET ɢɦɟɸɬɫɹ ɫɪɟɞɫɬɜɚ ɢ ɞɥɹ ɛɨɥɟɟ ɨɩɟɪɚɬɢɜɧɨɣ ɪɚɛɨɬɵ ɫ ȻȾ. Ɉɬɦɟɬɢɦ, ɱɬɨ ɪɚɫɫɦɨɬɪɟɧɧɵɟ ɜɵɲɟ ɧɚɛɨɪɵ ɞɚɧɧɵɯ Delphi ɜ ɩɪɢɧɰɢɩɟ ɧɟ ɦɨɝɭɬ ɪɚɛɨɬɚɬɶ ɜ ɨɬɫɭɬɫɬɜɢɟ ɫɨɟɞɢɧɟɧɢɹ. 3.7. Ʉɨɦɩɨɧɟɧɬɵ ɭɩɪɚɜɥɟɧɢɹ ɞɚɧɧɵɦɢ Ⱦɚɧɧɚɹ ɝɪɭɩɩɚ ɤɨɦɩɨɧɟɧɬɨɜ ɫɨɫɪɟɞɨɬɨɱɟɧɚ ɧɚ ɩɚɥɢɬɪɟ DataControls ɜ Delphi, ɩɪɟɞɧɚɡɧɚɱɟɧɚ ɞɥɹ ɨɬɨɛɪɚɠɟɧɢɹ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɡɚɩɢɫɟɣ ɧɚɛɨɪɚ ɞɚɧɧɵɯ ɢ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɨɜɦɟɫɬɧɨ ɫ ɤɨɦɩɨɧɟɧɬɚɦɢ TDataSet (ɩ. 3.5). Ʉɨɦɩɨɧɟɧɬɵ DataControls ɧɟ ɡɚɜɢɫɹɬ ɨɬ ɜɵɛɪɚɧɧɨɣ ɬɟɯɧɨɥɨɝɢɢ ɞɨɫɬɭɩɚ ɢ ɢɫɬɨɱɧɢɤɚ ɞɚɧɧɵɯ, ɯɨɪɨɲɨ ɢɡɭɱɟɧɵ ɢ ɩɨɞɪɨɛɧɨ ɨɩɢɫɚɧɵ ɜ ɥɢɬɟɪɚɬɭɪɟ [4– 5]. ɉɨɷɬɨɦɭ, ɧɟ ɭɝɥɭɛɥɹɹɫɶ ɜ ɞɟɬɚɥɢ, ɨɬɦɟɬɢɦ ɥɢɲɶ ɧɟɫɤɨɥɶɤɨ ɜɚɠɧɵɯ ɮɚɤɬɨɜ ɢ ɩɪɢɧɰɢɩɢɚɥɶɧɵɯ ɦɨɦɟɧɬɨɜ. ɇɚɜɢɝɚɬɨɪ DBNavigator ɜɵɡɵɜɚɟɬ ɦɟɬɨɞɵ ɧɚɛɨɪɚ ɞɚɧɧɵɯ (ɤɥɚɫɫɚ TDataSet) ɞɥɹ ɪɚɛɨɬɵ ɫ ɬɟɤɭɳɟɣ ɡɚɩɢɫɶɸ, ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɤɨɧɬɪɨɥɢɪɭɹ ɫɨɫɬɨɹɧɢɟ ɧɚɛɨɪɚ ɞɚɧɧɵɯ (ɫɜɨɣɫɬɜɨ State: TDataSetState). ȿɫɥɢ ɫɨɫɬɨɹɧɢɟ ɧɟ ɩɨɡɜɨɥɹɟɬ ɜɵɡɜɚɬɶ ɦɟɬɨɞ, ɤɧɨɩɤɚ ɧɚɜɢɝɚɬɨɪɚ ɧɟ ɞɨɫɬɭɩɧɚ. ɇɚɩɨɦɧɢɦ, ɱɬɨ ɦɟɬɨɞɵ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ (ɬ. ɟ. ɤɨɦɩɨɧɟɧɬɨɜ TIBTable, TIBQuery ɢ ɚɧɚɥɨɝɢɱɧɵɯ) First, Prior, Next, Last ɩɟɪɟɦɟɳɚɸɬ ɭɤɚɡɚɬɟɥɶ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ. Ɇɟɬɨɞ Append ɜɫɬɚɜɥɹɟɬ ɩɭɫɬɭɸ ɡɚɩɢɫɶ ɢ ɩɟɪɟɜɨɞɢɬ ɇȾ ɜ ɫɨɫɬɨɹɧɢɟ dsInsert. Ɇɟɬɨɞ Delete ɭɞɚɥɹɟɬ ɬɟɤɭɳɭɸ ɡɚɩɢɫɶ, Edit ɩɟɪɟɜɨɞɢɬ ɇȾ ɜ ɫɨɫɬɨɹɧɢɟ dsEdit, ɱɬɨ ɩɨɡɜɨɥɹɟɬ ɪɟɞɚɤɬɢɪɨɜɚɬɶ ɬɟɤɭɳɭɸ ɡɚɩɢɫɶ. Ɇɟɬɨɞ Post ɩɟɪɟɞɚɟɬ ɢɡɦɟɧɟɧɧɭɸ ɡɚɩɢɫɶ ɧɚ ɫɟɪɜɟɪ (ɟɫɥɢ ɧɟ ɚɤɬɢɜɢɪɨɜɚɧ ɪɟɠɢɦ ɩɚɤɟɬɧɵɯ ɨɛɧɨɜɥɟɧɢɣ) ɢ ɩɟɪɟɜɨɞɢɬ ɇȾ ɜ 55
ɫɨɫɬɨɹɧɢɟ dsBrowse (ɬɨɥɶɤɨ ɩɪɨɫɦɨɬɪ). Post ɦɨɠɧɨ ɜɵɡɜɚɬɶ, ɟɫɥɢ ɇȾ ɧɚɯɨɞɢɥɫɹ ɜ ɫɨɫɬɨɹɧɢɢ dsInsert ɢɥɢ dsEdit. Ɇɟɬɨɞ Cancel ɨɬɦɟɧɹɟɬ ɢɡɦɟɧɟɧɢɹ ɢ ɩɟɪɟɜɨɞɢɬ ɇȾ ɜ ɫɨɫɬɨɹɧɢɟ dsBrowse. Ɇɟɬɨɞ Refresh ɡɚɩɨɥɧɹɟɬ ɇȾ ɨɛɧɨɜɥɟɧɧɵɦɢ ɡɧɚɱɟɧɢɹɦɢ ɫ ɫɟɪɜɟɪɚ ɛɟɡ ɩɟɪɟɨɬɤɪɵɬɢɹ ɧɚɛɨɪɚ ɞɚɧɧɵɯ. Ȼɟɡ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɧɚɜɢɝɚɬɨɪɚ ɜɵɡɨɜ ɦɟɬɨɞɨɜ ɢ ɩɪɨɜɟɪɤɭ ɫɨɫɬɨɹɧɢɹ ɇȾ ɧɚɞɨ ɩɪɨɢɡɜɨɞɢɬɶ ɜɪɭɱɧɭɸ. ɇɨ ɷɬɨɬ «ɧɟɞɨɫɬɚɬɨɤ» ɨɛɨɪɚɱɢɜɚɟɬɫɹ ɩɪɟɢɦɭɳɟɫɬɜɚɦɢ, ɬɚɤ ɤɚɤ ɩɨɹɜɥɹɟɬɫɹ ɜɨɡɦɨɠɧɨɫɬɶ ɪɟɚɥɢɡɨɜɵɜɚɬɶ ɚɥɝɨɪɢɬɦɵ, ɩɪɨɜɟɪɹɬɶ ɢɫɤɥɸɱɢɬɟɥɶɧɵɟ ɫɢɬɭɚɰɢɢ ɢ ɬ. ɩ. ȼɫɟɝɞɚ ɥɢ ɧɟɨɛɯɨɞɢɦɨ ɹɜɧɨ ɜɵɡɵɜɚɬɶ Post ɢ Edit? ɇɟɬ. ɉɪɢ ɪɚɛɨɬɟ ɫ DBGrid ɦɟɬɨɞ Post ɜɵɡɵɜɚɟɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɪɢ ɜɵɯɨɞɟ ɢɡ ɹɱɟɣɤɢ. ȼɵɡɨɜ ɦɟɬɨɞɚ Edit ɡɚɜɢɫɢɬ ɨɬ ɡɧɚɱɟɧɢɹ ɫɜɨɣɫɬɜɚ AutoEdit ɤɨɦɩɨɧɟɧɬɚ DataSource, ɫɜɹɡɚɧɧɨɝɨ ɫ ɤɨɦɩɨɧɟɧɬɨɦ ɭɩɪɚɜɥɟɧɢɹ ɞɚɧɧɵɦɢ (DBGrid, DBEdit ɢ ɞɪɭɝɢɯ). ȿɫɥɢ AutoEdit = True (ɩɨ ɭɦɨɥɱɚɧɢɸ), ɬɨ Edit ɜɵɡɵɜɚɟɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ, ɤɚɤ ɬɨɥɶɤɨ ɫɬɪɨɤɚ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɩɨɥɭɱɢɬ ɫɨɛɵɬɢɟ ɨɬ ɤɥɚɜɢɚɬɭɪɵ ɫ ɞɨɩɭɫɬɢɦɵɦ ɤɨɞɨɦ ɫɢɦɜɨɥɚ. ɋɢɦɜɨɥɵ, ɧɟ ɞɨɩɭɫɬɢɦɵɟ ɞɥɹ ɞɚɧɧɨɝɨ ɬɢɩɚ ɫɬɨɥɛɰɚ, ɛɥɨɤɢɪɭɸɬɫɹ. ȿɫɥɢ AutoEdit = False, ɬɨ ɦɟɬɨɞ Edit ɧɚɞɨ ɜɵɡɵɜɚɬɶ ɹɜɧɨ ɢɥɢ ɫ ɩɨɦɨɳɶɸ ɤɧɨɩɤɢ ɧɚɜɢɝɚɬɨɪɚ. ɂɧɨɝɞɚ ɷɬɨ ɛɵɜɚɟɬ ɩɨɥɟɡɧɨ ɞɥɹ ɩɪɟɞɨɬɜɪɚɳɟɧɢɹ ɫɥɭɱɚɣɧɨɝɨ ɜɜɨɞɚ ɞɚɧɧɵɯ. Ɋɚɫɫɦɨɬɪɢɦ ɬɟɩɟɪɶ ɝɪɭɩɩɭ ɤɨɦɩɨɧɟɧɬɨɜ, ɩɪɟɞɧɚɡɧɚɱɟɧɧɵɯ ɞɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ. ȼ ɨɬɥɢɱɢɟ ɨɬ DBGrid, ɨɧɢ ɩɨɡɜɨɥɹɸɬ ɪɟɞɚɤɬɢɪɨɜɚɬɶ ɞɚɧɧɵɟ ɧɟ ɜ ɜɢɞɟ ɬɚɛɥɢɰ, ɚ ɜ ɜɢɞɟ ɮɨɪɦɵ. Ɍɚɛɥɢɰɵ (ɢɧɨɝɞɚ ɢɯ ɧɚɡɵɜɚɸɬ «ɫɟɬɤɢ») ɩɪɢɦɟɧɹɸɬɫɹ ɞɥɹ ɩɪɨɫɦɨɬɪɚ ɝɪɭɩɩɵ ɡɚɩɢɫɟɣ, ɚ ɜ ɮɨɪɦɟ, ɧɚɩɪɨɬɢɜ, ɨɬɨɛɪɚɠɚɟɬɫɹ ɬɨɥɶɤɨ ɨɞɧɚ ɬɟɤɭɳɚɹ ɡɚɩɢɫɶ, ɧɨ ɜ ɛɨɥɟɟ ɭɞɨɛɧɨɦ ɜɢɞɟ. ɉɨɩɪɨɛɭɣɬɟ, ɧɚɩɪɢɦɟɪ, ɩɪɟɞɫɬɚɜɢɬɶ ɫɟɛɟ ɫɟɬɤɭ ɫ 10 ɤɨɥɨɧɤɚɦɢ. ȼɫɟ ɪɚɫɫɦɚɬɪɢɜɚɟɦɵɟ ɤɨɦɩɨɧɟɧɬɵ ɢɦɟɸɬ ɫɜɨɣɫɬɜɨ DataSource: TDataSource, ɜ ɤɨɬɨɪɨɦ ɯɪɚɧɢɬɫɹ ɢɦɹ ɢɫɬɨɱɧɢɤɚ ɞɚɧɧɵɯ ɢ DataField: String, ɜ ɤɨɬɨɪɨɦ ɡɚɩɢɫɵɜɚɟɬɫɹ ɢɦɹ ɩɨɥɹ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ ɇȾ, ɨɬɨɛɪɚɠɚɟɦɨɟ ɜ ɤɨɦɩɨɧɟɧɬɟ. Ʉɨɦɩɨɧɟɧɬ DBText ɨɬɨɛɪɚɠɚɟɬ ɩɨɥɟ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ, ɭɤɚɡɚɧɧɨɟ ɜ ɟɝɨ ɫɜɨɣɫɬɜɟ DataField, ɜ ɪɟɠɢɦɟ «ɬɨɥɶɤɨ ɞɥɹ ɱɬɟɧɢɹ». DBEdit ɩɨɡɜɨɥɹɟɬ ɷɬɨ ɩɨɥɟ ɪɟɞɚɤɬɢɪɨɜɚɬɶ ɢ ɫɨɯɪɚɧɹɬɶ ɜɵɡɨɜɨɦ ɦɟɬɨɞɚ Post ɇȾ. DBMemo ɢ DBImage ɩɪɟɞɧɚɡɧɚɱɟɧɵ ɞɥɹ ɨɬɨɛɪɚɠɟɧɢɹ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɦɧɨɝɨɫɬɪɨɱɧɵɯ ɬɟɤɫɬɨɜɵɯ ɢ ɝɪɚɮɢɱɟɫɤɢɯ ɩɨɥɟɣ ɫɨɨɬɜɟɬɫɬɜɟɧɧɨ. Ʉɨɦɩɨɧɟɧɬɵ DBListBox (ɫɩɢɫɨɤ) ɢ DBComboBox (ɤɨɦɛɢɧɢɪɨɜɚɧɧɵɣ ɫɩɢɫɨɤ) ɩɨɞɨɛɧɵ ɫɬɚɧɞɚɪɬɧɵɦ ɤɨɦɩɨɧɟɧɬɚɦ Delphi ɫɨ ɫɯɨɠɢɦ ɧɚɡɜɚɧɢɟɦ. ɂɯ ɡɚɞɚɱɟɣ ɹɜɥɹɟɬɫɹ ɜɜɨɞ ɜ ɩɨɥɟ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ ɩɪɟɞɨɩɪɟɞɟɥɟɧɧɵɯ ɡɧɚɱɟɧɢɣ, ɤɨɬɨɪɵɟ ɜɵɛɢɪɚɸɬɫɹ ɢɡ ɫɩɢɫɤɚ, ɧɨ ɧɟ ɯɪɚɧɹɬɫɹ ɜ ɛɚɡɟ ɞɚɧɧɵɯ. ɋɩɢɫɨɤ ɩɪɟɞɫɬɚɜɥɟɧ ɫɜɨɣɫɬɜɨɦ Items: TStrings. ɇɚɩɪɢɦɟɪ, ɜ ɬɚɛɥɢɰɟ Products ɟɫɬɶ ɩɨɥɟ Warranty (ɝɚɪɚɧɬɢɹ), ɤɨɬɨɪɨɟ ɦɨɠɟɬ ɩɪɢɧɢɦɚɬɶ 56
ɬɨɥɶɤɨ ɡɧɚɱɟɧɢɹ 6 ɦɟɫ., 12 ɦɟɫ., 24 ɦɟɫ. Ɂɚɧɟɫɢɬɟ ɢɯ ɜ Items ɩɪɨɝɪɚɦɦɧɨ ɢɥɢ ɫ ɩɨɦɨɳɶɸ ɢɧɫɩɟɤɬɨɪɚ ɨɛɴɟɤɬɨɜ, ɩɨɫɥɟ ɱɟɝɨ ɷɬɢ ɬɪɢ ɡɧɚɱɟɧɢɹ ɛɭɞɭɬ ɜɵɛɢɪɚɬɶɫɹ ɢɡ ɫɩɢɫɤɚ ɩɪɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɢ. Ʉɨɦɩɨɧɟɧɬɵ DBLookUpListBox ɢ DBLookUpComboBox ɩɪɟɞɧɚɡɧɚɱɟɧɵ ɞɥɹ ɡɚɩɨɥɧɟɧɢɹ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ ɞɨɱɟɪɧɟɣ ɬɚɛɥɢɰɵ ɞɚɧɧɵɦɢ, ɜɵɛɪɚɧɧɵɦɢ ɢɡ ɪɨɞɢɬɟɥɶɫɤɨɣ ɬɚɛɥɢɰɵ (ɩ. 3.3.5). ɋɜɨɣɫɬɜɚ ListSource ɢ ListField ɭɤɚɡɵɜɚɸɬ ɧɚ ɬɚɛɥɢɰɭ, ɨɬɤɭɞɚ ɛɟɪɭɬɫɹ ɞɚɧɧɵɟ, DataSource ɢ DataField – ɧɚ ɬɚɛɥɢɰɭ, ɤɭɞɚ ɛɭɞɭɬ ɩɨɞɫɬɚɜɥɹɬɶɫɹ ɞɚɧɧɵɟ. KeyField – ɩɨɥɟ ɪɨɞɢɬɟɥɶɫɤɨɣ ɬɚɛɥɢɰɵ (ListSource), ɤɨɬɨɪɨɟ ɛɭɞɟɬ ɩɨɞɫɬɚɜɥɹɬɶɫɹ ɜ ɩɨɥɟ DataField. Ʉɨɦɩɨɧɟɧɬ DBCheckBox ɭɞɨɛɟɧ, ɤɨɝɞɚ ɧɚɞɨ ɜɜɨɞɢɬɶ ɨɞɧɨ ɢɡ ɞɜɭɯ ɡɧɚɱɟɧɢɣ. ȿɫɥɢ ɤɨɦɩɨɧɟɧɬ ɜɤɥɸɱɟɧ (Checked), ɬɨ ɜ ɫɜɹɡɚɧɧɨɟ ɩɨɥɟ ɇȾ ɩɨɞɫɬɚɜɥɹɟɬɫɹ ɡɧɚɱɟɧɢɟ, ɭɤɚɡɚɧɧɨɟ ɜ ɫɜɨɣɫɬɜɟ ValueChecked, ɢɧɚɱɟ – ɜ ValueUnchecked. Ʉɨɦɩɨɧɟɧɬ DBRadioGroup ɩɨɯɨɠ ɧɚ DBListBox. ȼ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɩɨɥɨɠɟɧɢɹ ɩɟɪɟɤɥɸɱɚɬɟɥɹ ɜ ɩɨɥɟ ɩɨɞɫɬɚɜɥɹɸɬɫɹ ɡɧɚɱɟɧɢɹ, ɡɚɞɚɧɧɵɟ ɜ ɫɜɨɣɫɬɜɟ Values: TStrings. Ɉɛɨɡɧɚɱɟɧɢɹ ɡɧɚɱɟɧɢɣ ɯɪɚɧɹɬɫɹ ɜ ɫɜɨɣɫɬɜɟ Items: TStrings. ȼɵɜɨɞɵ. 1. Ɉɬɥɢɱɢɬɟɥɶɧɨɣ ɨɫɨɛɟɧɧɨɫɬɶɸ ɪɚɫɫɦɨɬɪɟɧɧɵɯ ɜɵɲɟ ɤɨɦɩɨɧɟɧɬɨɜ ɹɜɥɹɟɬɫɹ «ɩɪɢɜɹɡɤɚ» ɤ ɬɟɤɭɳɟɣ ɡɚɩɢɫɢ ɧɚɛɨɪɚ ɞɚɧɧɵɯ, ɤɨɬɨɪɚɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɢɡɦɟɧɹɟɬɫɹ ɜ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɜɜɟɞɟɧɧɨɝɨ ɜ ɤɨɦɩɨɧɟɧɬ ɡɧɚɱɟɧɢɹ. ɉɨɷɬɨɦɭ ɢɯ ɱɚɫɬɨ ɧɚɡɵɜɚɸɬ «ɤɨɦɩɨɧɟɧɬɵ, ɱɭɜɫɬɜɢɬɟɥɶɧɵɟ ɤ ɞɚɧɧɵɦ». ɑɬɨɛɵ ɩɟɪɟɧɟɫɬɢ ɡɧɚɱɟɧɢɹ ɢɡ ɧɚɛɨɪɚ ɞɚɧɧɵɯ ɜ ɬɚɛɥɢɰɵ ɫɟɪɜɟɪɚ, ɧɟɨɛɯɨɞɢɦɨ ɜɵɡɵɜɚɬɶ ɦɟɬɨɞ Post. 2. ɉɪɟɢɦɭɳɟɫɬɜɨɦ ɩɟɪɟɞ ɚɧɚɥɨɝɢɱɧɵɦɢ ɫɬɚɧɞɚɪɬɧɵɦɢ ɤɨɦɩɨɧɟɧɬɚɦɢ (ɧɚɩɪɢɦɟɪ, TEdit) ɹɜɥɹɟɬɫɹ ɛɥɨɤɢɪɨɜɤɚ ɧɟɩɪɚɜɢɥɶɧɨɝɨ ɜɜɨɞɚ. ɇɚɩɪɢɦɟɪ, TDBEdit ɧɟ ɩɨɡɜɨɥɹɟɬ ɜɜɟɫɬɢ ɡɧɚɱɟɧɢɹ, ɬɢɩ ɤɨɬɨɪɵɯ ɨɬɥɢɱɚɟɬɫɹ ɨɬ ɬɢɩɚ ɫɬɨɥɛɰɚ ɬɚɛɥɢɰɵ. 3. ȼ ɰɟɥɨɦ ɞɚɧɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɦɨɝɭɬ ɩɪɢɜɨɞɢɬɶ ɤ ɛɨɥɟɟ ɞɥɢɧɧɵɦ ɬɪɚɧɡɚɤɰɢɹɦ, ɱɟɦ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɵɣ ɜɵɡɨɜ ɦɨɞɢɮɢɰɢɪɭɸɳɢɯ SQL ɡɚɩɪɨɫɨɜ ɱɟɪɟɡ TIBStoredProc ɢɥɢ TIBQuery. ɉɨɷɬɨɦɭ ɩɪɢ ɢɯ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɧɟ ɫɥɟɞɭɟɬ ɭɤɚɡɵɜɚɬɶ ɡɚɜɵɲɟɧɧɵɣ ɭɪɨɜɟɧɶ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ. Ⱦɥɹ ɭɦɟɧɶɲɟɧɢɹ ɱɢɫɥɚ ɛɥɨɤɢɪɨɜɨɤ ɱɚɫɬɨ ɨɤɚɡɵɜɚɟɬɫɹ ɩɨɥɟɡɧɵɦ ɦɟɯɚɧɢɡɦ ɤɷɲɢɪɨɜɚɧɢɹ ɢɡɦɟɧɟɧɢɣ. Ɉɬɨɛɪɚɠɟɧɢɟ ɞɚɧɧɵɯ – ɨɬɧɨɫɢɬɟɥɶɧɨ ɫɥɚɛɨɟ ɡɜɟɧɨ ɤɨɦɩɨɧɟɧɬɨɜ Delphi. ȼ ɩɪɨɮɟɫɫɢɨɧɚɥɶɧɵɯ ɩɪɨɟɤɬɚɯ ɦɧɨɝɢɟ ɤɨɦɩɨɧɟɧɬɵ (ɱɚɳɟ ɜɫɟɝɨ ɷɬɨ ɤɚɫɚɟɬɫɹ DBGrid) ɜɵɝɥɹɞɹɬ ɫɥɢɲɤɨɦ ɩɪɢɦɢɬɢɜɧɨ, ɧɚɩɪɢɦɟɪ, ɨɧɢ «ɧɟ ɭɦɟɸɬ» ɫɬɪɭɤɬɭɪɢɪɨɜɚɬɶ ɢɧɮɨɪɦɚɰɢɸ ɜ ɜɢɞɟ ɞɟɪɟɜɶɟɜ (Tree). ɉɨɷɬɨɦɭ ɪɚɡɪɚɛɨɬɱɢɤɢ ɨɯɨɬɧɨ ɩɪɢɛɟɝɚɸɬ ɤ ɤɨɦɩɨɧɟɧɬɚɦ ɫɬɨɪɨɧɧɢɯ ɮɢɪɦ (ɧɚɩɪɢ57
ɦɟɪ, DevExpress, ɫɚɣɬ http://www.devexpress.com), ɜɨɡɦɨɠɧɨɫɬɢ ɭ ɤɨɬɨɪɵɯ ɨɝɪɚɧɢɱɟɧɵ ɬɨɥɶɤɨ ɧɚɫɬɨɣɱɢɜɨɫɬɶɸ ɜ ɢɯ ɢɡɭɱɟɧɢɢ. ɇɚɩɪɢɦɟɪ, ɪɚɫɫɦɨɬɪɟɧɧɚɹ ɧɚɦɢ ɭɬɢɥɢɬɚ IBExpert ɪɚɡɪɚɛɨɬɚɧɚ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɤɨɦɩɨɧɟɧɬɨɜ DevExpress ɢ FIBPlus. 4. ɉɪɢɦɟɪ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ 4.1. ɉɪɟɞɦɟɬɧɚɹ ɨɛɥɚɫɬɶ ȼ ɤɚɱɟɫɬɜɟ ɩɪɢɦɟɪɚ ɪɚɫɫɦɨɬɪɢɦ ɡɚɞɚɱɭ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɛɪɨɧɢɪɨɜɚɧɢɹ ɚɜɢɚɛɢɥɟɬɨɜ. ɐɟɥɢ ɞɚɧɧɨɝɨ ɩɨɫɨɛɢɹ ɧɟ ɬɪɟɛɭɸɬ ɭɱɟɬɚ ɜɫɟɯ ɨɫɨɛɟɧɧɨɫɬɟɣ ɩɪɟɞɦɟɬɧɨɣ ɨɛɥɚɫɬɢ. ɉɨɷɬɨɦɭ ɭɩɪɨɫɬɢɦ ɡɚɞɚɱɭ ɞɨ ɦɢɧɢɦɚɥɶɧɨ ɜɨɡɦɨɠɧɵɯ ɩɪɟɞɟɥɨɜ, ɩɪɟɞɭɩɪɟɞɢɜ ɱɢɬɚɬɟɥɹ, ɱɬɨ ɩɪɟɞɫɬɚɜɥɟɧɧɚɹ ɦɨɞɟɥɶ ɢɦɟɟɬ ɜɟɫɶɦɚ ɨɬɞɚɥɟɧɧɨɟ ɨɬɧɨɲɟɧɢɟ ɤ ɪɟɚɥɶɧɨɣ ɫɢɬɭɚɰɢɢ. ɉɪɟɞɩɨɥɨɠɢɦ, ɱɬɨ ɛɚɡɚ ɞɚɧɧɵɯ ɫɨɫɬɨɢɬ ɢɡ ɱɟɬɵɪɟɯ ɬɚɛɥɢɰ (ɉɚɫɫɚɠɢɪɵ / Passengers, Ɋɟɣɫɵ / Voyages, ɉɭɧɤɬɵ ɧɚɡɧɚɱɟɧɢɹ / Destinations, ɂɧɮɨɪɦɚɰɢɹ ɨ ɡɚɛɪɨɧɢɪɨɜɚɧɧɵɯ ɛɢɥɟɬɚɯ / Bookings), ɫɜɹɡɚɧɧɵɯ ɩɨ ɤɥɸɱɚɦ passenger_id, destination_id, voyage_id ɢ booking_id. ȼ ɬɚɛɥɢɰɟ Destinations ɯɪɚɧɹɬɫɹ ɧɚɡɜɚɧɢɹ ɩɭɧɤɬɨɜ ɧɚɡɧɚɱɟɧɢɹ; ɜ ɬɚɛɥɢɰɟ Passengers – ɫɜɟɞɟɧɢɹ ɨ ɩɚɫɫɚɠɢɪɚɯ; ɜ ɬɚɛɥɢɰɟ Voyages – ɫɜɟɞɟɧɢɹ ɨɛ ɚɜɢɚɪɟɣɫɚɯ; Bookings ɯɪɚɧɢɬ ɢɧɮɨɪɦɚɰɢɸ ɨ ɡɚɛɪɨɧɢɪɨɜɚɧɧɵɯ ɛɢɥɟɬɚɯ. Ʉɚɠɞɚɹ ɡɚɩɢɫɶ ɨɛ ɚɜɢɚɪɟɣɫɟ ɢ ɤɚɠɞɚɹ ɡɚɩɢɫɶ ɨ ɡɚɛɪɨɧɢɪɨɜɚɧɧɨɦ ɛɢɥɟɬɟ ɯɪɚɧɢɬɫɹ ɜ ɜɢɞɟ ɫɨɜɨɤɭɩɧɨɫɬɢ ɩɨɥɟɣ, ɫɨɞɟɪɠɚɳɢɯ ɜɧɟɲɧɢɟ ɤɥɸɱɢ – FK, Foreign Keys (ɪɢɫ. 4.1). ɉɟɪɟɞ ɛɪɨɧɢɪɨɜɚɧɢɟɦ ɛɢɥɟɬɚ ɧɟɨɛɯɨɞɢɦɨ ɜɧɟɫɬɢ ɜ ɛɚɡɭ ɞɚɧɧɵɯ ɫɜɟɞɟɧɢɹ ɨ ɩɚɫɫɚɠɢɪɟ (ɡɚɩɢɫɶ ɜ ɬɚɛɥɢɰɟ Passengers) ɢ ɭɛɟɞɢɬɶɫɹ, ɱɬɨ ɬɪɟɛɭɟɦɵɣ ɪɟɣɫ ɭɠɟ ɫɭɳɟɫɬɜɭɟɬ (ɡɚɩɢɫɶ ɜ ɬɚɛɥɢɰɟ Voyages). Ʉɚɠɞɵɣ ɩɚɫɫɚɠɢɪ ɦɨɠɟɬ ɡɚɛɪɨɧɢɪɨɜɚɬɶ ɛɢɥɟɬɵ ɧɚ ɧɟɫɤɨɥɶɤɨ ɪɟɣɫɨɜ, ɢ ɜ ɬɨ ɠɟ ɜɪɟɦɹ ɤɚɠɞɵɣ ɪɟɣɫ ɦɨɠɟɬ ɛɵɬɶ ɡɚɛɪɨɧɢɪɨɜɚɧ ɧɟɫɤɨɥɶɤɢɦɢ ɩɚɫɫɚɠɢɪɚɦɢ. Ⱥɧɨɧɢɦɧɵɟ ɛɪɨɧɢɪɨɜɤɢ ɧɟ ɞɨɩɭɫɤɚɸɬɫɹ. Ȼɢɥɟɬɵ ɛɪɨɧɢɪɭɸɬɫɹ ɩɚɫɫɚɠɢɪɚɦɢ ɲɬɭɱɧɨ, ɩɪɢɱɟɦ ɧɟɥɶɡɹ ɡɚɛɪɨɧɢɪɨɜɚɬɶ ɛɢɥɟɬ ɧɚ ɪɟɣɫ, ɧɚ ɤɨɬɨɪɨɦ ɧɟɬ ɫɜɨɛɨɞɧɵɯ ɦɟɫɬ. ɉɪɢ ɪɚɛɨɬɟ ɫ ɞɚɧɧɵɦɢ ɜɫɟ ɩɨɥɹ ɨɛɹɡɚɬɟɥɶɧɵ ɞɥɹ ɡɚɩɨɥɧɟɧɢɹ (ɧɟɥɶɡɹ ɫɨɡɞɚɬɶ ɡɚɩɢɫɶ ɨ ɩɚɫɫɚɠɢɪɟ, ɞɥɹ ɤɨɬɨɪɨɝɨ, ɧɚɩɪɢɦɟɪ, ɧɟ ɭɤɚɡɚɧ ɧɨɦɟɪ ɩɚɫɩɨɪɬɚ ɢɥɢ ɎɂɈ). Ɍɚɤɠɟ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɜɨɡɦɨɠɧɨɫɬɶ ɨɬɦɟɧɢɬɶ ɡɚɛɪɨɧɢɪɨɜɚɧɧɵɣ ɛɢɥɟɬ. Ʉɥɢɟɧɬɫɤɨɟ ɩɪɢɥɨɠɟɧɢɟ ɞɨɥɠɧɨ ɜɵɩɨɥɧɹɬɶ ɤɚɤ ɦɢɧɢɦɭɦ ɫɥɟɞɭɸɳɢɟ ɬɪɢ ɮɭɧɤɰɢɢ. 1. ɉɨɞɤɥɸɱɟɧɢɟ ɤ ɛɚɡɟ ɞɚɧɧɵɯ. 2. ɉɪɨɫɦɨɬɪ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɟ ɬɚɛɥɢɰ Passengers, Destinations, Voyages. 3. ɋɨɡɞɚɧɢɟ ɢ ɭɞɚɥɟɧɢɟ ɡɚɩɢɫɟɣ ɨ ɡɚɛɪɨɧɢɪɨɜɚɧɧɵɯ ɚɜɢɚɛɢɥɟɬɚɯ (ɜɵɡɨɜ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ).
58
Ʌɨɝɢɱɟɫɤɚɹ ɫɬɪɭɤɬɭɪɚ ɛɚɡɵ ɞɚɧɧɵɯ ɜ ɧɨɬɚɰɢɢ ɫɢɫɬɟɦɵ CASEɩɪɨɟɤɬɢɪɨɜɚɧɢɹ ERwin ɩɪɢɜɟɞɟɧɚ ɧɚ ɪɢɫ. 4.1. (ɡɚɦɟɬɢɦ, ɱɬɨ ɜ ɫɨɫɬɚɜɟ IBExpert ɢɦɟɟɬɫɹ ɩɨɞɨɛɧɵɣ ɢɧɫɬɪɭɦɟɧɬ Database Designer).
Ɋɢɫ. 4.1. 4.2. ɋɬɪɭɤɬɭɪɚ ɛɚɡɵ ɞɚɧɧɵɯ. ɋɟɪɜɟɪɧɚɹ ɱɚɫɬɶ ɩɪɢɥɨɠɟɧɢɹ ɋɬɪɭɤɬɭɪɚ ɛɚɡɵ ɞɚɧɧɵɯ ɞɥɹ ɩɪɟɞɦɟɬɧɨɣ ɨɛɥɚɫɬɢ ɢ ɫɟɪɜɟɪɧɚɹ ɱɚɫɬɶ ɩɪɢɥɨɠɟɧɢɹ ɨɩɢɫɵɜɚɸɬɫɹ ɫ ɩɨɦɨɳɶɸ ɫɥɟɞɭɸɳɟɝɨ SQL-ɫɤɪɢɩɬɚ: SET TERM ^; /* Ɍɚɛɥɢɰɵ */ CREATE TABLE DESTINATIONS ( /* id ɩɭɧɤɬɚ ɧɚɡɧɚɱɟɧɢɹ, ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ */ DESTINATION_ID INTEGER NOT NULL /* ɧɚɡɜɚɧɢɟ ɩɭɧɤɬɚ ɧɚɡɧɚɱɟɧɢɹ */ TITLE VARCHAR(40) NOT NULL, ) ^ CREATE TABLE PASSENGERS ( /* id ɩɚɫɫɚɠɢɪɚ, ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ */ PASSENGER_ID INTEGER NOT NULL, /* ɎɂɈ ɩɚɫɫɚɠɢɪɚ */ NAME VARCHAR(40) NOT NULL, /* ɧɨɦɟɪ ɩɚɫɩɨɪɬɚ ɩɚɫɫɚɠɢɪɚ */ PASSPORT_NO VARCHAR(10) NOT NULL, /* ɚɞɪɟɫ ɩɚɫɫɚɠɢɪɚ */ ADDRESS VARCHAR(80), /* ɝɪɚɠɞɚɧɫɬɜɨ ɩɚɫɫɚɠɢɪɚ */ CITIZENSHIP VARCHAR(20) NOT NULL ) ^
59
CREATE TABLE VOYAGES ( /* id ɚɜɢɚɪɟɣɫɚ, ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ */ VOYAGE_ID INTEGER NOT NULL, /* ɜɧɭɬɪɟɧɧɢɣ ɤɨɞ ɪɟɣɫɚ ɚɜɢɚɤɨɦɩɚɧɢɢ */ ALIAS VARCHAR(9) NOT NULL, /* ɚɜɢɚɤɨɦɩɚɧɢɹ */ AIRCARRIER VARCHAR(30) NOT NULL, /* ɦɨɞɟɥɶ ɫɚɦɨɥɟɬɚ */ AIRCRAFT VARCHAR(20) NOT NULL, /* ɜɦɟɫɬɢɦɨɫɬɶ */ CAPACITY INTEGER NOT NULL CHECK (CAPACITY > 0), /* ɜɪɟɦɹ ɨɬɩɪɚɜɥɟɧɢɹ */ DEPARTURE_TIME TIME NOT NULL, /* ɜɪɟɦɹ ɩɪɢɛɵɬɢɹ */ ARRIVAL_TIME TIME NOT NULL, /* ɩɭɧɤɬ ɨɬɩɪɚɜɥɟɧɢɹ */ DEPARTURE_ID INTEGER NOT NULL, /* ɩɭɧɤɬ ɩɪɢɛɵɬɢɹ */ ARRIVAL_ID INTEGER NOT NULL, /* ɞɚɬɚ ɪɟɣɫɚ */ VOYAGEDATE DATE NOT NULL ) ^ CREATE TABLE BOOKINGS ( /* id ɛɪɨɧɢɪɨɜɤɢ, ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ */ BOOKING_ID INTEGER NOT NULL, /* id ɩɚɫɫɚɠɢɪɚ, ɛɪɨɧɢɪɭɸɳɟɝɨ ɛɢɥɟɬ */ PASSENGER_ID INTEGER NOT NULL, /* id ɚɜɢɚɪɟɣɫɚ, ɧɚ ɤɨɬɨɪɵɣ ɛɪɨɧɢɪɭɟɬɫɹ ɛɢɥɟɬ */ VOYAGE_ID INTEGER NOT NULL, /* ɫɬɨɢɦɨɫɬɶ ɚɜɢɚɛɢɥɟɬɚ */ PRICE NUMERIC(9,0) NOT NULL CHECK (PRICE > 0), /* ɤɥɚɫɫ ɩɭɬɟɲɟɫɬɜɢɹ */ CLASS VARCHAR(20) NOT NULL ) ^ /* ɉɟɪɜɢɱɧɵɟ ɤɥɸɱɢ */ ALTER TABLE BOOKINGS ADD PRIMARY KEY (booking_id); ALTER TABLE DESTINATIONS ADD PRIMARY KEY (destination_id); ALTER TABLE PASSENGERS ADD PRIMARY KEY (passenger_id); ALTER TABLE VOYAGES ADD PRIMARY KEY (voyage_id); /* ȼɧɟɲɧɢɟ ɤɥɸɱɢ */ ALTER TABLE BOOKINGS ADD FOREIGN KEY (voyage_id) REFERENCES VOYAGES; ALTER TABLE BOOKINGS
60
ADD FOREIGN KEY (passenger_id) REFERENCES PASSENGERS; ALTER TABLE VOYAGES ADD FOREIGN KEY (arrival_id) REFERENCES DESTINATIONS; ALTER TABLE VOYAGES ADD FOREIGN KEY (departure_id) REFERENCES DESTINATIONS; /* Ƚɟɧɟɪɚɬɨɪɵ */ CREATE GENERATOR GEN_BOOKINGS ^ SET GENERATOR GEN_BOOKINGS TO 0 ^ CREATE GENERATOR GEN_DESTINATIONS ^ SET GENERATOR GEN_DESTINATIONS TO 0 ^ CREATE GENERATOR GEN_PASSENGERS ^ SET GENERATOR GEN_PASSENGERS TO 0 ^ CREATE GENERATOR GEN_VOYAGES ^ SET GENERATOR GEN_VOYAGES TO 0 ^ /* ɏɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ */ /* ɍɞɚɥɹɟɬ ɛɪɨɧɶ ɫ ɡɚɞɚɧɧɵɦ ɧɨɦɟɪɨɦ */ CREATE PROCEDURE DELETE_BOOKING ( P_BOOKING INTEGER) AS DECLARE VARIABLE P_VOYAGE INTEGER; begin select voyage_id from bookings where booking_id=:p_booking into :p_voyage; delete from bookings where booking_id=:p_booking; update voyages set voyages.capacity=voyages.capacity+1 where voyages.voyage_id=:p_voyage; end ^ /* ɉɨɥɭɱɚɟɬ ɧɨɦɟɪ ɛɪɨɧɢ ɩɨ ɢɧɮɨɪɦɚɰɢɢ ɨ ɧɟɣ */ CREATE PROCEDURE GET_BOOKING_ID ( P_VOYAGE INTEGER, P_PASSENGER INTEGER) RETURNS ( P_BOOKING INTEGER) AS begin select booking_id from bookings where passenger_id=:p_passenger and voyage_id=:p_voyage into :p_booking; suspend; end ^ /* ɉɨɥɭɱɚɟɬ ɢɧɮɨɪɦɚɰɢɸ ɨ ɛɪɨɧɟ ɩɨ ɟɟ ɧɨɦɟɪɭ */ CREATE PROCEDURE GET_BOOKING_INFO (
61
P_BOOKING INTEGER) RETURNS ( P_VOYAGE INTEGER, P_PASSENGER INTEGER) AS begin select voyage_id, passenger_id from bookings where booking_id=:p_booking into :p_voyage, :p_passenger; suspend; end ^ /* Ȼɪɨɧɢɪɨɜɚɧɢɟ ɛɢɥɟɬɚ */ CREATE PROCEDURE NEW_BOOKING ( P_PASSENGER INTEGER, P_VOYAGE INTEGER, P_PRICE FLOAT, P_CLASS VARCHAR(20)) AS DECLARE VARIABLE AVAILABLE_CAPACITY INTEGER; begin select capacity from voyages where (voyages.voyage_id=:p_voyage) into :available_capacity; insert into bookings (passenger_id, voyage_id, price, class) values (:p_passenger, :p_voyage, :p_price, :p_class); end ^ /* Ɍɪɢɝɝɟɪɵ */ /* ɍɦɟɧɶɲɟɧɢɟ ɤɨɥ-ɜɚ ɞɨɫɬɭɩɧɵɯ ɩɨɫɚɞɨɱɧɵɯ ɦɟɫɬ ɧɚ ɪɟɣɫ ɩɪɢ ɛɪɨɧɢɪɨɜɚɧɢɢ */ CREATE TRIGGER TRIG_NEW_BOOKING FOR BOOKINGS ACTIVE BEFORE INSERT POSITION 0 AS declare actual_capacity integer; begin SELECT capacity FROM voyages WHERE (voyages.voyage_id = new.voyage_id) INTO :actual_capacity; if (actual_capacity > 0) then UPDATE voyages SET capacity = capacity – 1 WHERE voyage_id = new.voyage_id; else exception sold_out; end ^ /* Ɂɚɩɨɥɧɹɟɬ ɤɥɸɱɟɜɨɟ ɩɨɥɟ ɬɚɛɥɢɰɵ BOOKINGS */ CREATE TRIGGER TRIG_BOOKINGS FOR BOOKINGS
62
ACTIVE BEFORE INSERT POSITION 1 AS begin new.booking_id = GEN_ID(gen_bookings, 1); end ^ /* ɂɫɤɥɸɱɟɧɢɹ */ /* ɂɫɤɥɸɱɟɧɢɟ, ɜɵɡɵɜɚɟɦɨɟ ɩɪɢ ɩɨɩɵɬɤɟ ɡɚɛɪɨɧɢɪɨɜɚɬɶ ɛɢɥɟɬ ɧɚ ɚɜɢɚɪɟɣɫ, ɧɚ ɤɨɬɨɪɵɣ ɩɪɨɞɚɧɵ ɜɫɟ ɛɢɥɟɬɵ */ CREATE EXCEPTION SOLD_OUT 'ȼɫɟ ɛɢɥɟɬɵ ɧɚ ɪɟɣɫ ɩɪɨɞɚɧɵ!'; /* ɉɪɢɫɜɨɟɧɢɟ ɩɪɢɜɢɥɟɝɢɣ ɪɨɥɹɦ */ GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON BOOKINGS TO MANAGER; GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON DESTINATIONS TO MANAGER; GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON PASSENGERS TO MANAGER; GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON VOYAGES TO MANAGER; GRANT EXECUTE ON PROCEDURE DELETE_BOOKING TO MANAGER; GRANT EXECUTE ON PROCEDURE GET_BOOKING_ID TO MANAGER; GRANT EXECUTE ON PROCEDURE GET_BOOKING_INFO TO MANAGER; GRANT EXECUTE ON PROCEDURE NEW_BOOKING TO MANAGER; GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON DESTINATIONS TO OPERATOR; GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON PASSENGERS TO OPERATOR; GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON VOYAGES TO OPERATOR;
COMMIT ^ SET TERM ; ^
Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɩɟɪɟɱɢɫɥɟɧɧɵɯ ɨɛɴɟɤɬɨɜ ɜɵɩɨɥɧɢɬɟ ɫɤɪɢɩɬ ɜ ɨɤɧɟ Script Executive (ɜɵɡɵɜɚɟɬɫɹ ɫɨɱɟɬɚɧɢɟɦ ɤɥɚɜɢɲ Ctrl + F12) ɢɥɢ ɜɨɫɩɨɥɶɡɭɣɬɟɫɶ ɞɢɚɥɨɝɨɜɵɦɢ ɫɪɟɞɫɬɜɚɦɢ IBExpert. ȼ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɢ ɩɪɢɥɨɠɟɧɢɹ ɫ ɩɨɦɨɳɶɸ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ ɪɟɚɥɢɡɨɜɚɧɵ ɦɟɯɚɧɢɡɦɵ ɛɪɨɧɢɪɨɜɚɧɢɹ ɛɢɥɟɬɚ, ɨɬɦɟɧɵ ɛɪɨɧɢ; ɫ ɩɨɦɨɳɶɸ ɬɪɢɝɝɟɪɨɜ ɪɟɚɥɢɡɨɜɚɧɵ ɛɢɡɧɟɫ-ɩɪɚɜɢɥɚ (ɭɦɟɧɶɲɟɧɢɟ ɤɨɥɢɱɟɫɬɜɚ ɞɨɫɬɭɩɧɵɯ ɦɟɫɬ ɧɚ ɪɟɣɫ ɩɪɢ ɛɪɨɧɢɪɨɜɚɧɢɢ ɛɢɥɟɬɚ) ɢ ɡɚɩɨɥɧɟɧɢɟ ɩɟɪɜɢɱɧɨɝɨ ɤɥɸɱɚ ɬɚɛɥɢɰɵ Bookings. Ɍ. ɟ. ɜ ɫɟɪɜɟɪɧɨɣ ɱɚɫɬɢ ɪɟɚɥɢɡɨɜɚɧɵ ɬɟ ɮɭɧɤɰɢɢ ɩɪɢɥɨɠɟɧɢɹ, ɤɨɬɨɪɵɟ ɞɨɥɠɧɵ ɜɵɩɨɥɧɹɬɶɫɹ ɦɚɤɫɢɦɚɥɶɧɨ ɛɵɫɬɪɨ ɢ ɫ ɧɚɢɦɟɧɶɲɢɦɢ ɡɚɬɪɚɬɚɦɢ ɪɟɫɭɪɫɨɜ. ȼ ɛɚɡɟ ɞɚɧɧɵɯ ɩɪɟɞɭɫɦɨɬɪɟɧɵ ɪɨɥɢ Operator ɢ Manager (ɪɢɫ. 4.2).
63
Ɋɢɫ. 4.2. ɉɟɪɜɚɹ ɪɨɥɶ, Operator – ɢɦɟɟɬ ɩɨɥɧɵɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɬɨɥɶɤɨ ɧɚ ɬɚɛɥɢɰɵ Passengers, Voyages, Destinations, ɜɬɨɪɚɹ – Manager – ɩɨɥɧɵɟ ɩɪɚɜɚ ɞɨɫɬɭɩɚ ɧɚ ɜɫɟ ɨɛɴɟɤɬɵ ɛɚɡɵ ɞɚɧɧɵɯ (ɪɢɫ. 4.3). ɉɪɟɞɩɨɥɚɝɚɟɬɫɹ, ɱɬɨ ɮɭɧɤɰɢɹ ɨɩɟɪɚɬɨɪɚ – «ɱɟɪɧɨɜɚɹ ɪɚɛɨɬɚ», ɬ. ɟ. ɪɚɛɨɬɚ ɫɨ ɜɫɩɨɦɨɝɚɬɟɥɶɧɵɦɢ ɞɚɧɧɵɦɢ, ɚ ɨɛɹɡɚɧɧɨɫɬɢ ɦɟɧɟɞɠɟɪɚ – ɛɪɨɧɢɪɨɜɚɧɢɟ ɚɜɢɚɛɢɥɟɬɨɜ.
Ɋɢɫ. 4.3. 4.3. Ʉɥɢɟɧɬɫɤɚɹ ɱɚɫɬɶ ȼ ɤɥɢɟɧɬɫɤɨɦ ɩɪɢɥɨɠɟɧɢɢ ɪɟɚɥɢɡɨɜɚɧɨ ɜɡɚɢɦɨɞɟɣɫɬɜɢɟ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ, ɭɩɪɚɜɥɟɧɢɟ «ɜɫɩɨɦɨɝɚɬɟɥɶɧɵɦɢ» ɞɚɧɧɵɦɢ (ɩɭɧɤɬɵ ɧɚɡɧɚɱɟɧɢɹ, ɩɚɫɫɚɠɢɪɵ, ɚɜɢɚɪɟɣɫɵ), ɜɵɡɨɜ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ ɞɥɹ ɫɨɡɞɚɧɢɹ/ɭɞɚɥɟɧɢɹ ɛɪɨɧɢ, ɩɨɥɭɱɟɧɢɟ ɢɧɮɨɪɦɚɰɢɢ ɨ ɡɚɛɪɨɧɢɪɨɜɚɧɧɵɯ ɚɜɢɚɛɢɥɟɬɚɯ. 64
4.3.1. ɇɚɫɬɪɨɣɤɚ ɦɨɞɭɥɹ ɞɚɧɧɵɯ ɋɨɡɞɚɞɢɦ ɦɨɞɭɥɶ ɞɚɧɧɵɯ (ɩɭɧɤɬ ɦɟɧɸ File – New – Data Module), ɩɪɢɫɜɨɢɦ ɫɜɨɣɫɬɜɭ Name ɡɧɚɱɟɧɢɟ DM ɢ ɫɨɯɪɚɧɢɦ ɟɝɨ. Ɋɚɫɩɨɥɨɠɢɦ ɜ ɦɨɞɭɥɟ ɞɚɧɧɵɯ ɤɨɦɩɨɧɟɧɬɵ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ (ɪɢɫ. 4.4). ɉɪɢ ɜɵɛɨɪɟ ɢɦɟɧ ɤɨɦɩɨɧɟɧɬɨɜ ɡɞɟɫɶ ɢ ɞɚɥɟɟ ɛɭɞɟɦ ɩɨɥɶɡɨɜɚɬɶɫɹ ɜɟɧɝɟɪɫɤɨɣ ɧɨɬɚɰɢɟɣ. ɉɪɟɮɢɤɫ “ds” ɢɫɩɨɥɶɡɭɟɦ ɞɥɹ ɤɨɦɩɨɧɟɧɬɨɜ ɬɢɩɚ TDataSource, “ibds” – TIBDataSet, “ibqr” – TIBQuery ɢ ɬ. ɞ.
Ɋɢɫ. 4.4. 1. ɋɨɡɞɚɣɬɟ ɞɜɚ ɤɨɦɩɨɧɟɧɬɚ trMain ɢ trBooking: TIBTransaction. ɉɟɪɜɵɣ ɤɨɦɩɨɧɟɧɬ ɭɩɪɚɜɥɟɧɢɹ ɬɪɚɧɡɚɤɰɢɹɦɢ (trMain) ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɥɹ ɭɩɪɚɜɥɟɧɢɹ ɬɚɛɥɢɰɚɦɢ Passengers, Destinations, Voyages. ɉɚɪɚɦɟɬɪɵ ɬɪɚɧɡɚɤɰɢɢ «ɠɟɫɬɤɢɟ», ɬɚɤ ɤɚɤ ɧɟ ɬɪɟɛɭɟɬɫɹ ɨɩɟɪɚɬɢɜɧɨɫɬɢ ɩɪɢ ɪɚɛɨɬɟ ɫ ɷɬɢɦɢ ɬɚɛɥɢɰɚɦɢ.
Ɋɢɫ. 4.5. ȼɬɨɪɨɣ ɤɨɦɩɨɧɟɧɬ (trBooking) ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɥɹ ɭɩɪɚɜɥɟɧɢɹ ɛɪɨɧɢɪɨɜɚɧɢɟɦ ɚɜɢɚɛɢɥɟɬɨɜ ɜ ɭɫɥɨɜɢɹɯ ɤɨɧɤɭɪɢɪɭɸɳɢɯ ɬɪɚɧɡɚɤɰɢɣ, ɩɚɪɚɦɟɬɪɵ ɬɪɚɧɡɚɤɰɢɢ ɛɨɥɟɟ «ɦɹɝɤɢɟ».
65
Ɋɢɫ. 4.6. Ɉɫɬɚɥɶɧɵɟ ɫɜɨɣɫɬɜɚ ɤɨɦɩɨɧɟɧɬɨɜ ɨɫɬɚɜɢɦ ɛɟɡ ɢɡɦɟɧɟɧɢɣ. 2. ɇɚɫɬɪɨɣɬɟ ɤɨɦɩɨɧɟɧɬ ɫɨɟɞɢɧɟɧɢɹ Bookings: TIBDatabase. ɉɪɢ ɧɚɱɚɥɶɧɨɣ ɨɬɥɚɞɤɟ ɜɨɫɩɨɥɶɡɭɣɬɟɫɶ ɞɥɹ ɧɚɫɬɪɨɣɤɢ Bookings ɪɟɞɚɤɬɨɪɨɦ Database Editor (ɩ. 2.1), ɜ ɤɨɬɨɪɨɦ ɭɤɚɠɢɬɟ ɩɚɪɚɦɟɬɪɵ ɫɨɟɞɢɧɟɧɢɹ, ɜɤɥɸɱɚɹ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ (User Name) ɢ ɩɚɪɨɥɶ (Password). ɋɜɨɣɫɬɜɨ
Ɂɧɚɱɟɧɢɟ
DatabaseName
D:\IB\4gr\Example\Bookings.gdb
LoginPrompt DefaultTransaction
False trMain
ɉɨɫɥɟ ɬɨɝɨ, ɤɚɤ ɩɪɨɝɪɚɦɦɚ ɛɭɞɟɬ ɩɨɥɧɨɫɬɶɸ ɨɬɥɚɠɟɧɚ, ɜɵɡɨɜɢɬɟ Database Editor ɢ ɨɱɢɫɬɢɬɟ ɜ ɧɟɦ ɜɫɟ ɩɨɥɹ (DatabaseName, Params). Ɉɧɢ ɛɭɞɭɬ ɡɚɩɨɥɧɹɬɶɫɹ ɫ ɩɨɦɨɳɶɸ ɮɨɪɦɵ ɫɨɟɞɢɧɟɧɢɹ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ ɩɪɢ ɡɚɩɭɫɤɟ ɩɪɢɥɨɠɟɧɢɹ. 3. ɇɚɫɬɪɨɣɬɟ ɤɨɦɩɨɧɟɧɬɵ ibdsPassengers, ibdsDestinations, ibdsVoyages, ɫɜɹɡɚɜ ɢɯ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ. ɋɜɨɣɫɬɜɨ Transaction ɡɚɩɨɥɧɢɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɢ ɩɨɥɭɱɢɬ ɡɧɚɱɟɧɢɟ trMain: Database Transaction
Bookings trMain
4. Ⱦɥɹ ɨɛɴɟɤɬɨɜ ibdsPassengers, ibdsDestinations, ibdsVoyages: TIBDataSet ɭɤɚɠɢɬɟ ɜ ɫɜɨɣɫɬɜɚɯ SelectSQL ɡɚɩɪɨɫɵ ɜɢɞɚ SELECT * FROM <ɢɦɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɣ ɬɚɛɥɢɰɵ>
66
5. ɂɫɩɨɥɶɡɭɹ Dataset Editor (ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ ɤɨɦɩɨɧɟɧɬɨɜ TIBDataSet), ɨɩɪɟɞɟɥɢɬɟ ɞɟɣɫɬɜɢɹ ɩɨ ɪɟɞɚɤɬɢɪɨɜɚɧɢɸ ɧɚɛɨɪɨɜ ɞɚɧɧɵɯ. Ⱦɥɹ ɩɪɢɦɟɪɚ ɪɚɫɫɦɨɬɪɢɦ ɤɨɦɩɨɧɟɧɬ ibdsPassengers (ɪɢɫ. 4.7).
Ɋɢɫ. 4.7. Ʉɧɨɩɤɚ Get Table Fields ɡɚɩɨɥɧɹɟɬ ɩɨɥɹɦɢ ɬɚɛɥɢɰɵ ɨɛɥɚɫɬɢ ɧɚ ɷɤɪɚɧɟ Key Fields ɢ Update Fields. ȼɨ ɜɬɨɪɨɣ ɨɛɥɚɫɬɢ ɭɤɚɡɵɜɚɸɬɫɹ ɪɟɞɚɤɬɢɪɭɟɦɵɟ ɩɨɥɹ. Ʉɚɤ ɩɪɚɜɢɥɨ, ɦɨɠɧɨ ɨɫɬɚɜɢɬɶ ɜɫɟ ɩɨɥɹ. ȼ ɨɛɥɚɫɬɢ ɫɥɟɜɚ ɧɟɨɛɯɨɞɢɦɨ ɜɵɛɪɚɬɶ ɤɥɸɱɟɜɵɟ ɩɨɥɹ, ɩɨ ɤɨɬɨɪɵɦ ɛɭɞɟɬ ɩɪɨɢɫɯɨɞɢɬɶ ɩɨɢɫɤ ɜ ɬɚɛɥɢɰɟ. ɇɚɠɚɜ ɤɧɨɩɤɭ Select Primary Keys, ɜɵɛɟɪɟɦ ɞɥɹ ɩɨɢɫɤɚ ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ. ɉɪɢ ɜɵɛɨɪɟ Datasets Defaults ɩɨɢɫɤ ɛɭɞɟɬ ɩɪɨɜɨɞɢɬɶɫɹ ɩɨ ɜɫɟɦ ɩɨɥɹɦ. ɇɚɠɚɜ ɤɧɨɩɤɭ Generate SQL, ɩɨɥɭɱɢɦ ɧɚɛɨɪ SQL-ɨɩɟɪɚɬɨɪɨɜ ɞɥɹ ɭɩɪɚɜɥɟɧɢɹ ɧɚɛɨɪɨɦ ɞɚɧɧɵɯ; ɧɚɛɨɪ SQL-ɨɩɟɪɚɬɨɪɨɜ ɦɨɠɧɨ ɩɪɨɫɦɨɬɪɟɬɶ ɢ ɩɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɨɬɪɟɞɚɤɬɢɪɨɜɚɬɶ ɧɚ ɜɤɥɚɞɤɟ SQL (ɜ Dataset Editor). ɋɚɦɢ ɨɩɟɪɚɬɨɪɵ ɯɪɚɧɹɬɫɹ ɜ ɫɜɨɣɫɬɜɚɯ SelectSQL, DeleteSQL, InsertSQL, ModifySQL ɤɨɦɩɨɧɟɧɬɚ ibdsPassengers ɢ ɢɦɟɸɬ ɫɨɨɬɜɟɬɫɬɜɟɧɧɨ ɜɢɞ: SELECT * FROM PASSENGERS ORDER BY NAME, PASSPORT_NO DELETE FROM PASSENGERS WHERE PASSENGER_ID = :OLD_PASSENGER_ID INSERT INTO PASSENGERS (NAME, PASSENGER_ID, PASSPORT_NO, ADDRESS, CITIZENSHIP) VALUES (:NAME, :PASSENGER_ID, :PASSPORT_NO, :ADDRESS, :CITIZENSHIP) UPDATE PASSENGERS SET NAME = :NAME, PASSENGER_ID = :PASSENGER_ID,
67
PASSPORT_NO = :PASSPORT_NO, ADDRESS = :ADDRESS, CITIZENSHIP = :CITIZENSHIP WHERE PASSENGER_ID = :OLD_PASSENGER_ID
ɉɚɪɚɦɟɬɪɚɦɢ ɡɚɩɪɨɫɨɜ (ɧɚɩɪɢɦɟɪ, :PASSENGER_ID) ɹɜɥɹɸɬɫɹ ɩɨɥɹ ɧɚɛɨɪɚ ɞɚɧɧɵɯ, ɡɧɚɱɟɧɢɹ ɤɨɬɨɪɵɯ ɩɨɞɫɬɚɜɥɹɸɬɫɹ ɜ ɩɨɥɹ ɬɚɛɥɢɰɵ ɧɚ ɫɟɪɜɟɪɟ. ɉɪɢɫɬɚɜɤɚ OLD (:OLD_PASSENGER_ID) ɨɡɧɚɱɚɟɬ ɨɛɪɚɳɟɧɢɟ ɤ ɫɬɚɪɨɦɭ ɡɧɚɱɟɧɢɸ ɩɨɥɹ ɢɡ ɧɚɛɨɪɚ ɞɚɧɧɵɯ (ɞɨ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ), ɫ ɤɨɬɨɪɵɦ ɫɪɚɜɧɢɜɚɟɬɫɹ ɩɨɥɟ ɢɡ ɬɚɛɥɢɰɵ ɧɚ ɫɟɪɜɟɪɟ. Ɂɚɩɨɥɧɢɬɟ ɫɜɨɣɫɬɜɨ GeneratorField ɤɨɦɩɨɧɟɧɬɚ ibdsPassengers, ɭɤɚɡɚɜ ɢɦɹ ɝɟɧɟɪɚɬɨɪɚ GEN_PASSENGERS, ɢɦɹ ɤɥɸɱɟɜɨɝɨ ɩɨɥɹ PASSENGER_ID ɢ ɫɨɛɵɬɢɟ On New Record (ɪɢɫ. 4.8).
Ɋɢɫ. 4.8. Ⱥɧɚɥɨɝɢɱɧɵɦ ɨɛɪɚɡɨɦ ɧɚɫɬɪɨɣɬɟ ɤɨɦɩɨɧɟɧɬɵ ibdsDestinations, ibdsVoyages.
6. Ⱦɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɩɚɫɫɚɠɢɪɨɜ, ɩɭɧɤɬɨɜ ɧɚɡɧɚɱɟɧɢɹ ɢ ɚɜɢɚɪɟɣɫɨɜ ɜɤɥɸɱɢɦ ɪɟɠɢɦ ɤɷɲɢɪɨɜɚɧɢɹ ɢɡɦɟɧɟɧɢɣ, ɭɫɬɚɧɨɜɢɜ ɫɜɨɣɫɬɜɨ CachedUpdates ɤɨɦɩɨɧɟɧɬɨɜ ibdsPassengers, ibdsDestinations, ibdsVoyages ɜ True. Ʉɷɲɢɪɨɜɚɧɢɟ ɢɡɦɟɧɟɧɢɣ ɨɡɧɚɱɚɟɬ, ɱɬɨ ɡɚɩɢɫɢ ɧɚ ɫɟɪɜɟɪɟ ɦɨɝɭɬ ɢɡɦɟɧɹɬɶɫɹ «ɩɨɪɰɢɹɦɢ», ɤɨɬɨɪɵɟ ɛɭɞɭɬ ɩɟɪɟɧɨɫɢɬɶɫɹ ɢɡ ɩɪɢɥɨɠɟɧɢɹ ɧɚ ɫɟɪɜɟɪ ɨɬɞɟɥɶɧɨɣ ɤɨɦɚɧɞɨɣ. ȼ ɞɚɧɧɨɦ ɫɥɭɱɚɟ ɦɨɠɧɨ ɛɭɞɟɬ ɞɨɛɚɜɥɹɬɶ ɫɪɚɡɭ ɧɟɫɤɨɥɶɤɨ ɩɚɫɫɚɠɢɪɨɜ, ɧɨ ɜ ɛɚɡɟ ɞɚɧɧɵɯ ɨɧɢ ɩɨɹɜɹɬɫɹ ɬɨɥɶɤɨ ɩɨɫɥɟ ɜɵɡɨɜɚ ɦɟɬɨɞɚ ApplyUpdates ɤɨɦɩɨɧɟɧɬɚ ibdsPassengers. 7. Ⱦɥɹ ɤɨɦɩɨɧɟɧɬɨɜ ibdsPassengers, ibdsDestinations, ibdsVoyages ɫɨɡɞɚɣɬɟ ɬɢɩɢɡɢɪɨɜɚɧɧɵɟ ɩɨɥɹ (ɧɚɩɪɢɦɟɪ, ibdsPassengersPASSPORT_NO: TIBStringField), ɢɫɩɨɥɶɡɭɹ ɪɟɞɚɤɬɨɪ ɩɨɥɟɣ Fields Editor. Ɋɟɞɚɤɬɨɪ ɩɨɥɟɣ ɜɵɡɵɜɚɟɬɫɹ ɜ ɤɨɧɬɟɤɫɬɧɨɦ ɦɟɧɸ ɤɨɦɩɨɧɟɧɬɨɜ TIBDataSet 68
(TIBQuery, TIBTable). Ⱦɨɛɚɜɶɬɟ ɜ ɫɨɫɬɚɜ ɬɢɩɢɡɢɪɨɜɚɧɧɵɯ ɩɨɥɟɣ ɜɫɟ ɩɨɥɹ ɧɚɛɨɪɚ ɞɚɧɧɵɯ. ɂɦɟɧɚ ɬɢɩɢɡɢɪɨɜɚɧɧɵɯ ɩɨɥɟɣ ɫɬɪɨɹɬɫɹ ɩɨ ɩɪɢɧɰɢɩɭ ɂɦɹɇɚɛɨɪɚȾɚɧɧɵɯ+ɂɦɹɉɨɥɹ ɢ ɜɤɥɸɱɚɸɬɫɹ ɜ ɨɩɢɫɚɧɢɟ ɦɨɞɭɥɹ ɞɚɧɧɵɯ. Ɉɱɟɜɢɞɧɵɦ ɩɪɟɢɦɭɳɟɫɬɜɨɦ ɞɚɧɧɨɝɨ ɩɨɞɯɨɞɚ ɹɜɥɹɟɬɫɹ ɤɨɧɬɪɨɥɶ ɤɨɦɩɢɥɹɬɨɪɚ ɡɚ ɤɨɪɪɟɤɬɧɨɫɬɶɸ ɨɛɪɚɳɟɧɢɣ ɤ ɩɨɥɹɦ. Lookup ɩɨɥɹ (ɩɨɥɹ ɩɪɨɫɦɨɬɪɚ) ɫɥɭɠɚɬ ɞɥɹ ɨɬɨɛɪɚɠɟɧɢɹ ɡɧɚɱɟɧɢɣ ɢɡ ɤɚɤɨɝɨ-ɥɢɛɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ ɩɨ ɨɩɪɟɞɟɥɟɧɧɨɦɭ ɩɪɚɜɢɥɭ. ɗɬɢ ɩɨɥɹ ɞɨɫɬɭɩɧɵ ɬɨɥɶɤɨ ɞɥɹ ɱɬɟɧɢɹ. Lookup ɩɨɥɹ ɨɛɵɱɧɨ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɤɚɤ ɚɥɶɬɟɪɧɚɬɢɜɚ ɤɨɦɩɨɧɟɧɬɚɦ TDBLookupComboBox. ɉɪɢɦɟɧɢɬɟɥɶɧɨ ɤ ɧɚɲɟɣ ɡɚɞɚɱɟ lookup ɩɨɥɹ ɦɨɝɭɬ ɛɵɬɶ ɢɫɩɨɥɶɡɨɜɚɧɵ, ɧɚɩɪɢɦɟɪ, ɞɥɹ ɨɬɨɛɪɚɠɟɧɢɹ ɧɚɡɜɚɧɢɣ ɩɭɧɤɬɨɜ ɧɚɡɧɚɱɟɧɢɹ ɚɜɢɚɪɟɣɫɚ ɜɦɟɫɬɨ ɨɬɨɛɪɚɠɟɧɢɹ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɜ (DEPARTURE_ID, ARRIVAL_ID) ɩɭɧɤɬɨɜ ɧɚɡɧɚɱɟɧɢɹ ɜ ɫɟɬɤɟ ɞɚɧɧɵɯ TDBGrid. ȼ ɪɟɚɥɶɧɵɯ ɡɚɞɚɱɚɯ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɩɨɥɟɣ ɩɪɨɫɦɨɬɪɚ ɧɟɰɟɥɟɫɨɨɛɪɚɡɧɨ ɩɪɢ ɛɨɥɶɲɢɯ ɪɚɡɦɟɪɚɯ ɬɚɛɥɢɰ-ɫɩɪɚɜɨɱɧɢɤɨɜ, ɬɚɤ ɤɚɤ ɩɪɢɜɨɞɢɬ ɤ ɜɨɡɪɚɫɬɚɧɢɸ ɧɚɝɪɭɡɤɢ ɧɚ ɫɟɬɶ ɢ, ɤɚɤ ɫɥɟɞɫɬɜɢɟ, ɤ ɡɚɦɟɞɥɟɧɢɸ ɪɚɛɨɬɵ. Ⱦɥɹ ɤɨɦɩɨɧɟɧɬɚ ibdsVoyages ɫɨɡɞɚɞɢɦ ɞɜɚ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ lookup ɩɨɥɹ ɞɥɹ ɬɟɤɫɬɨɜɨɝɨ ɨɬɨɛɪɚɠɟɧɢɹ ɩɭɧɤɬɨɜ ɜɵɥɟɬɚ ɢ ɩɪɢɥɟɬɚ ɚɜɢɚɪɟɣɫɚ. Ⱦɥɹ ɷɬɨɝɨ ɫ ɩɨɦɨɳɶɸ ɪɟɞɚɤɬɨɪɚ ɩɨɥɟɣ ɞɨɛɚɜɶɬɟ ɧɨɜɨɟ ɩɨɥɟ (New Field), ɜ ɨɬɤɪɵɜɲɟɣɫɹ ɮɨɪɦɟ ɜɩɢɲɢɬɟ ɧɚɡɜɚɧɢɟ ɫɨɡɞɚɜɚɟɦɨɝɨ ɩɨɥɹ (Name) – DEPARTURE_TXT (ɩɚɪɚɦɟɬɪ Component ɛɭɞɟɬ ɡɚɩɨɥɧɟɧ ɢɦɟɧɟɦ ɫɨɡɞɚɜɚɟɦɨɝɨ ɩɨɥɹ ɩɪɢ ɡɚɩɨɥɧɟɧɢɢ Name ɚɜɬɨɦɚɬɢɱɟɫɤɢ); ɭɤɚɠɢɬɟ ɬɢɩ ɩɨɥɹ (Type) – String ɢ ɪɚɡɦɟɪ (Size) – 40 (ɭɤɚɡɵɜɚɟɬɫɹ ɜ ɬɨɦ ɫɥɭɱɚɟ, ɟɫɥɢ ɬɨɝɨ ɬɪɟɛɭɟɬ ɬɢɩ). Ⱦɚɥɟɟ ɧɟɨɛɯɨɞɢɦɨ ɭɤɚɡɚɬɶ ɬɢɩ ɩɨɥɹ Field Type – Lookup; Key Field – DEPARTURE_ID – ɜɧɟɲɧɢɣ ɤɥɸɱ ɜ ɩɨɞɱɢɧɟɧɧɨɦ ɧɚɛɨɪɟ ɞɚɧɧɵɯ (ibdsVoyages), ɞɥɹ ɤɨɬɨɪɨɝɨ ɛɭɞɟɬ ɩɨɞɫɬɚɜɥɟɧ ɟɝɨ «ɚɧɚɥɨɝ» ɢɡ ɝɥɚɜɧɨɝɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ (ibdsDestinations), Dataset – ibdsDestinations – ɝɥɚɜɧɵɣ ɧɚɛɨɪ ɞɚɧɧɵɯ, «Lookup Keys – DESTINATION_ID – ɩɟɪɜɢɱɧɵɣ ɤɥɸɱ ɝɥɚɜɧɨɝɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ (ɭɤɚɡɚɧɧɨɝɨ ɜ ɫɜɨɣɫɬɜɟ Dataset), Result Field – TITLE – ɡɧɚɱɟɧɢɟ, ɤɨɬɨɪɨɟ ɫɬɚɧɟɬ ɡɧɚɱɟɧɢɟɦ ɧɚɲɟɝɨ lookup ɩɨɥɹ DEPARTURE_TXT (ɪɢɫ. 4.9).
Ɋɢɫ. 4.9. 69
Ⱥɧɚɥɨɝɢɱɧɨ ɫɨɡɞɚɣɬɟ lookup ɩɨɥɟ ARRIVAL_TXT ɞɥɹ ɬɟɤɫɬɨɜɨɝɨ ɨɬɨɛɪɚɠɟɧɢɹ ɩɭɧɤɬɚ ɩɪɢɥɟɬɚ. 8. ɍɫɬɚɧɨɜɢɬɟ ɫɜɨɣɫɬɜɨ DataSet ɨɛɴɟɤɬɨɜ dsPassengers, dsDestinations, dsVoyages ɜ ibdsPassengers, ibdsDestinations, ibdsVoyages ɫɨɨɬɜɟɬɫɬɜɟɧɧɨ. 9. Ⱦɥɹ ɜɵɡɨɜɚ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ ɩɪɢ ɛɪɨɧɢɪɨɜɚɧɢɢ ɚɜɢɚɛɢɥɟɬɚ ɩɚɫɫɚɠɢɪɨɦ ɢɫɩɨɥɶɡɭɟɦ ɤɨɦɩɨɧɟɧɬ ibspBookings: TIBStoredProc. ɋɜɹɠɢɬɟ ɟɝɨ ɫ ɤɨɦɩɨɧɟɧɬɨɦ Bookings: TIBDatabase, ɜ ɫɜɨɣɫɬɜɟ StoredProcName ɭɤɚɠɢɬɟ ɢɦɹ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ NEW_BOOKING (ɜɵɛɢɪɚɟɬɫɹ ɢɡ ɫɩɢɫɤɚ). ɑɬɨɛɵ ɯɪɚɧɢɦɚɹ ɩɪɨɰɟɞɭɪɚ ɜɵɩɨɥɧɹɥɚɫɶ ɜ ɤɨɧɬɟɤɫɬɟ ɬɪɚɧɡɚɤɰɢɢ trBooking (ɨɬɥɢɱɚɸɳɟɣɫɹ ɩɨ ɩɚɪɚɦɟɬɪɚɦ ɨɬ ɬɪɚɧɡɚɤɰɢɢ trMain), ɜ ɫɜɨɣɫɬɜɟ Transaction ɭɫɬɚɧɨɜɢɬɟ trBooking. 10. ɋɨɡɞɚɣɬɟ ɬɢɩɢɡɢɪɨɜɚɧɧɵɟ ɥɨɝɢɱɟɫɤɢɟ ɩɨɥɹ ɢ ɩɨɦɟɧɹɣɬɟ ɢɯ ɡɚɝɨɥɨɜɤɢ (DisplayLabel), ɱɬɨɛɵ ɨɧɢ ɜ ɞɚɥɶɧɟɣɲɟɦ ɩɪɢ ɨɬɨɛɪɚɠɟɧɢɢ ɧɚ ɮɨɪɦɟ ɩɨɥɭɱɢɥɢ ɪɭɫɫɤɢɟ ɧɚɡɜɚɧɢɹ. 4.3.2. ȼɡɚɢɦɨɞɟɣɫɬɜɢɟ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ Ƚɥɚɜɧɚɹ ɮɨɪɦɚ ɩɪɢɥɨɠɟɧɢɹ
Ɋɢɫ. 4.10. Ɏɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ ɩɪɢɥɨɠɟɧɢɹ ɪɟɚɥɢɡɨɜɚɧɚ ɫ ɩɨɦɨɳɶɸ ɝɥɚɜɧɨɝɨ ɦɟɧɸ (TMainMenu). ɂɡ ɝɥɚɜɧɨɝɨ ɦɟɧɸ ɜɵɡɵɜɚɟɬɫɹ ɮɨɪɦɚ, ɪɟɚɥɢɡɭɸɳɚɹ ɮɭɧɤɰɢɢ ɭɩɪɚɜɥɟɧɢɹ ɡɚɩɢɫɹɦɢ ɨ ɩɚɫɫɚɠɢɪɚɯ, ɩɭɧɤɬɚɯ ɧɚɡɧɚɱɟɧɢɹ, ɚɜɢɚɪɟɣɫɚɯ, ɚ ɬɚɤɠɟ ɮɨɪɦɚ ɞɨɛɚɜɥɟɧɢɹ/ɭɞɚɥɟɧɢɹ ɛɪɨɧɢ. ȼɫɟ ɞɟɣɫɬɜɢɹ, ɪɟɚɥɢɡɨɜɚɧɧɵɟ ɫ ɩɨɦɨɳɶɸ ɝɥɚɜɧɨɝɨ ɦɟɧɸ, ɩɪɨɞɭɛɥɢɪɨɜɚɧɵ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɦɢ ɫɨɱɟɬɚɧɢɹɦɢ ɤɥɚɜɢɲ (Shortcuts). ɍɫɬɚɧɨɜɤɚ ɫɨɟɞɢɧɟɧɢɹ ɫ ɛɚɡɨɣ ɞɚɧɧɵɯ ɜɵɩɨɥɧɹɟɬɫɹ ɩɪɢ ɜɵɛɨɪɟ ɩɭɧɤɬɚ «Ɏɚɣɥ – ɉɨɞɤɥɸɱɟɧɢɟ ɤ ȻȾ». Ɉɬɤɪɵɜɚɟɬɫɹ ɮɨɪɦɚ ɫɨɟɞɢɧɟɧɢɹ (fmConnection), ɢɦɟɸɳɚɹ ɧɚ ɷɬɚɩɟ ɪɚɡɪɚɛɨɬɤɢ ɫɥɟɞɭɸɳɢɣ ɜɢɞ. 70
Ɋɢɫ. 4.11. Ⱦɥɹ ɜɜɨɞɚ ɩɚɪɨɥɹ ɡɞɟɫɶ ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɨɦɩɨɧɟɧɬ TEdit ɫɨ ɫɜɨɣɫɬɜɨɦ PasswordChar = ‘*’.
ɂɧɮɨɪɦɚɰɢɹ ɨ ɫɨɟɞɢɧɟɧɢɢ ɡɚɩɢɫɵɜɚɟɬɫɹ ɜ ɤɨɦɩɨɧɟɧɬɵ edDatabase: TEdit; // ɩɨɥɧɨɟ ɢɦɹ ȻȾ ɫ ɭɤɚɡɚɧɢɟɦ ɫɟɪɜɟɪɚ edLogin: TEdit; // ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ edPassword: TEdit; // ɩɚɪɨɥɶ edRole: TEdit; // ɪɨɥɶ
ȼ ɨɛɪɚɛɨɬɱɢɤ ɫɨɛɵɬɢɹ OnClick ɤɧɨɩɤɢ sbDatabase: TSpeedButton ɡɚɩɢɲɢɬɟ: if odDatabase.Execute then edDatabase.Text := odDatabase.FileName;
ɋɨɟɞɢɧɟɧɢɟ ɜɵɩɨɥɧɹɟɬɫɹ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ var File_Of_Settings: TIniFile; Ini_Name, Exe_Path: WideString; procedure TfmConnection.btOKClick(Sender: TObject); begin File_Of_Settings := TIniFile.Create(Exe_Path + Ini_Name); try // ɡɚɩɢɫɵɜɚɟɦ ɩɭɬɶ ɤ ȻȾ ɜ ɫɟɤɰɢɸ [DB], ɤɥɸɱ “Path” File_Of_Settings.WriteString('DB', 'Path', edDatabase.Text); // ɡɚɩɢɫɵɜɚɟɦ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɜ ɫɟɤɰɢɸ [DB], ɤɥɸɱ “Login” File_Of_Settings.WriteString('DB', 'Login', edLogin.Text); finally File_Of_Settings.Free; end; try with DM.Bookings do
71
begin Connected := FALSE; DatabaseName := edDatabase.Text; Params.Clear; Params.Add(Format('user_name=%s',[edLogin.Text])); Params.Add(Format('password=%s',[edPassword.Text])); Params.Add(Format('sql_role_name=%s',[edRole.Text])); Connected := TRUE; end; except on E: Exception do MessageDlg(TranslateMessage(E.Message),mtError,[mbOk],0); end; end; // Ɏɭɧɤɰɢɹ «ɩɟɪɟɜɨɞɚ» ɫɨɨɛɳɟɧɢɹ ɨ ɜɨɡɧɢɤɧɨɜɟɧɢɢ ɢɫɤɥɸɱɟɧɢɹ function TranslateMessage(AStr: String): String; var IsKnownError: Boolean; begin IsKnownError := FALSE; if ( Pos('unavailable database', AStr) > 0 ) then begin IsKnownError := TRUE; Result := 'Ɉɲɢɛɤɚ! ȼɨɡɦɨɠɧɨ, ɧɟ ɡɚɩɭɳɟɧ ɫɟɪɜɟɪ IB/FB.'; end; if ( Pos('user name and password', AStr) > 0 ) then begin IsKnownError := TRUE; Result := 'Ɉɲɢɛɤɚ! ɇɟɜɟɪɧɵɟ ɢɦɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ/ɢɥɢ ɩɚɪɨɥɶ.'; end; if ( Pos('I/O error', AStr) > 0 ) then begin IsKnownError := TRUE; Result := 'Ɉɲɢɛɤɚ! ɇɟɩɪɚɜɢɥɶɧɨ ɭɤɚɡɚɧɨ ɪɚɫɩɨɥɨɠɟɧɢɟ ȻȾ.'; end; if not IsKnownError then Result := 'ɇɟɢɡɜɟɫɬɧɚɹ ɨɲɢɛɤɚ!'; end;
ɉɪɢ ɨɬɤɪɵɬɢɢ ɮɨɪɦɵ ɞɟɥɚɟɬɫɹ ɩɨɩɵɬɤɚ ɫɱɢɬɚɬɶ ɢɦɹ ɛɚɡɵ ɞɚɧɧɵɯ ɢɡ ɨɞɧɨɢɦɟɧɧɨɝɨ ɫ ɩɪɢɥɨɠɟɧɢɟɦ INI-ɮɚɣɥɚ. procedure TfmConnection.FormShow(Sender: TObject); begin Exe_Path := ExtractFilePath(Application.ExeName); Ini_Name := ExtractFileName(Application.ExeName); Ini_Name := Copy(Ini_Name, 1, Pos(ExtractFileExt(Application.ExeName),Ini_Name))+'ini'; File_Of_Settings := TIniFile.Create(Exe_Path + Ini_Name); try
72
edDatabase.Text:=File_Of_Settings.ReadString('DB','Path',''); edLogin.Text:=File_Of_Settings.ReadString('DB','Login',''); edPassword.Clear; finally File_Of_Settings.Free; end; edPassword.SetFocus; end;
Ɏɨɪɦɚ ɭɩɪɚɜɥɟɧɢɹ ɫɜɟɞɟɧɢɹɦɢ ɨ ɩɚɫɫɚɠɢɪɚɯ, ɩɭɧɤɬɚɯ ɧɚɡɧɚɱɟɧɢɹ, ɚɜɢɚɪɟɣɫɚɯ («ɜɫɩɨɦɨɝɚɬɟɥɶɧɵɟ» ɞɚɧɧɵɟ) ɫɨɫɬɨɢɬ ɢɡ ɬɪɟɯ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɬɚɛɥɢɰɚɦ ɡɚɤɥɚɞɨɤ ɢ ɢɦɟɟɬ ɜɢɞ,ɩɨɤɚɡɤɧɧɵɣ ɧɚ ɪɢɫ. 4.12.
Ɋɢɫ. 4.12. Ɏɨɪɦɚ ɪɚɫɤɪɵɜɚɟɬɫɹ ɩɪɢ ɜɵɛɨɪɟ ɩɭɧɤɬɚ ɦɟɧɸ «Ɋɚɛɨɬɚ ɫ ɞɚɧɧɵɦɢ – ȼɫɩɨɦ. ɞɚɧɧɵɟ» ɢɥɢ ɧɚɠɚɬɢɢ ɫɨɱɟɬɚɧɢɹ ɤɥɚɜɢɲ Ctrl + P. Ɋɚɡɦɟɫɬɢɬɟ ɧɚ ɮɨɪɦɟ ɤɨɦɩɨɧɟɧɬ TPageControl. ȼɵɛɢɪɚɹ ɜ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɦ ɦɟɧɸ ɩɭɧɤɬ New Page, ɫɨɡɞɚɣɬɟ ɬɪɢ ɡɚɤɥɚɞɤɢ TTabSheet – tsPassengers, tsDestinations, tsVoyages. Ɋɚɫɩɨɥɨɠɢɬɟ ɧɚ ɩɨɫɥɟɞɧɟɦ ɢɡ ɧɢɯ ɫɟɬɤɭ ɞɚɧɧɵɯ DBGrid ɢ ɞɪɭɝɢɟ ɷɥɟɦɟɧɬɵ ɭɩɪɚɜɥɟɧɢɹ, ɤɚɤ ɩɨɤɚɡɚɧɨ ɧɚ ɪɢɫ. 4.12. ɋɜɹɠɢɬɟ ɫɟɬɤɭ ɞɚɧɧɵɯ dbgVoyages ɫ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɦ ɢɫɬɨɱɧɢɤɨɦ ɞɚɧɧɵɯ DM.dsVoyages: TDataSource. Ⱦɨɛɚɜɥɟɧɢɟ/ɢɡɦɟɧɟɧɢɟ ɞɚɧɧɵɯ ɬɚɛɥɢɰ ɩɚɫɫɚɠɢɪɵ, ɩɭɧɤɬɵ ɧɚɡɧɚɱɟɧɢɹ, ɚɜɢɚɪɟɣɫɵ ɛɭɞɟɬ ɩɪɨɢɫɯɨɞɢɬɶ ɫ ɩɨɦɨɳɶɸ ɤɨɦɩɨɧɟɧɬɨɜ TDBEdit (ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɦɟɯɚɧɢɡɦɚ ɤɷɲɢɪɨɜɚɧɧɵɯ ɢɡɦɟɧɟɧɢɣ). 73
Ʉɨɦɩɨɧɟɧɬɵ dblcbDeparture, dblcbArrival: TDBLookUpComboBox ɫɥɭɠɚɬ ɞɥɹ ɡɚɧɟɫɟɧɢɹ ɞɚɧɧɵɯ ɨ ɩɭɧɤɬɚɯ ɧɚɡɧɚɱɟɧɢɹ ɜ ɢɧɮɨɪɦɚɰɢɸ ɨ ɚɜɢɚɪɟɣɫɟ. Ʉɨɦɩɨɧɟɧɬ dblcbDeparture ɧɚɫɬɪɚɢɜɚɟɬɫɹ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ. ɋɜɨɣɫɬɜɨ DataField DataSource
Ɂɧɚɱɟɧɢɟ
ɉɪɢɦɟɱɚɧɢɟ ȼ ɤɚɤɨɟ ɩɨɥɟ… … ɤɚɤɨɝɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ ɡɚɩɢɫɵɜɚɟɬɫɹ ɑɬɨ ɡɚɩɢɫɵɜɚɟɬɫɹ
DEPARTURE_ID DM.dsVoyages
KeyField
DESTINATION_ID
ListField
TITLE;DESTINATION_ID ɑɬɨ ɨɬɨɛɪɚɠɚɟɬɫɹ ɜ ɫɩɢɫɤɟ DM.dsDestinations Ɉɬɤɭɞɚ ɛɟɪɟɬɫɹ
ListSource
Ʉɨɦɩɨɧɟɧɬ dblcbArrival ɢɦɟɟɬ ɬɟ ɠɟ ɩɚɪɚɦɟɬɪɵ, ɱɬɨ ɢ ɤɨɦɩɨɧɟɧɬ dblcbDeparture.
Ʉɨɦɩɨɧɟɧɬ dbedCapacity: TDBEdit ɩɪɟɞɧɚɡɧɚɱɟɧ ɞɥɹ ɜɜɨɞɚ ɢɧɮɨɪɦɚɰɢɢ ɜ ɫɜɹɡɚɧɧɨɟ ɫ ɧɢɦ ɩɨɥɟ ɬɚɛɥɢɰɵ (ɤɨɥɢɱɟɫɬɜɨ ɞɨɫɬɭɩɧɵɯ ɩɨɫɚɞɨɱɧɵɯ ɦɟɫɬ ɧɚ ɪɟɣɫ). ɋɜɨɣɫɬɜɨ DataField DataSource
Ɂɧɚɱɟɧɢɟ
ɉɪɢɦɟɱɚɧɢɟ ȼ ɤɚɤɨɟ ɩɨɥɟ… … ɤɚɤɨɝɨ ɧɚɛɨɪɚ ɞɚɧɧɵɯ ɡɚɩɢɫɵɜɚɟɬɫɹ
CAPACITY DM.dsVoyages
Ȼɨɥɶɲɢɦ ɩɪɟɢɦɭɳɟɫɬɜɨɦ TDBEdit ɩɨ ɫɪɚɜɧɟɧɢɸ ɫ ɨɛɵɱɧɵɦɢ TEdit ɹɜɥɹɟɬɫɹ ɟɝɨ «ɬɢɩɢɡɢɪɨɜɚɧɧɨɫɬɶ»: ɜɜɨɞ ɫɢɦɜɨɥɨɜ, ɧɟɞɨɩɭɫɬɢɦɵɯ ɞɥɹ ɬɢɩɚ ɫɜɹɡɚɧɧɨɝɨ ɫ ɤɨɦɩɨɧɟɧɬɨɦ ɩɨɥɹ, ɛɥɨɤɢɪɭɟɬɫɹ. ɇɚɩɢɲɟɦ ɩɪɨɫɬɭɸ ɩɪɨɰɟɞɭɪɭ (ɦɟɬɨɞ ɤɥɚɫɫɚ TfmMiscData), ɤɨɬɨɪɚɹ ɜ ɫɥɭɱɚɟ ɞɨɛɚɜɥɟɧɢɹ/ɢɡɦɟɧɟɧɢɹ ɞɚɧɧɵɯ ɨ ɩɚɫɫɚɠɢɪɚɯ ɞɟɥɚɟɬ ɞɨɫɬɭɩɧɵɦɢ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɟ ɷɥɟɦɟɧɬɵ ɭɩɪɚɜɥɟɧɢɹ. procedure TfmMiscData.Passenger_UnLockDBEdits(Sender: ject); begin dbedName.ReadOnly := FALSE; dbedPassportNo.ReadOnly := FALSE; dbedCitizenship.ReadOnly := FALSE; dbedAddress.ReadOnly := FALSE; end;
TOb-
ɉɪɟɞɭɫɦɨɬɪɟɧɚ ɚɧɚɥɨɝɢɱɧɚɹ ɩɪɨɰɟɞɭɪɚ Passenger_LockDBEdits, ɡɚɩɪɟɳɚɸɳɚɹ ɢɡɦɟɧɟɧɢɟ ɞɚɧɧɵɯ ɫ ɩɨɦɨɳɶɸ ɜɢɡɭɚɥɶɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ ɜ ɫɥɭɱɚɟ, ɟɫɥɢ ɧɚɛɨɪ ɞɚɧɧɵɯ ɧɟ ɪɟɞɚɤɬɢɪɭɟɬɫɹ. procedure TfmMiscData.Passenger_LockDBEdits(Sender: TObject); begin dbedName.ReadOnly := TRUE; dbedPassportNo.ReadOnly := TRUE;
74
dbedCitizenship.ReadOnly := TRUE; dbedAddress.ReadOnly := TRUE; end;
ɉɪɢ ɡɚɤɪɵɬɢɢ ɮɨɪɦɵ ɩɪɨɜɟɪɹɟɦ, ɢɦɟɸɬɫɹ ɥɢ ɧɟɫɨɯɪɚɧɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ ɜ ɤɚɤɨɣ-ɥɢɛɨ ɢɡ ɬɚɛɥɢɰ, ɢ ɟɫɥɢ «ɞɚ», ɬɨ ɩɪɨɫɢɦ ɩɨɥɶɡɨɜɚɬɟɥɹ ɩɨɞɬɜɟɪɞɢɬɶ ɢɥɢ ɨɬɦɟɧɢɬɶ ɷɬɢ ɢɡɦɟɧɟɧɢɹ (ɦɟɯɚɧɢɡɦ ɤɷɲɢɪɨɜɚɧɢɹ ɢɡɦɟɧɟɧɢɣ), ɚ ɬɚɤɠɟ ɩɪɨɜɟɪɹɟɦ, ɚɤɬɢɜɧɚ ɥɢ ɬɪɚɧɡɚɤɰɢɹ, ɩɨɤɚɡɵɜɚɟɦ ɩɪɟɞɭɩɪɟɠɞɟɧɢɟ ɢ ɡɚɤɪɵɜɚɟɦ ɮɨɪɦɭ ɫ ɩɨɞɬɜɟɪɠɞɟɧɢɟɦ ɢɥɢ ɨɬɤɚɬɨɦ ɬɪɚɧɡɚɤɰɢɢ. procedure TfmMiscData.FormClose(Sender: TObject; var Action: TCloseAction); begin with DM do begin case pcMiscData.TabIndex of 0: if ibdsPassengers.UpdatesPending and ( MessageDlg('ɂɦɟɸɬɫɹ ɧɟɩɨɞɬɜɟɪɠɞɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ (PASSENGERS). ɉɨɞɬɜɟɪɞɢɬɶ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes ) then ibdsPassengers.ApplyUpdates else ibdsPassengers.CancelUpdates; 1: if ibdsDestinations.UpdatesPending and ( MessageDlg('ɂɦɟɸɬɫɹ ɧɟɩɨɞɬɜɟɪɠɞɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ (DESTINATIONS). ɉɨɞɬɜɟɪɞɢɬɶ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes ) then ibdsDestinations.ApplyUpdates else ibdsDestinations.CancelUpdates; 2: if ibdsVoyages.UpdatesPending and ( MessageDlg('ɂɦɟɸɬɫɹ ɧɟɩɨɞɬɜɟɪɠɞɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ (VOYAGES). ɉɨɞɬɜɟɪɞɢɬɶ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes ) then ibdsVoyages.ApplyUpdates else ibdsVoyages.CancelUpdates; end; if trMain.InTransaction then if ( MessageDlg('Ɍɪɚɧɡɚɤɰɢɹ ɚɤɬɢɜɧɚ.' + 'Ɂɚɜɟɪɲɢɬɶ ɟɟ ɫ ɫɨɯɪɚɧɟɧɢɟɦ ɢɡɦɟɧɟɧɢɣ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes ) then trMain.CommitRetaining else trMain.RollbackRetaining; end; end;
Ɏɨɪɦɚ ɛɪɨɧɢɪɨɜɚɧɢɹ ɚɜɢɚɛɢɥɟɬɚ ɜɵɡɵɜɚɟɬɫɹ ɜ ɨɛɪɚɛɨɬɱɢɤɟ procedure TfmMain.mBookingClick(Sender: TObject);
75
begin fmBooking.ShowModal; end;
ɢ ɢɦɟɟɬ ɫɥɟɞɭɸɳɢɣ ɜɢɞ.
Ɋɢɫ. 4.13. Ʉɨɦɩɨɧɟɧɬɵ dblcbPassenger, dblcbVoyage: TDBLookUpComboBox ɫɥɭɠɚɬ ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɢɧɮɨɪɦɚɰɢɢ ɨ ɤɨɞɟ ɩɚɫɫɚɠɢɪɚ-ɡɚɤɚɡɱɢɤɚ, ɜɵɛɢɪɚɟɦɨɝɨ ɢɡ ɬɚɛɥɢɰɵ ɩɚɫɫɚɠɢɪɨɜ, ɢ ɤɨɞɚ ɚɜɢɚɪɟɣɫɚ, ɧɚ ɤɨɬɨɪɵɣ ɛɪɨɧɢɪɭɟɬɫɹ ɛɢɥɟɬ. Ɉɬɥɢɱɢɟ ɨɬ ɤɨɦɩɨɧɟɧɬɨɜ dblcbDeparture, dblcbArrival, ɨɩɢɫɚɧɧɵɯ ɜɵɲɟ, ɫɨɫɬɨɢɬ ɜ ɬɨɦ, ɱɬɨ ɜɵɛɪɚɧɧɵɟ ɡɧɚɱɟɧɢɹ ɧɟ ɡɚɩɢɫɵɜɚɸɬɫɹ ɜ ɞɪɭɝɨɣ ɧɚɛɨɪ ɞɚɧɧɵɯ, ɚ ɢɫɩɨɥɶɡɭɸɬɫɹ ɜ ɤɚɱɟɫɬɜɟ ɜɯɨɞɧɵɯ ɩɚɪɚɦɟɬɪɨɜ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ NEW_BOOKING. Ʉɨɦɩɨɧɟɧɬ dblcbPassenger ɧɚɫɬɪɚɢɜɚɟɬɫɹ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ. ɋɜɨɣɫɬɜɨ
Ɂɧɚɱɟɧɢɟ
ListField
NAME;PASSPORT_NO;PASSENGER_ID
ListSource
DM.dsPassengers
Ʉɨɦɩɨɧɟɧɬ dblcbVoyage ɜɵɛɢɪɚɟɬ ɞɚɧɧɵɟ ɢɡ ɬɚɛɥɢɰɵ ɚɜɢɚɪɟɣɫɨɜ. ɋɜɨɣɫɬɜɨ
Ɂɧɚɱɟɧɢɟ
ListField
ALIAS;CAPACITY;VOYAGEDATE;DEP ARTURE_TXT;ARRIVAL_TXT ListSource DM.dsVoyages
ɋɪɟɞɢ ɨɬɨɛɪɚɠɚɟɦɵɯ ɩɨɥɟɣ ɩɪɢɫɭɬɫɬɜɭɸɬ ɫɨɡɞɚɧɧɵɟ ɧɚɦɢ ɪɚɧɟɟ lookup ɩɨɥɹ DEPARTURE_TXT, ARRIVAL_TXT. ɉɪɢ ɧɚɩɢɫɚɧɢɢ ɨɛɪɚɛɨɬɱɢɤɚ ɧɚɠɚɬɢɹ ɤɧɨɩɤɢ «Ȼɪɨɧɢɪɨɜɚɬɶ» ɧɟɨɛɯɨɞɢɦɨ ɩɪɢɧɹɬɶ ɜɨ ɜɧɢɦɚɧɢɟ, ɱɬɨ ɩɪɨɰɟɞɭɪɚ ɛɪɨɧɢɪɨɜɚɧɢɹ ɫɨɫɬɨɢɬ ɢɡ ɝɪɭɩ76
ɩɵ ɨɩɟɪɚɰɢɣ, ɩɪɨɢɡɜɨɞɢɦɵɯ ɧɚɞ ɞɜɭɦɹ ɬɚɛɥɢɰɚɦɢ (ɡɚɧɟɫɟɧɢɟ ɜ ɬɚɛɥɢɰɭ Bookings ɧɨɜɨɣ ɡɚɩɢɫɢ ɢ ɭɦɟɧɶɲɟɧɢɟ ɤɨɥɢɱɟɫɬɜɚ ɞɨɫɬɭɩɧɵɯ ɦɟɫɬ ɧɚ
ɪɟɣɫ),
ɩɪɢɱɟɦ
ɩɨɫɥɟɞɧɹɹ
ɜɵɩɨɥɧɹɟɬɫɹ
ɫɟɪɜɟɪɨɦ
ɜɧɭɬɪɢ
ɬɪɢɝɝɟɪɚ
TRIG_NEW_BOOKING. procedure TfmBooking.btBookClick(Sender: TObject); begin if ( MessageDlg('ɉɈȾɌȼȿɊȾɂɌȿ ȻɊɈɇɂɊɈȼȺɇɂȿ', mtConfirmation, [mbOk, mbCancel], 0) = mrOK ) then with DM do begin if not trBooking.Active then trBooking.StartTransaction; with ibspBookings do begin try // ɨɩɪɟɞɟɥɟɧɢɟ ɜɯɨɞɧɵɯ ɩɚɪɚɦɟɬɪɨɜ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ ParamByName('P_PASSENGER').Value := ibdsPassengersPASSENGER_ID.Value; // ɜɦɟɫɬɨ ibdsPassengersPASSENGER_ID.Value // ɦɨɠɧɨ ɧɚɩɢɫɚɬɶ «dblcbPassenger. // .ListSource.DataSet. // .FieldByName('passenger_id').Value», ɬ.ɤ. ɜɵɛɨɪ // ɤɚɤɨɝɨ-ɥɢɛɨ ɡɧɚɱɟɧɢɹ ɜ TDBLookupComboBox // ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɢɡɦɟɧɹɟɬ ɤɭɪɫɨɪ ɜ ɫɜɹɡɚɧɧɨɦ ɫ ɧɢɦ // ɧɚɛɨɪɟ ɞɚɧɧɵɯ ParamByName('P_VOYAGE').Value := ibdsVoyagesVOYAGE_ID.Value; // dblcbVoyage.ListSource. // .DataSet.FieldByName('voyage_id').Value; ParamByName('P_PRICE').Value := edPrice.Text; ParamByName('P_CLASS').Value := cbClass.Text; with ibqrGetBookingID do begin Close; ParamByName('voyage').Value := ibspBookings.ParamByName('P_VOYAGE').Value; ParamByName('passenger').Value := ibspBookings.ParamByName('P_PASSENGER').Value; end; Prepare; ExecProc; trBooking.CommitRetaining; trMain.Commit; trMain.StartTransaction; edPrice.Clear; cbClass.ItemIndex := 0; with ibqrGetBookingID do begin Open; MessageDlg('Ⱥɜɢɚɛɢɥɟɬ ɡɚɛɪɨɧɢɪɨɜɚɧ!' +#13+#13+ 'ɇɨɦɟɪ ɛɪɨɧɢɪɨɜɤɢ:' +#9+
77
FieldByName('p_booking').AsString, mtInformation, [mbOk], 0); end; except // ɜ ɫɥɭɱɚɟ ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɢɫɤɥɸɱɢɬɟɥɶɧɨɣ ɫɢɬɭɚɰɢɢ // ɨɬɤɚɬɵɜɚɟɦ ɨɛɟ ɬɪɚɧɡɚɤɰɢɢ trBooking.RollbackRetaining; trMain.RollbackRetaining; MessageDlg('Ɉɲɢɛɤɚ ɡɚɩɢɫɢ!', mtError, [mbOk], 0); end; end; fmBooking.OnShow(Sender); end; end;
Ɉɬɦɟɧɚ ɛɪɨɧɢ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɨ ɟɟ ɧɨɦɟɪɭ (BOOKING_ID) ɫ ɩɨɦɨɳɶɸ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɵ DELETE_BOOKING, ɢɦɟɸɳɟɣ ɥɢɲɶ ɨɞɧɢ ɜɯɨɞɧɨɣ ɩɚɪɚɦɟɬɪ. ȼ ɫɥɭɱɚɟ ɟɫɥɢ ɩɨɥɶɡɨɜɚɬɟɥɶ ɜɜɨɞɢɬ ɧɨɦɟɪ ɧɟɫɭɳɟɫɬɜɭɸɳɟɣ ɛɪɨɧɢ, ɜɵɜɨɞɢɬɫɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɟ ɫɨɨɛɳɟɧɢɟ. Ɉɩɟɪɚɰɢɹ ɨɬɦɟɧɵ ɛɪɨɧɢ, ɬɚɤɠɟ ɤɚɤ ɢ ɨɩɟɪɚɰɢɹ ɛɪɨɧɢɪɨɜɚɧɢɹ, ɫɨɫɬɨɢɬ ɢɡ ɝɪɭɩɩɵ ɨɩɟɪɚɰɢɣ, ɩɪɨɢɡɜɨɞɢɦɵɯ ɧɚɞ ɞɜɭɦɹ ɬɚɛɥɢɰɚɦɢ (ɭɞɚɥɟɧɢɟ ɢɡ ɬɚɛɥɢɰɵ Bookings ɫɭɳɟɫɬɜɭɸɳɟɣ ɡɚɩɢɫɢ ɢ ɭɜɟɥɢɱɟɧɢɟ ɤɨɥɢɱɟɫɬɜɚ ɞɨɫɬɭɩɧɵɯ ɦɟɫɬ ɧɚ ɪɟɣɫ). procedure TfmBooking.btUnBookClick(Sender: TObject); begin with DM do begin with ibqrGetBookingInfo do begin Close; ParamByName('booking').Value := edBookingID.Text; Open; end; if (ibqrGetBookingInfo.FieldByName('P_VOYAGE').AsString<>'') then begin with ibqrGetVoyageInfo do begin Close; ParamByName('voyage').Value := ibqrGetBookingInfo.FieldByName('P_VOYAGE').Value; Open; end; with ibqrGetPassengerInfo do begin Close; ParamByName('passenger').Value := ibqrGetBookingInfo.FieldByName('P_PASSENGER').Value; Open; end; if ( MessageDlg('ɋɇəɌɖ ȻɊɈɇɖ?, mtInformation,
78
[mbOk, mbCancel], 0) = mrOK ) then begin if not trBooking.Active then trBooking.StartTransaction; with ibspUnBook do begin try ParamByName('P_BOOKING').Value := edBookingID.Text; Prepare; ExecProc; trBooking.CommitRetaining; trMain.Commit; trMain.StartTransaction; MessageDlg('Ȼɪɨɧɶ ɫɧɹɬɚ.', mtInformation, [mbOk], 0); except trBooking.RollbackRetaining; trMain.Rollback; trMain.StartTransaction; MessageDlg('Ɉɲɢɛɤɚ ɭɞɚɥɟɧɢɹ!', mtError, [mbOk], 0); end; end; end; end else MessageDlg('Ɉɲɢɛɤɚ! Ȼɪɨɧɶ ɫ ɧɨɦɟɪɨɦ ' + edBookingID.Text+' ɧɟ ɧɚɣɞɟɧɚ!',mtError,[mbOk],0); end; end;
Ʉɚɤ ɢ ɜ ɫɥɭɱɚɟ ɫ ɛɪɨɧɢɪɨɜɚɧɢɟɦ, ɜ ɫɥɭɱɚɟ ɭɫɩɟɲɧɨɣ ɨɬɦɟɧɵ ɩɨɞɬɜɟɪɠɞɚɸɬɫɹ ɨɛɟ ɬɪɚɧɡɚɤɰɢɢ, ɜ ɫɥɭɱɚɟ ɧɟɭɞɚɱɢ ɨɛɟ ɨɬɤɚɬɵɜɚɸɬɫɹ. Ⱦɥɹ ɩɪɨɜɟɪɤɢ ɫɭɳɟɫɬɜɨɜɚɧɢɹ ɛɪɨɧɢ ɫ ɜɜɟɞɟɧɧɵɦ ɩɨɥɶɡɨɜɚɬɟɥɟɦ ɧɨɦɟɪɨɦ ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɨɦɩɨɧɟɧɬ ibqrGetBookingInfo: TIBQuery, ɨɛɪɚɳɚɸɳɢɣɫɹ ɤ ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɟ GET_BOOKING_INFO ɱɟɪɟɡ ɡɚɩɪɨɫ SELECT * FROM GET_BOOKING_INFO (:booking)
ɜ ɤɚɱɟɫɬɜɟ ɩɚɪɚɦɟɬɪɚ :booking ɯɪɚɧɢɦɨɣ ɩɪɨɰɟɞɭɪɟ ɩɟɪɟɞɚɟɬɫɹ ɧɨɦɟɪ ɛɪɨɧɢ. Ɂɚɞɚɧɢɹ ɞɥɹ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨɣ ɪɚɛɨɬɵ Ɋɟɲɟɧɢɟ ɤɚɠɞɨɣ ɡɚɞɚɱɢ ɞɨɥɠɧɨ ɜɤɥɸɱɚɬɶ ER-ɦɨɞɟɥɶ ɭɤɚɡɚɧɧɨɣ ɩɪɟɞɦɟɬɧɨɣ ɨɛɥɚɫɬɢ, ɫɬɪɭɤɬɭɪɭ ȻȾ ɫ ɫɟɪɜɟɪɧɨɣ ɪɟɚɥɢɡɚɰɢɟɣ ɛɢɡɧɟɫ-ɩɪɚɜɢɥ ɢ ɤɥɢɟɧɬɫɤɨɟ ɩɪɢɥɨɠɟɧɢɟ. 79
1. Ȼɢɛɥɢɨɬɟɤɚ. 2. ȼɢɞɟɨɬɟɤɚ. 3. ɂɧɮɨɪɦɚɰɢɨɧɧɨ-ɩɨɢɫɤɨɜɚɹ ɫɢɫɬɟɦɚ. 4. Ɇɭɡɵɤɚɥɶɧɵɟ ɚɥɶɛɨɦɵ. 5. Ɉɬɞɟɥ ɤɚɞɪɨɜ. 6. Ɋɚɫɩɪɟɞɟɥɟɧɢɟ ɭɱɟɛɧɨɣ ɧɚɝɪɭɡɤɢ. 7. Ȼɪɨɧɢɪɨɜɚɧɢɟ ɚɜɢɚɛɢɥɟɬɨɜ. 8. Ƚɨɫɬɢɧɢɰɚ. 9. ɉɪɨɤɭɪɚɬɭɪɚ. 10. Ɏɚɤɭɥɶɬɟɬ. 11. ɂɌɍ. 12. Ʉɭɥɢɧɚɪɧɵɟ ɪɟɰɟɩɬɵ. 13. ɇɚɪɨɞɧɵɟ ɞɟɩɭɬɚɬɵ. 14. Ɋɟɝɢɫɬɪɚɬɭɪɚ ɥɟɱɟɛɧɨɝɨ ɭɱɪɟɠɞɟɧɢɹ. 15. Ⱥɜɬɨɡɚɩɱɚɫɬɢ. 16. Ɂɚɤɚɡɵ ɧɚ ɫɛɨɪɤɭ ɤɨɦɩɶɸɬɟɪɨɜ. 17. Ⱥɜɬɨɫɚɥɨɧ.
18. F1 Word Grand Prix. 19. Ȼɢɪɠɚ ɬɪɭɞɚ. 20. Ɍɭɪɚɝɟɧɬɫɬɜɨ. 21. Ⱥɪɟɧɞɚ ɩɨɦɟɳɟɧɢɣ. 22. Ɋɢɷɥɬɟɪɫɤɚɹ ɮɢɪɦɚ. 23. CIA. 24. Ɏɢɧɚɧɫɨɜɚɹ ɨɪɝɚɧɢɡɚɰɢɹ. 25. ɍɩɪɚɜɥɟɧɢɟ ɝɨɫɢɦɭɳɟɫɬɜɨɦ. 26. Ɉɪɞɟɧɚ ɢ ɧɚɝɪɚɞɵ. 27. Ɉɯɪɚɧɧɨɟ ɚɝɟɧɬɫɬɜɨ. 28. Hollywood. 29. Ɋɨɫɫɢɣɫɤɢɣ ɮɭɬɛɨɥ. 30. Ƚɨɪɨɞɫɤɢɟ ɞɨɫɬɨɩɪɢɦɟɱɚɬɟɥɶɧɨɫɬɢ. 31. Ⱦɨɦɚ ɧɚ ɩɪɨɞɚɠɭ. 32. Ⱥɥɶɩɢɧɢɫɬɫɤɢɣ ɤɥɭɛ. 33. ɍɩɪɚɜɥɟɧɢɟ ɩɪɨɟɤɬɚɦɢ. 34. Ʉɚɬɟɪɚ ɢ ɹɯɬɵ. 35. Ɋɟɫɬɨɪɚɧ. 36. Ɂɚɩɨɜɟɞɧɢɤ.
ɉɪɢɥɨɠɟɧɢɟ. Ɍɢɩɵ ɩɨɥɟɣ InterBase
SmallInt
Ɋɚɡɦɟɪ, ɛɚɣɬ 2
Ⱦɢɚɩɚɡɨɧ / ɬɨɱɧɨɫɬɶ –32768…32767
Integer
4
Float
4
–2,147,483,648… 2,147,483,647 –3,4 1038… 3,4 10 38 –2,225 10307 2,225 10308 0–32767
Ɍɢɩ ɩɨɥɹ
Double 8 precision Char(n) n VarChar(n)
n
0–32767
Date
8
01.01.0100 – 29.02.32768 0:00–23:59.9999 1.01.100 – 29.02. 32768
Time 4 TIMESTAMP 8
80
ɏɪɚɧɢɦɵɟ ɡɧɚɱɟɧɢɹ ɐɟɥɵɟ ɱɢɫɥɚ ɜ ɞɢɚɩɚɡɨɧɟ –32767 … 32767 ɐɟɥɵɟ ɱɢɫɥɚ ɫɨ ɡɧɚɤɨɦ ɑɢɫɥɚ ɫ ɩɥɚɜɚɸɳɟɣ ɬɨɱɤɨɣ ɬɨɱɧɨɫɬɶɸ ɞɨ 7 ɡɧɚɱɚɳɢɯ ɰɢɮɪ ɑɢɫɥɚ ɫ ɩɥɚɜɚɸɳɟɣ ɬɨɱɤɨɣ ɬɨɱɧɨɫɬɶɸ ɞɨ 15 ɡɧɚɱɚɳɢɯ ɰɢɮɪ ɋɢɦɜɨɥɶɧɵɣ ɫɬɨɥɛɟɰ ɞɥɢɧɨɣ n ɫɢɦɜɨɥɨɜ ɋɢɦɜɨɥɶɧɵɣ ɫɬɨɥɛɟɰ ɩɟɪɟɦɟɧɧɨɣ ɞɥɢɧɵ, ɫɨɞɟɪɠɚɳɢɣ ɞɨ n ɫɢɦɜɨɥɨɜ Ⱦɚɬɚ ȼɪɟɦɹ ɞɧɹ ɋɨɞɟɪɠɢɬ ɞɚɬɭ ɢ ɜɪɟɦɹ
Blob
ɉɟɪɟɦɟɧɧɵɣ
ɧɟɬ
Decimal (p,s)
ɩɟɪɟɦɟɧɧɵɣ
P – ɨɛɳɟɟ ɱɢɫɥɨ ɡɧɚɤɨɜ ɨɬ 1 ɞɨ 18, s – ɱɢɫɥɨ ɡɧɚɤɨɜ ɩɨɫɥɟ ɬɨɱɤɢ ɨɬ 0 ɞɨ 18, s <= p
Numeric (p,s)
ɩɟɪɟɦɟɧɧɵɣ
P – ɨɛɳɟɟ ɱɢɫɥɨ ɡɧɚɤɨɜ ɨɬ 1 ɞɨ 18, s – ɱɢɫɥɨ ɡɧɚɤɨɜ ɩɨɫɥɟ ɬɨɱɤɢ.
ɂɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɯɪɚɧɟɧɢɹ ɨɛɴɟɦɧɵɯ ɞɚɧɧɵɯ (ɬɟɤɫɬ, ɝɪɚɮɢɤɚ, ɨɰɢɮɪɨɜɚɧɧɵɣ ɡɜɭɤ ɢ ɞɪ.). ɋɨɞɟɪɠɢɦɨɟ ɨɩɪɟɞɟɥɹɟɬɫɹ ɩɨɞɬɢɩɨɦ ɑɢɫɥɨ ɫ ɮɢɤɫɢɪɨɜɚɧɧɨɣ ɬɨɱɤɨɣ. ɇɚɩɪɢɦɟɪ, DECIMAL(10, 3) ɫɨɞɟɪɠɢɬ ɱɢɫɥɚ ɫɥɟɞɭɸɳɟɝɨ ɮɨɪɦɚɬɚ: ppppppp.sss. ɑɢɫɥɨ P ɨɩɪɟɞɟɥɹɟɬ ɧɚɢɦɟɧɶɲɭɸ ɬɨɱɧɨɫɬɶ ɩɪɢ ɯɪɚɧɟɧɢɢ ɑɢɫɥɨ ɫ ɮɢɤɫɢɪɨɜɚɧɧɨɣ ɬɨɱɤɨɣ. ɇɚɩɪɢɦɟɪ, NUMERIC (10, 3) ɫɨɞɟɪɠɢɬ ɱɢɫɥɚ ɫɥɟɞɭɸɳɟɝɨ ɮɨɪɦɚɬɚ: ppppppp.sss. P ɨɩɪɟɞɟɥɹɟɬ ɬɨɱɧɨɟ ɱɢɫɥɨ ɯɪɚɧɢɦɵɯ ɡɧɚɤɨɜ
Ɍɚɛɥɢɰɚ ɫɨɫɬɚɜɥɟɧɚ ɩɪɢɦɟɧɢɬɟɥɶɧɨ ɤ InterBase 6.5 ɢ Firebird 1.1, ɜ ɞɪɭɝɢɯ ɜɟɪɫɢɹɯ InterBase ɢ Firebird ɢɦɟɸɬɫɹ ɧɟɤɨɬɨɪɵɟ ɪɚɡɥɢɱɢɹ. Ʌɢɬɟɪɚɬɭɪɚ 1. Ʉɨɜɹɡɢɧ Ⱥ. Ɇɢɪ InterBase / Ⱥ. Ʉɨɜɹɡɢɧ., ɋ. ȼɨɫɬɪɢɤɨɜ. – Ɇ. : ɄɍȾɂɐɈȻɊȺɁ, 2006. – 496 ɫ. 2. ɋɤɥɹɪ Ⱥ.ə. ȼɜɟɞɟɧɢɟ ɜ InterBase / Ⱥ.ə. ɋɤɥɹɪ. – Ɇ. : Ƚɨɪɹɱɚɹ ɥɢɧɢɹ – Ɍɟɥɟɤɨɦ, 2002. – 517 ɫ. 3. Ʉɪɟɧɤɟ Ⱦ. Ɍɟɨɪɢɹ ɢ ɩɪɚɤɬɢɤɚ ɩɨɫɬɪɨɟɧɢɹ ɛɚɡ ɞɚɧɧɵɯ / Ⱦ. Ʉɪɟɧɤɟ. – ɋɉɛ. : ɉɢɬɟɪ, 2005. – 859 ɫ. 4. Ʉɷɧɬɭ Ɇ. Delphi 7 ɞɥɹ ɩɪɨɮɟɫɫɢɨɧɚɥɨɜ / Ɇ. Ʉɷɧɬɭ. – ɋɉɛ. : ɉɢɬɟɪ, 2004. – 1101 ɫ. 5. Ɋɚɡɪɚɛɨɬɤɚ ɩɪɢɥɨɠɟɧɢɣ ɛɚɡ ɞɚɧɧɵɯ ɜ ɫɪɟɞɟ Delphi : ɭɱɟɛ.-ɦɟɬɨɞ. ɩɨɫɨɛɢɟ ɩɨ ɫɩɟɰɢɚɥɶɧɨɫɬɢ «ɉɪɢɤɥɚɞɧɚɹ ɦɚɬɟɦɚɬɢɤɚ ɢ ɢɧɮɨɪɦɚɬɢɤɚ» 010200 / ɫɨɫɬ.: ȼ.Ƚ. Ɋɭɞɚɥɟɜ, ɘ.Ⱥ. Ʉɪɵɠɚɧɨɜɫɤɚɹ. – ȼɨɪɨɧɟɠ : ɅɈɉ ȼȽɍ, 2002. – ɑ. 1. – 59 ɫ.
81
ɋɈȾȿɊɀȺɇɂȿ ȼɜɟɞɟɧɢɟ........................................................................................................... 3 1. Ɉɫɧɨɜɵ ɪɚɛɨɬɵ ɜ InterBase ......................................................................... 4 1.1. ɍɫɬɚɧɨɜɤɚ InterBase ............................................................................ 4 1.2. ɂɧɫɬɪɭɦɟɧɬɚɥɶɧɵɟ ɫɪɟɞɫɬɜɚ ............................................................. 5 1.3. ɋɨɡɞɚɧɢɟ ɢ ɪɟɝɢɫɬɪɚɰɢɹ ɛɚɡɵ ɞɚɧɧɵɯ .............................................. 5 1.4. ɋɨɡɞɚɧɢɟ ɬɚɛɥɢɰ ............................................................................... 10 1.5. ɋɨɡɞɚɧɢɟ ɝɟɧɟɪɚɬɨɪɨɜ, ɬɪɢɝɝɟɪɨɜ ɢ ɯɪɚɧɢɦɵɯ ɩɪɨɰɟɞɭɪ............. 12 1.6. ȼɵɩɨɥɧɟɧɢɟ SQL-ɡɚɩɪɨɫɨɜ.............................................................. 14 1.7. ɍɩɪɚɜɥɟɧɢɟ ɩɨɥɶɡɨɜɚɬɟɥɹɦɢ ........................................................... 16 1.7.1. ɋɦɟɧɚ ɩɚɪɨɥɹ ɚɞɦɢɧɢɫɬɪɚɬɨɪɚ..................................................... 16 1.7.2. Ⱦɨɛɚɜɥɟɧɢɟ ɧɨɜɨɝɨ ɩɨɥɶɡɨɜɚɬɟɥɹ................................................. 17 1.7.3. ɉɪɟɞɨɫɬɚɜɥɟɧɢɟ ɩɪɢɜɢɥɟɝɢɣ ........................................................ 17 1.7.4. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɪɨɥɟɣ .................................................................... 18 1.8. ɋɨɡɞɚɧɢɟ UDF ................................................................................... 20 2. ɋɟɪɜɟɪɧɚɹ ɱɚɫɬɶ ɩɪɢɥɨɠɟɧɢɹ................................................................... 22 2.1. ɉɪɨɟɤɬɢɪɨɜɚɧɢɟ ɩɪɢɥɨɠɟɧɢɣ.......................................................... 22 2.2. Ƚɟɧɟɪɚɬɨɪɵ ........................................................................................ 24 2.3. ɏɪɚɧɢɦɵɟ ɩɪɨɰɟɞɭɪɵ ...................................................................... 25 2.4. Ɍɪɢɝɝɟɪɵ ............................................................................................ 28 2.5. ɉɪɟɞɫɬɚɜɥɟɧɢɹ .................................................................................. 30 3. ɇɚɩɢɫɚɧɢɟ ɤɥɢɟɧɬɫɤɢɯ ɩɪɢɥɨɠɟɧɢɣ ....................................................... 31 3.1. ɋɨɟɞɢɧɟɧɢɟ ɫ ɫɟɪɜɟɪɨɦ.................................................................... 32 3.2. ɍɩɪɚɜɥɟɧɢɟ ɬɪɚɧɡɚɤɰɢɹɦɢ .............................................................. 33 3.3. ɉɚɪɚɦɟɬɪɵ ɬɪɚɧɡɚɤɰɢɣ .................................................................... 36 3.3.1. ɍɪɨɜɧɢ ɢɡɨɥɹɰɢɢ ɬɪɚɧɡɚɤɰɢɣ ...................................................... 37 3.3.2. Ȼɥɨɤɢɪɨɜɤɢ .................................................................................... 38 3.3.3. ɇɚɫɬɪɨɣɤɚ ɩɚɪɚɦɟɬɪɨɜ ɬɪɚɧɡɚɤɰɢɣ.............................................. 41 3.4. Ʌɚɛɨɪɚɬɨɪɧɚɹ ɪɚɛɨɬɚ........................................................................ 43 3.5. Ʉɨɦɩɨɧɟɧɬɵ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɵɦ ...................................................... 49 3.5.1. TIBTable ......................................................................................... 49 3.5.2. TIBQuery ........................................................................................ 50 3.5.3. TIBDataSet...................................................................................... 50 3.5.4. TIBStoredProc................................................................................. 51 3.6. Ɍɪɚɧɡɚɤɰɢɢ ɢ ɤɷɲɢɪɨɜɚɧɧɵɟ ɢɡɦɟɧɟɧɢɹ ....................................... 53 3.7. Ʉɨɦɩɨɧɟɧɬɵ ɭɩɪɚɜɥɟɧɢɹ ɞɚɧɧɵɦɢ................................................. 55 4. ɉɪɢɦɟɪ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ...................................................................... 58 4.1. ɉɪɟɞɦɟɬɧɚɹ ɨɛɥɚɫɬɶ ......................................................................... 58 4.2. ɋɬɪɭɤɬɭɪɚ ɛɚɡɵ ɞɚɧɧɵɯ. ɋɟɪɜɟɪɧɚɹ ɱɚɫɬɶ ɩɪɢɥɨɠɟɧɢɹ............... 59 4.3. Ʉɥɢɟɧɬɫɤɚɹ ɱɚɫɬɶ.............................................................................. 64 4.3.1. ɇɚɫɬɪɨɣɤɚ ɦɨɞɭɥɹ ɞɚɧɧɵɯ ........................................................... 65 4.3.2. ȼɡɚɢɦɨɞɟɣɫɬɜɢɟ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ................................................ 70 Ɂɚɞɚɧɢɹ ɞɥɹ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨɣ ɪɚɛɨɬɵ......................................................... 79 ɉɪɢɥɨɠɟɧɢɟ. Ɍɢɩɵ ɩɨɥɟɣ InterBase ............................................................ 80 Ʌɢɬɟɪɚɬɭɪɚ ..................................................................................................... 81 82
ɍɱɟɛɧɨɟ ɢɡɞɚɧɢɟ
Ɋɭɞɚɥɟɜ ȼɚɥɟɪɢɣ Ƚɟɧɧɚɞɶɟɜɢɱ, ɉɪɨɧɢɧ ɋɟɪɝɟɣ ɋɟɪɝɟɟɜɢɱ ɄɅɂȿɇɌ-ɋȿɊȼȿɊɇɕȿ ɉɊɂɅɈɀȿɇɂə ȻȺɁ ȾȺɇɇɕɏ ɍɱɟɛɧɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ
Ɋɟɞɚɤɬɨɪ ȿ.ɋ. Ʉɨɬɥɹɪɨɜɚ
ɉɨɞɩɢɫɚɧɨ ɜ ɩɟɱɚɬɶ 03.05.07. Ɏɨɪɦɚɬ 60×84/16. ɍɫɥ. ɩɟɱ. ɥ. 4,82. Ɍɢɪɚɠ 50 ɷɤɡ. Ɂɚɤɚɡ 877. ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. 394000, ɝ. ȼɨɪɨɧɟɠ, ɩɥ. ɢɦ. Ʌɟɧɢɧɚ, 10. Ɍɟɥ. 208-298, 598-026 (ɮɚɤɫ) http://www.ppc.vsu.ru; e-mail:
[email protected] Ɉɬɩɟɱɚɬɚɧɨ ɜ ɬɢɩɨɝɪɚɮɢɢ ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɨɝɨ ɰɟɧɬɪɚ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. 394000, ɝ. ȼɨɪɨɧɟɠ, ɭɥ. ɉɭɲɤɢɧɫɤɚɹ, 3. Ɍɟɥ. 204-133. 83