3_autoincrement_autoincerror.prg
上传用户:szlqfpcb
上传日期:2020-05-18
资源大小:5k
文件大小:2k
源码类别:

数据库系统

开发平台:

VFP

  1. ********************************************************************************
  2. * 3_AutoIncrement_AutoIncError.prg
  3. * Description: This program will show how to use Scatter / Gather with auto
  4. * increment fields by setting the AutoIncError to 'OFF' in order
  5. * to suppress a Read-only error from being thrown.
  6. * Tip: The AutoIncError setting can be set globally by using SET AUTOINCERROR.
  7. ********************************************************************************
  8. #DEFINE CRLF CHR(13)+CHR(10)
  9. LOCAL lcStr as String
  10. LOCAL lnSelect as Integer
  11. * Save environment and erase auto increment table.
  12. lnSelect = SELECT()
  13. SELECT 0
  14. ERASE _AI_Table.dbf
  15. * Create Auto Increment table setting the 'iID' column as an auto increment field
  16. * with the starting value set to 1 and the increment value set to 1.
  17. CREATE TABLE AI_Table FREE ;
  18. ( iID i AUTOINC NEXTVALUE 1 STEP 1, ;
  19.   CustName c(30))
  20. * Insert three records into the table.  You do not assign any values to the auto
  21. * increment field.
  22. INSERT INTO AI_Table (CustName) VALUES ("Jane Smith")
  23. INSERT INTO AI_Table (CustName) VALUES ("John Doe")
  24. INSERT INTO AI_Table (CustName) VALUES ("Greg Jones")
  25. GO TOP
  26. * Browse the table.
  27. BROWSE NOWAIT
  28. lcStr = "Auto Increment Table created with the starting value set to 1 and" + ;
  29. " the increment set to 1"
  30. MESSAGEBOX(lcStr)
  31. * Scatter the current record
  32. SCATTER MEMVAR
  33. * Set the AutoIncError setting for the cursor to OFF to suppress the error and
  34. * ignore the replacement value when a value is copied into the auto increment 
  35. * field.
  36. CURSORSETPROP("AutoIncError","OFF")
  37. * Append a new record and replace the fields with the values from the Scatter.
  38. APPEND BLANK
  39. GATHER MEMVAR
  40. * Browse the table.
  41. BROWSE NOWAIT
  42. lcStr = "Auto Increment Table was altered to set the next auto increment value" + ;
  43. " to 100 and the increment step to 10"
  44. MESSAGEBOX(lcStr)
  45. * Restore environment.
  46. USE
  47. SELECT (lnSelect)
  48. RETURN