معالجة البيانات
يمكنك كتابة التعليمات البرمجية لمعالجة البيانات المخزنة في قاعدة البيانات.
- استخدم طريقة
selectلتعريف البيانات التي سيتم تعديلها. - تُستخدم طريقة
insertلإضافة سجل واحد أو أكثر إلى جدول. - تُستخدم طريقة
updateلتعديل السجل الحالي في حقول النظام المناسبة. - تُستخدم عبارة
whereلتحديد الحالة التي ستختبرها أسلوبupdateأثناء معالجة كل صف بالجدول. - تُستخدم طريقة
deleteلإزالة سجلات من جدول. قبل استخدام طريقةupdateأوdelete، يجب استخدام طريقةselectلتحديد البيانات المراد تحديثها أو حذفها. - لتحديد عدة سجلات أو حقول، تستخدم طريقة
selectبالبداية ثم تستخدم طريقةnextلإحضار السجل التالي في جدول. - لتكرار الحلقة عبر العديد من السجلات التي تحقق معيار محدد، يمكنك استخدام
while selectطريقة.
ستقوم العبارة select بإحضار البيانات أو معالجتها من قاعدة البيانات باستخدام X++. يمكنك استخدام عبارة select لإحضار سجل أو حقل واحد. يمكنك استخدام العبارات الأخرى مثل next لإحضار سجلات إضافية أو استخدام while select لاجتياز سجلات متعددة.
على سبيل المثال، سوف يُحضر نموذج الرمز التالي جميع الأعمدة في الصف الأول من CustTable، ثم سيطبع القيمة في عمود AccountNum لهذا الصف:
CustTable custTable;
select firstonly custTable; //this is a short notation for 'select firstonly * from custTable;'
info("AccountNum: " + custTable.AccountNum);
فيما يلي نماذج من التعليمات البرمجية لطرق insert، وupdate، وdelete. تستخدم العينات جدولاً وهمياً هو MyCustomerTable يحتوي على حقول وهمية لـ AccountNumber وCustomerName.
طريقة
insert//This will insert a new record into a sample MyCustomerTable table. The only mandatory field that is set on this table is AccountNumber. private void AddCustomer() { MyCustomerTable myCustomerTable; ttsBegin; myCustomerTable.AccountNumber = "1234"; //The new record will have the account number 1234. myCustomerTable.insert(); ttsCommit; }طريقة
update//This will update the record where the AccountNumber field is set to 1234 by adding more information in the CustomerName field. private void UpdateCustomer() { MyCustomerTable myCustomerTable ttsBegin; select forUpdate myCustomerTable where myCustomerTable.AccountNumber == "1234"; //Now we will update the CustomerName field to be Sally myCustomerTable.CustomerName = "Sally"; myCustomerTable.update(); ttsCommit; }طريقة
delete//This will delete the record from the MyCustomerTable table where the AccountNumber field is set to 1234. private void DeleteCustomer() { ttsBegin; while select forUpdate myCustomerTable where myCustomerTable.AccountNumber == "1234" { myCustomerTable.delete(); } ttsCommit; }