Access | scripts | Data Access data in a data window in a PowerScript script
Zhang Jianji 01-6-22 03:50:25
In the previous version of 4.0, if you wanted to access data in a data window in a PowerScript script, there was only one way to do it, which is to use the SetItem and GetItem series functions to specify what you want The value of one of the rows accessed, the limitation of which is that you can access only one number at a time. In version 5.0, PowerBuilder expands the properties of the data window so that the data in the Data window becomes an attribute of the object, allowing the user to be as direct as accessing other object properties Access data from the Data window. So we have two ways to access the data. 1. Traditional use of SetItem and GetItem series functions, such as: Dw_1.setitem (1, "EmpName", "Phillips") Ls_name = dw_1.getitemstring (1, "EmpName") 2. An expression method that specifies the entire data for a column, a row, a piece, or a user-selected row, or even the entire data window control , such as: dw_1.object.empname[1] = "Phillips" dw_1.object.data[1,1] = "Phillips" Both of these methods can allow the user to specify a specific data buffer, also This means that you can access the original values, filtered values, deleted values, and current values before the data is modified in any of these ways. In most cases, you can take either of these two methods, but the two methods are also pros and cons when used. If you just want to access a number of a column in a row, the two methods are essentially the same in terms of execution efficiency. If you plan to use the Data window's column name instead of a numeric value to represent a column, theA column's column name does not know before running, or depends on the user's different input to decide, then you can only use the function method, because this method can dynamically change the column name. If you need to access more than one column of data, but instead determine the range of multiple rows and columns, you will get more efficient with the expression method. The expression method is PowerBuilder5.0 new function, although this method can make the data window object-oriented characteristic more obvious, the language expression is also more intuitive, easy to make the spectator read Reading other people's programs is easy to understand, but the grammatical form of this method is very complex and diverse, but not easy to use. Generally speaking, the syntax of an expression can be divided into 3 groups: directly specify the column name method: If you know beforehand that you need to access the data in the column name, and only access this column , you can use this method. Select one or more records in this control Dwcontrol.object.columnname {. buffer} {. datasource} {[startrownum{, endrownum}]} The four buffers on the data window have been introduced in the previous topic, and the buffer option in this command's syntax allows you to select Primary,filter or delete the three buffers , the default is Primary;datasource option is current or original, and the default is current. If you select original, the system will read the data in the original buffer of the data window, obviously the original buffer is read-only and you cannot assign a value to it. In the following brackets, you can specify the number of start and end records in this column that you intend to access, and if it's just a record, you're in the STAThe line number is specified in the Rtrownum, and if the two parameters in the brackets are all defaults, then all records for that column. For example: string ls_namels_name = Dw_1.object.name[1] Another example: dw_1.object.salary[8,12] = id_salaryid_salary is an array, if only four element, the value of line 12th salary is null. Select the highlighted record Dwcontrol in this data window control. Object.columnname {. Primary}{.datasource}. Selected the record highlighted in the Data window is the record you used to highlight the line by using the SelectRow function. Obviously, access to this feature data can only be in the primary buffer, but the data source can still choose whether it is current or original. If you choose the original, that is, you get the data from the database is found in the data before the modification. For example: string ls_namels_name = dw_1.Object.name.Selected uses numeric values to represent columns: Dwcontrol. Object.data {. buffer} {. DataSource} [Startrownum, Startcolnum, Endrownum, Endcolnum] We know the letters in the SetItem and GetItem series Number, the expression of a column can be indicated either by a column name or by a numeric indicator, as is the case here. If we use numerical means to refer to a column name, as in the previous comparison, we replace the column name with the keyword data, and in the following square brackets, the argument becomes four. The return value of this expression will be an array of structures, or a user object. It is important to note that the structure you define or useThe user object must match the data type of these columns in the Data window, or the PowerBuilder will appear with an error. Manipulation of whole-line records: Dwcontrol. Object.data {. buffer} {. datasource} {[RowNum]} This method is a special case of the previous method, and if the value in RowNum is default, the entire data window is represented All data. For example, the column name and data type in the Data window are as follows: ID (number) name (String) Retired_status (Boolean) birth_date (date) First we have to draw in the structure A STR_EMPDATA data structure is defined in the pen. It consists of four elements, the types are: Integer, String, Boolean, and date execute the following code: Str_empdata lstr_currdata[] Lstr_currdata = dw_1.obj Ect. Data the upper bound of the array in the LSTR_CURRDATA structure is equal to the number of rows recorded in the Data window control, and the assignment is completed. We can also use this method to specify the high brightness row dwcontrol in this control. Object.data {. Primary} {. DataSource}. Selected these three forms of functionality are compared as follows: The access scope syntax accesses the high brightness row 11 columns Dwcontrol.object.columnname{.buffer} {. DataSource in the control Can be more than 2 columns Dwcontrol.object.data{.buffer} {. DataSource} not all columns of 31 records Dwcontrol.object.data{.buffer} {. DataSource We should be aware of the following points when using these statements: using the SetItem and GetItem series functions, PowerBuilder will not check the validity of the column that you indicated at compile time, you must check yourself and ensure the validity of the reference. In the first method we must note that there must be a suffix after the column name, for example: ld_salary[] = Dw_1.object.emp_salary.primaryld_salray = Dw_1.object Emp_salary[5] The above expression is legal, but ld_salary[] = dw_1.object.emp_salary is an illegal expression. Because dw_1.object.emp_salary refers to the Dwobject object of this emp_salary column, not the data in the Emp_salary column. We can use Dw_1.object.emp_salary to refer to objects in the data window, such as: integer li_data dwobject dwo_empsalary dwo_empsalary = Dw_1.obje Ct.emp_salary for li_cnt = 1 to Li_data = dwo_empsalary[li_cnt] ... NEXT This expression method returns the data type of any type, PowerBuilder will convert the data type of the database and PowerBuilder according to the "compatible" principle, so if you call the overload function to use an expression method to get data from a data window as a parameter, it is recommended that you use a function that casts the data type. For example: Wf_overload (Real (dw_1.object.dept_id[1))
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.