МатематикаМоя статистика
Тест по PowerBuilder
100 вопросов в 10 темах (лёгкий — 35, средний — 40, сложный — 25). Выберите темы, уровень и количество вопросов — к каждому ответу есть объяснение.
PowerScript, события и функции, наследование, DataWindow и его буферы, транзакции и SQLCA, окна и элементы управления, обработка ошибок и современный PowerBuilder. Вопросы на английском.
Все вопросы теста 100
Нажмите на вариант ответа, чтобы проверить себя, или «Показать ответ».
PowerBuilder basics10
Which file extension does a PowerBuilder library, the file that stores the source and compiled form of objects such as windows and menus, have?
- .pbd
- .pbw
- .pbt
- .pbl
Objects are kept in PowerBuilder libraries (.pbl). A .pbt file is a target (application object plus library list), a .pbw is a workspace that groups targets, and a .pbd is a compiled deployment library without source — mixing up .pbl and .pbd is the usual slip, since both are "libraries".
Which object's Open event is the first script to run when a PowerBuilder application starts?
- The first window in the library list
- The application object
- The first user object created by the application
- The main menu object
Every target has exactly one application object; its Open event is the entry point, and that script typically connects to the database and opens the first window. Windows are not opened automatically just because they exist in a library.
What does a PowerBuilder target (.pbt file) define?
- An application object together with its ordered library list of .pbl files
- The database profiles used by the Database painter
- A compiled runtime package ready to copy to users
- A group of several applications opened together in the IDE
A target describes one application: which application object to use and which libraries (in which order) contain its objects. Grouping several targets is the job of the workspace (.pbw); database profiles are stored separately, and compiled output is produced by a project object.
Two libraries in a target's library list both contain a window named w_main. Which one does the application use?
- Neither — the target refuses to build until one is deleted
- The one that was modified most recently
- The one in the library listed first in the library list
- The one in the library listed last, because later libraries override earlier ones
PowerBuilder searches the library list from top to bottom and uses the first object with a matching name. This is why the order of the library list matters; assuming that a later library "overrides" an earlier one, as with some class-path schemes, is the typical mistake.
A project is set to build PowerBuilder dynamic libraries (.pbd) rather than machine-code DLLs. What do the .pbd files contain?
- The full source code of the objects, compiled when the application starts
- Native machine code that runs without any PowerBuilder runtime files
- Only the DataWindow objects, while all scripts go into the .exe
- The objects compiled to Pcode, without their source, executed by the PowerBuilder runtime
A .pbd holds Pcode (pseudocode) that the PowerBuilder virtual machine interprets; source is stripped. Even the machine-code option (.dll) still needs the PowerBuilder runtime files, so "runs without any runtime" is wrong for both. Nothing is compiled from source at startup.
You need a reusable object that holds business logic and has no visual interface. What do you create?
- A standard visual user object
- A custom class (nonvisual) user object
- A menu object
- A DataWindow object
Nonvisual (custom class) user objects — usually named n_... — encapsulate logic, variables and functions without a UI. Visual user objects are reusable controls; menus and DataWindow objects have specific purposes.
How is a menu object m_main attached to a window?
- By giving the menu the same name as the window
- Through the window's MenuName property
- By dragging m_main into the window's library
- By calling m_main.Attach(w_main)
A window's MenuName property (set in the Window painter) names its menu; at runtime ChangeMenu can switch to another one. Menus are not linked by name or library location.
The application object's Open event connects to the database but does not open any window. What happens when the event script finishes?
- The first window in the library list is opened automatically
- An empty default main window is shown
- The application ends, because no window is open
- The application keeps running invisibly until it is killed
A PowerBuilder application runs as long as it has windows. If the Open event of the application object finishes without opening one, the application terminates — which is why that script normally ends with Open(w_main).
You copy only app.exe and its .pbd files to a clean PC, and the program does not start. What is missing?
- The workspace (.pbw) and target (.pbt) files
- The .pbl source libraries
- The PowerBuilder runtime files (such as pbvm.dll) of the same version and build, plus the database driver
- The PowerBuilder IDE
Deployed PowerBuilder applications need the runtime DLLs (for example pbvm.dll and the database interface DLLs) matching the build used to compile them. Source libraries, targets and the IDE are not needed on user machines.
What does an incremental build of a target do, compared with a full build?
- It recompiles only objects that changed and the objects that depend on them
- It recompiles every object in every library
- It only checks syntax without producing compiled code
- It compiles only the object currently open in the painter
An incremental build regenerates changed objects plus their dependents, which is fast; a full build regenerates everything, which is needed e.g. after large ancestor changes or a migration. Neither is limited to the open object.
PowerScript syntax10
How do you write a single-line comment in PowerScript?
- -- this is a comment
- ' this is a comment
- // this is a comment
- # this is a comment
PowerScript uses // for a comment to the end of the line and /* ... */ for block comments. The other forms come from shell scripts, SQL and Visual Basic, and do not compile as comments in PowerScript.
Which character continues a PowerScript statement on the next line?
ls_sql = "SELECT emp_id, emp_name " + ?
"FROM employee"- +
- \
- &
- _
An ampersand at the end of a line tells the compiler that the statement continues. The underscore is Visual Basic's continuation character, and a trailing + alone (without &) leaves an incomplete statement on that line.
A window declares ii_count in its instance variables. Which statement describes ii_count?
// Declare Instance Variables of w_order
integer ii_count- Each open instance of w_order has its own ii_count, usable in all scripts of the window and its controls
- It is visible in every object of the application
- It exists only while the current event script is running
- All open instances of w_order share one ii_count
Instance variables belong to one object instance and live as long as that instance. A value shared by all instances is a shared variable; application-wide visibility is a global variable; a variable that disappears after the script is a local one.
What does the message box display?
integer li_count
string ls_name
MessageBox("Info", String(li_count) + "[" + ls_name + "]")- 0[]
- A runtime error: variable used before assignment
- -1[]
- An empty message, because both variables are NULL
PowerScript initializes declared variables to the default of their type: 0 for numbers, an empty string for strings, FALSE for booleans. Variables are never NULL unless you call SetNull or read a NULL from the database, so expecting NULL (as with uninitialized database columns) is the usual mistake.
What does IsNull(ls_c) return after this code?
string ls_a, ls_b, ls_c
ls_a = "x"
SetNull(ls_b)
ls_c = ls_a + ls_b- TRUE
- The concatenation raises a runtime error, so IsNull is never reached
- FALSE, and ls_c is an empty string
- FALSE, and ls_c is "x"
In PowerScript any expression containing a NULL operand evaluates to NULL, so the concatenation is NULL. Treating NULL as an empty string (as some languages do) is the classic mistake; this also means comparisons like ls_b = "" are neither TRUE nor FALSE — test with IsNull.
What is ls_r after this code?
integer li_n = 7
string ls_r
CHOOSE CASE li_n
CASE 1 TO 5
ls_r = "low"
CASE IS > 5
ls_r = "high"
CASE ELSE
ls_r = "other"
END CHOOSE- "" because CASE IS cannot compare with >
- "high"
- "low"
- "other"
CHOOSE CASE runs the first matching branch: 7 is not in 1 TO 5, but satisfies IS > 5. CASE IS with a relational operator is valid PowerScript; CASE ELSE runs only when no other branch matches.
How many times does the loop body run?
FOR li_i = 1 TO 10 STEP 2
li_count = li_count + 1
NEXT- 5
- 4
- 10
- 6
li_i takes the values 1, 3, 5, 7, 9; the next value, 11, is greater than 10, so the loop stops. The end value is inclusive, which is why 4 is wrong.
What is li_n after this code?
integer li_i = 10, li_n = 0
DO WHILE li_i < 5
li_n++
li_i++
LOOP
DO
li_n++
li_i++
LOOP UNTIL li_i > 5- 2
- 1
- The second loop never ends
- 0
DO WHILE tests before the body, so with li_i = 10 the first loop never runs. DO ... LOOP UNTIL tests after the body, so it always runs at least once: li_n becomes 1, li_i becomes 11, and the condition li_i > 5 ends the loop.
w_doc declares a shared variable si_opened and adds 1 to it in its Open event. Three instances of w_doc are opened one after another. What is si_opened in the third instance?
// Declare Shared Variables of w_doc
integer si_opened
// w_doc Open event
si_opened = si_opened + 1- 3
- 1
- It differs by instance: 1, 2 and 3 respectively, read at the same time
- 0
A shared variable belongs to the object class, not to an instance: all instances see the same variable, and it even keeps its value after instances are closed. An instance variable would give 1 in every window.
Which operator means "not equal" in PowerScript?
- ~=
- !=
- #
- <>
PowerScript uses <> for inequality and = for both assignment and equality comparison. != comes from C-family languages and does not compile in PowerScript.
Events and functions10
Which window event runs after the window is opened by Open() but before it is displayed, and is the usual place for initialization code?
- Activate
- Open
- Show
- Constructor
The Open event fires after the window is created and before it appears, so it is used to set up data and controls. Activate fires later, each time the window becomes active; Constructor is an event of controls and user objects, not of the window itself.
In what order are the three message boxes shown when cb_1 is clicked? (cb_2's Clicked event shows "3".)
// cb_1 Clicked event
MessageBox("Step", "1")
cb_2.PostEvent(Clicked!)
MessageBox("Step", "2")- 1, 3, 2
- 3, 1, 2
- 1, 2 — a posted event never runs while the window is open
- 1, 2, 3
PostEvent only queues the event; it runs after the current script finishes, so "3" comes last. The order 1, 3, 2 is what TriggerEvent would produce, because a triggered event runs immediately, synchronously, before the next line.
The descendant's Clicked script overrides the ancestor script. Which statement explicitly runs the ancestor's Clicked script from it?
- This.TriggerEvent("ancestor")
- Parent.Clicked()
- Ancestor::Clicked()
- CALL Super::Clicked
Super refers to the immediate ancestor, and CALL Super::eventname executes its script. Parent is the containing window, not the ancestor class, and there is no Ancestor pronoun; This.TriggerEvent would just run the descendant's own event again.
Window w_main contains a single-line edit sle_1. In which order do these scripts run when w_main is opened?
- sle_1 Constructor, then w_main Open
- The order is not defined and can change from run to run
- w_main Open, then sle_1 Constructor
- sle_1 Constructor runs only when sle_1 first receives focus
Controls are created as part of creating the window, and each control's Constructor event fires before the window's Open event. Assuming Open comes first and initializing controls there that a Constructor script then overwrites is a common source of confusion.
What is true about the return value of a function or event called with the POST keyword, e.g. This.EVENT POST ue_calc()?
- It is returned as usual, just after a short delay
- It is not available: the call is only queued and runs after the current script ends
- It is stored in Message.LongParm when the posted call finishes
- It is always 1 if the call was queued successfully
A posted call is placed in the message queue and executed later, after the calling script has finished, so there is nothing to return to the caller. If you need the result, use TRIGGER (the default) or have the posted code store the result somewhere itself.
cb_ok has no script in its Clicked event. What does this call return?
li_rc = cb_ok.TriggerEvent(Clicked!)- NULL
- 1
- 0
- -1
TriggerEvent returns 1 when the event script runs and -1 when the event is invalid for the object or has no script. Assuming 1 because the call itself "worked" is the typical mistake.
You want an event named ue_save on a window that other scripts can trigger. What is it called in PowerBuilder?
- A system event
- A global function
- A user event, defined on the window and optionally mapped to an event ID
- An external function
User events are events you declare yourself on an object (in the painter's event list); they can be mapped to a Windows message event ID (pbm_...) or left unmapped, and are invoked with EVENT ue_save() or TriggerEvent/PostEvent.
Which statement about object functions compared with events is true?
- Only events can take arguments
- Functions can be declared private or protected, while events are always public
- Functions run asynchronously, events synchronously
- Events can return values, functions cannot
Object functions have access levels (public, protected, private) and can be overloaded; events are always public. Both can take arguments and return values, and both can be triggered or posted.
What does a window's CloseQuery event script do if it returns 1?
- It closes the window without saving
- It closes all other windows too
- It shows the standard "Save changes?" dialog
- It prevents the window from closing
CloseQuery fires before a window closes; returning 1 cancels the close, returning 0 allows it. It is the usual place to ask about unsaved changes — PowerBuilder shows no dialog of its own.
Which line runs the Clicked event script of cb_save immediately, from another script?
- Clicked(cb_save)
- cb_save.Clicked()
- cb_save.TriggerEvent(Clicked!)
- cb_save.RunEvent("Clicked")
TriggerEvent (or the newer syntax cb_save.EVENT Clicked()) runs the event synchronously. cb_save.Clicked() would be a function call and fails because Clicked is an event, not a function.
Inheritance and objects10
What does visual inheritance let you do with a window w_base?
- Display w_base inside another window at runtime
- Share one running instance of w_base between several windows
- Create a descendant window that inherits its controls, properties and scripts, and then add to or change them
- Copy w_base into a new window that no longer depends on it
An inherited window keeps a live link to its ancestor: changes made to w_base later flow into every descendant. A plain copy (Save As) breaks that link, which is exactly what inheritance is meant to avoid.
A descendant window has a script in a button's Clicked event, and "Extend Ancestor Script" is checked (the default). What runs when the button is clicked?
- The descendant's script, then the ancestor's script
- The ancestor's script, then the descendant's script
- Only the descendant's script
- Only the ancestor's script, unless the descendant calls Super
Extending means the ancestor script runs first and the descendant code follows. "Only the descendant" is what Override Ancestor Script does; with override you must use CALL Super:: yourself if you still want the ancestor code.
In the Clicked event of a command button placed directly on a window, what does the pronoun Parent refer to?
- The button itself
- The application object
- The window that contains the button
- The ancestor of the button's class
For a control, Parent is the object that contains it — here the window, which is why Close(Parent) is the usual way to close a window from a button. The button itself is This, and the ancestor class is reached with Super.
In a menu item's Clicked script, which pronoun refers to the window that the menu is attached to?
- Super
- Parent
- This
- ParentWindow
ParentWindow is valid only in menu scripts and gives the window the menu belongs to. In a menu, Parent is the menu item one level up (e.g. the File item for File > Save), and This is the clicked item itself — using Parent there is the usual bug.
What does IsValid(lnv_b) return at the end of this script?
n_calc lnv_a, lnv_b
lnv_a = CREATE n_calc
lnv_b = lnv_a
DESTROY lnv_a- FALSE
- TRUE, because lnv_b holds its own copy of the object
- The assignment lnv_b = lnv_a does not compile for objects
- TRUE, until lnv_b goes out of scope
Object variables hold references: lnv_b = lnv_a makes both point to the same object, so destroying it through lnv_a leaves lnv_b pointing at a destroyed object, and IsValid returns FALSE. Thinking the assignment copies the object is the typical mistake.
A descendant event has "Override Ancestor Script" checked and its own script. What runs when the event fires?
- The ancestor script, then the descendant script
- Only the descendant script, unless it calls the ancestor with CALL Super::
- The descendant script, then the ancestor script
- Only the ancestor script
Override replaces the ancestor's script for this descendant; the ancestor code runs only if you call it explicitly. Ancestor-then-descendant is the behaviour of the default Extend option.
What happens on the second line of this script?
n_calc lnv_calc
ld_total = lnv_calc.of_sum(10, 20)- of_sum returns 0
- A runtime "null object reference" error, because the object was never created
- A compile error, because lnv_calc is not created
- of_sum runs normally with default instance variables
Declaring an object variable creates only a reference; for a normal nonvisual object you must instantiate it with lnv_calc = CREATE n_calc first. The compiler cannot know this, so it fails only at runtime.
In a control's event script, what does the pronoun This refer to?
- The window that contains the control
- The control whose script is running
- The ancestor of the control
- The application object
This is the object the script belongs to, e.g. This.Text = "Done" in a button's Clicked event changes that button. The containing window is Parent, and the ancestor is Super.
n_dog is inherited from n_animal, and both define of_speak(). Which version runs?
n_animal lnv_a
lnv_a = CREATE n_dog
ls_s = lnv_a.of_speak()- Both, ancestor first
- n_animal's of_speak, because the variable is declared as n_animal
- A compile error: the variable type does not match CREATE
- n_dog's of_speak, because the object is an n_dog
Object functions are resolved by the actual object at runtime (polymorphism). CREATE n_dog into an n_animal variable is valid because a descendant is an ancestor; expecting the declared type to decide is the usual mistake.
A nonvisual user object n_util has its AutoInstantiate property set. What changes in how you use it?
n_util lnv_util
ls_x = lnv_util.of_format(ld_value)- It is created once per application and shared by all variables
- It is created when the application starts, even if never declared
- It must still be created with CREATE, but DESTROY is automatic
- It is created automatically when the variable is declared and destroyed when it goes out of scope, so no CREATE or DESTROY is needed
Autoinstantiated objects behave like structures: the declaration itself creates the instance and leaving the scope destroys it. Without AutoInstantiate, the same code would fail with a null object reference.
DataWindow basics10
Which property of a DataWindow control specifies which DataWindow object it displays?
- DataSource
- DataObject
- SQLSelect
- DWObject
The DataWindow object (d_...) is designed in the DataWindow painter; the control (dw_...) on a window shows it through its DataObject property, set in the painter or in script (dw_1.DataObject = "d_customers"). Confusing the object and the control is the most common beginner mistake.
Before calling dw_1.Retrieve() on a DataWindow whose data source is SQL, what must the script do?
- Assign a connected transaction object, e.g. dw_1.SetTransObject(SQLCA)
- Call dw_1.Reset() to allocate the buffers
- Call dw_1.Update() to open the cursor
- Nothing; the control connects to SQLCA automatically
A DataWindow control does not know which connection to use until you give it one with SetTransObject (or SetTrans). Forgetting it makes Retrieve fail with -1 and a "transaction not connected" kind of error, even though SQLCA itself is connected.
dw_1.Retrieve() returns 0. What does that mean?
- The retrieval failed because of a database error
- The retrieval succeeded but no rows matched
- The DataWindow has no transaction object
- The retrieval was cancelled by the user
Retrieve returns the number of rows retrieved, or -1 if it fails. 0 is a normal, successful result with an empty result set; treating it as an error is a frequent mistake.
What is the difference between dw_1.SetTransObject(SQLCA) and dw_1.SetTrans(SQLCA)?
- SetTransObject works only for Retrieve, SetTrans only for Update
- They are identical; SetTrans is just the older name
- SetTransObject uses your connected transaction object as is; SetTrans copies its values into an internal one and the DataWindow connects and disconnects on each Retrieve or Update
- SetTrans uses your connection; SetTransObject opens a new private connection
With SetTransObject you control the connection and the transaction (COMMIT/ROLLBACK), which is efficient and lets several DataWindows share one unit of work. SetTrans makes the DataWindow do its own CONNECT/COMMIT/DISCONNECT for every database call — simpler but slow, and you cannot group updates in one transaction.
Which DataWindow presentation style shows rows and columns with grid lines, and lets the user resize and reorder columns at runtime, like a spreadsheet?
- Freeform
- Composite
- Grid
- Label
Grid style is the spreadsheet-like layout. Freeform shows one row as a form, Label prints mailing labels, and Composite only combines several other DataWindow objects in one report.
The DataWindow's SQL has a retrieval argument :as_state used in its WHERE clause. How do you pass the value "CA" to it?
- dw_1.Retrieve("CA")
- dw_1.Object.as_state = "CA"
- dw_1.Retrieve(as_state = "CA")
- dw_1.SetArgument("as_state", "CA")
Retrieval arguments are passed positionally to Retrieve, in the order they are defined in the DataWindow object. Calling Retrieve without them makes PowerBuilder prompt the user for the values.
Which SQL statements does dw_1.Update() send for an updatable DataWindow?
- Only UPDATE statements; inserts need embedded SQL
- INSERT for new modified rows, UPDATE for modified retrieved rows, DELETE for retrieved rows in the Delete buffer
- DELETE of all rows followed by INSERT of the current rows
- One UPDATE for every row in the Primary buffer
Update looks at row and column status flags and generates only the necessary statements, using the update table and key columns set in Update Properties. Rows that were never changed produce no SQL at all.
Which DataWindow data source do you choose when the data does not come from a database and the script fills the rows itself?
- Quick Select
- External
- Query
- Stored Procedure
An External DataWindow defines only the columns; rows are added with InsertRow/SetItem or ImportString/ImportFile. The other data sources all retrieve from a database.
What does dw_1.Reset() do?
- Deletes all rows from the database table
- Removes all rows from all buffers without changing the database
- Undoes changes since the last Update
- Re-executes the last Retrieve
Reset clears the Primary, Filter and Delete buffers on the client only. Nothing is sent to the database, and there is no undo-to-last-update; re-reading data needs another Retrieve.
A DataWindow's SQL joins the orders and customers tables. What can dw_1.Update() do with it?
- Nothing; joined DataWindows can never be updated
- Update whichever table has more modified columns
- Update both tables automatically in one call
- Update one table at a time — the one set in Update Properties; for the other you change the update settings with Modify and call Update again
A DataWindow updates a single table, chosen with its key and updatable columns in Update Properties. To update a second table, scripts switch Table.UpdateTable and the column update settings with Modify and call Update again (usually with resetflag FALSE until all succeed).
DataWindow programming10
Which line is equivalent to ls_name = dw_1.GetItemString(5, "emp_name")?
- ls_name = dw_1.Object.emp_name[5]
- ls_name = dw_1.emp_name[5]
- ls_name = dw_1.Object[5].emp_name
- ls_name = dw_1.GetItem(5).emp_name
DataWindow dot notation goes through the Object property: dw_1.Object.column[row]. Leaving out .Object (dw_1.emp_name) makes PowerBuilder look for a property of the control itself; the row index belongs after the column name, not after Object.
A row that was retrieved from the database is removed with dw_1.DeleteRow(3). Where does it go?
- To the Filter buffer
- To the Delete buffer, so the next Update generates a DELETE for it
- It is discarded at once and cannot affect the database
- It stays in the Primary buffer, marked as deleted
A DataWindow has Primary, Filter, Delete and Original buffers. DeleteRow moves the row from Primary to Delete; Update then sends a DELETE statement. Thinking the row is simply gone, so nothing happens in the database, is the typical misunderstanding.
dw_1 holds 10 rows; 4 of them have status = 'A'. What is ll_rows?
dw_1.SetFilter("status = 'A'")
dw_1.Filter()
ll_rows = dw_1.RowCount()- 6
- 10
- 0, because SetFilter must be called after Filter
- 4
Filter moves rows that do not match into the Filter buffer, and RowCount counts only the Primary buffer, so it returns 4 (FilteredCount would return 6). SetFilter only sets the expression; Filter applies it, so the order shown is the correct one.
In a DataWindow's ItemChanged event, which return value rejects the new value and keeps the focus in the column?
- RETURN 2
- RETURN -1
- RETURN 1
- RETURN 0
ItemChanged return codes: 0 (default) accepts the value, 1 rejects it and does not let the focus change, 2 rejects it but lets the focus move on. Using RETURN 0 to "stop" the change is the usual mistake — 0 means accept.
In dw_1's ItemChanged event for column emp_name, what does this line return?
ls_value = This.GetItemString(row, "emp_name")- An empty string until the event finishes
- The new value the user just typed
- NULL, because the column is being edited
- The old value; the new value is in the event's data argument
ItemChanged fires before the new value is written to the buffer, so GetItemString still returns the previous value. Validate the data argument instead — reading the buffer and expecting the new value is a classic bug.
What is the row status after this code?
ll_row = dw_1.InsertRow(0)
dw_1.SetItem(ll_row, "emp_name", "Ann")
ls_status = String(dw_1.GetItemStatus(ll_row, 0, Primary!))- NewModified!
- NotModified!
- DataModified!
- New!
InsertRow creates a row with status New!; once a value is set it becomes NewModified!, and only such rows produce an INSERT on Update. DataModified! is for retrieved rows that were changed, NotModified! for retrieved rows left untouched.
After dw_1.SetSort("salary D") the rows on screen stay in the same order. What is missing?
- A call to dw_1.Filter()
- A call to dw_1.Retrieve()
- A call to dw_1.Sort()
- Nothing; "D" means "default order"
SetSort only defines the sort criteria ("D" means descending, "A" ascending); Sort() applies them. It is the same two-step pattern as SetFilter/Filter.
Two DataWindows must be saved in one transaction. Why is the first Update called with resetflag FALSE?
IF dw_order.Update(TRUE, FALSE) = 1 THEN
IF dw_items.Update(TRUE, FALSE) = 1 THEN
dw_order.ResetUpdate()
dw_items.ResetUpdate()
COMMIT USING SQLCA;
ELSE
ROLLBACK USING SQLCA;
END IF
ELSE
ROLLBACK USING SQLCA;
END IF- So dw_order keeps its row status flags if dw_items fails and the transaction is rolled back
- So the DataWindow re-retrieves its rows after updating
- So AcceptText is skipped for speed
- So the changes are committed immediately
By default Update resets the status flags after success. If the second Update then fails and you roll back, dw_order would "forget" its changes and a retry would send nothing. Passing FALSE and calling ResetUpdate only after COMMIT keeps the flags consistent with the database.
In a DataWindow's ItemError event, which return value rejects the invalid value without showing PowerBuilder's default error message box?
- RETURN 0
- RETURN 2
- RETURN 1
- RETURN 3
ItemError codes: 0 (default) rejects the value and shows the default message, 1 rejects it silently (typically after your own message), 2 accepts the value, 3 rejects it but lets the focus change. Confusing these with ItemChanged's codes is common.
A user types a new name into dw_1 and clicks a toolbar button whose script calls dw_1.GetItemString(1, "emp_name"). The old name is returned. Why?
- The row must be re-retrieved after each change
- GetItemString always returns the value as originally retrieved
- The typed text is still in the edit control; call dw_1.AcceptText() first to validate and store it
- Toolbar clicks run before the keyboard input is processed
Until the user leaves the column or AcceptText is called, the new value lives only in the DataWindow's edit control, not in the buffer. Toolbar items do not take focus, so the column is never left; Update(TRUE) calls AcceptText for you, but GetItem functions do not.
Database and transactions10
What is SQLCA in a PowerBuilder application?
- The DataWindow that stores query results
- A system function that runs SQL strings
- The default global transaction object used for database connections
- The name of the database driver DLL
SQLCA (SQL Communications Area) is a global variable of type Transaction created automatically. You set its connection properties, CONNECT USING SQLCA, and then pass it to DataWindows with SetTransObject and to embedded SQL.
After an embedded SELECT ... INTO statement, SQLCA.SQLCode is 100. What does it mean?
- A database error occurred
- The statement succeeded and returned exactly one row
- 100 rows were found
- No row was found
SQLCode is 0 for success, 100 for "not found" and -1 for an error. Checking only for -1 and treating 100 as success leaves the INTO variables unchanged and is a common bug.
An embedded SQL statement fails and SQLCA.SQLCode is -1. Which property holds the database's error message?
- SQLCA.SQLMessage
- SQLCA.SQLErrText
- SQLCA.ErrorMessage
- SQLCA.LastError
The Transaction object exposes SQLCode (PowerBuilder's 0/100/-1), SQLDBCode (the DBMS-specific error number) and SQLErrText (the DBMS message). The other names do not exist on the Transaction object.
Why are emp_name and ll_id written with a colon in this embedded SQL?
SELECT emp_name INTO :ls_name
FROM employee
WHERE emp_id = :ll_id
USING SQLCA;- The colon marks PowerScript variables (host variables) inside the SQL statement
- The colon is needed only for string variables
- The colon tells the database to bind them as output parameters only
- The colon makes the parameters optional
In embedded SQL, PowerScript variables are prefixed with a colon so the compiler can tell them from column names, both in INTO and in WHERE. Note that embedded SQL statements also end with a semicolon, unlike ordinary PowerScript lines.
This singleton SELECT matches three rows in the table. What is SQLCA.SQLCode afterwards?
SELECT emp_name INTO :ls_name
FROM employee
WHERE dept_id = 10
USING SQLCA;- -1, because a singleton SELECT returned more than one row
- 0, and ls_name holds the first row
- 0, and ls_name holds the last row
- 100, because no single row could be chosen
SELECT ... INTO must return at most one row; more than one is an error (-1), with the reason in SQLErrText. Expecting the first row to be taken silently is the typical mistake; use a cursor or a DataWindow to process several rows.
Which property of a Transaction object names the database interface to use, for example "ODBC"?
- DBMS
- Database
- ServerName
- DBParm
DBMS selects the PowerBuilder database interface (driver). Database and ServerName identify where to connect, and DBParm carries interface-specific options such as an ODBC connect string.
With SQLCA.AutoCommit = FALSE (the default) and dw_1 using SetTransObject(SQLCA), why is COMMIT needed here?
IF dw_1.Update() = 1 THEN
COMMIT USING SQLCA;
ELSE
ROLLBACK USING SQLCA;
END IF- COMMIT re-reads the saved rows into dw_1
- It is not needed; Update commits automatically when it returns 1
- COMMIT is needed only for Oracle databases
- Update only sends the SQL inside the open transaction; it does not commit it
With SetTransObject, you own the transaction: Update executes INSERT/UPDATE/DELETE but leaves committing or rolling back to your script. Assuming Update commits by itself leads to locks being held and changes lost on rollback.
A cursor loop reads rows with FETCH. Which condition keeps the loop running while rows remain?
DECLARE c_emp CURSOR FOR
SELECT emp_name FROM employee USING SQLCA;
OPEN c_emp;
FETCH c_emp INTO :ls_name;
DO WHILE ?
// process ls_name
FETCH c_emp INTO :ls_name;
LOOP
CLOSE c_emp;- SQLCA.SQLCode = 100
- NOT IsNull(ls_name)
- SQLCA.SQLCode <> 100
- SQLCA.SQLCode = 0
FETCH sets SQLCode to 0 when a row was read, 100 when there are no more rows, and -1 on error. Looping on <> 100 would loop forever on a database error (-1), and testing ls_name fails when a column really is NULL.
SQLCA.AutoCommit is TRUE. A script runs two UPDATE statements and then ROLLBACK USING SQLCA. What happens to the updates?
- They stay in the database: each statement was committed as soon as it ran
- Only the second UPDATE is undone
- The ROLLBACK raises a runtime error and closes the connection
- Both are undone by the ROLLBACK
With AutoCommit TRUE every statement is committed immediately, so there is no open transaction left to roll back. Multi-statement units of work (like a DataWindow update of several rows) need AutoCommit FALSE plus explicit COMMIT/ROLLBACK.
The application needs a second database connection alongside SQLCA. What do you do?
- Set SQLCA.DBParm to list both databases
- Call CONNECT USING SQLCA a second time with new properties
- Create another Transaction object (CREATE transaction), set its properties and CONNECT USING it
- Copy SQLCA into a structure and connect the structure
Each connection needs its own Transaction object: ltr_report = CREATE transaction, set DBMS etc., CONNECT USING ltr_report, pass it to SetTransObject, and DISCONNECT and DESTROY it at the end. SQLCA can hold only one connection.
Windows and controls10
Which window type is application-modal, so the user must close it before working in any other window of the application?
- Response
- Main
- Child
- Popup
A response window (dialog) blocks the rest of the application until it is closed, and the script that opened it waits at the Open call. Main, child and popup windows are all modeless.
How does w_detail read the value "ABC" passed by this call?
OpenWithParm(w_detail, "ABC")- w_detail.Parm property
- The first argument of w_detail's Open event
- Message.DoubleParm in w_detail's Open event
- Message.StringParm in w_detail's Open event
OpenWithParm stores the parameter in the global Message object: strings in Message.StringParm, numbers in Message.DoubleParm, objects and structures in Message.PowerObjectParm. The window's Open event has no argument for it.
A response window closes itself with CloseWithReturn(Parent, "OK"). Where does the calling script find "OK" after its Open(w_confirm) call returns?
- In Message.StringParm
- In w_confirm.ReturnValue
- In a global variable created automatically by CloseWithReturn
- In the return value of Open
CloseWithReturn closes the window and puts the value into the Message object; because the response window is modal, the caller continues right after Open and reads Message.StringParm there. Open itself returns only 1 or -1 (success/failure).
In an MDI application, which call opens w_doc as a sheet inside the frame w_frame?
- OpenChild(w_doc, w_frame)
- OpenSheet(w_doc, w_frame)
- Open(w_doc, MDI!)
- w_frame.AddSheet(w_doc)
Sheets are opened with OpenSheet (or OpenSheetWithParm), passing the MDI frame. The other forms do not exist; opening a sheet with plain Open would create a normal window outside the frame's client area.
Why should a window copy Message.StringParm into an instance variable at the very start of its Open event?
- Message.StringParm is cleared automatically when the Open event ends
- Message is one global object, and later events or OpenWithParm calls can overwrite it
- Message.StringParm can be read only once
- Instance variables are faster to read than Message properties
There is a single Message object for the whole application. Any other window opened, closed with a return value, or event that uses it can replace StringParm, so the documented practice is to save the value immediately.
Which statement in a command button's Clicked event closes the window that contains the button?
- Close(Parent)
- Parent.Hide()
- DESTROY Parent
- Close(This)
Close takes a window; Parent in a control's script is the containing window. This is the button itself, so Close(This) does not compile, and Hide only makes the window invisible without closing it.
In an MDI application, a frame toolbar item "Save" must act on the sheet the user is working in. Which function returns that sheet?
- w_frame.GetFocus()
- w_frame.GetActiveSheet()
- w_frame.ActiveSheet()
- w_frame.GetCurrentWindow()
GetActiveSheet returns the active sheet of an MDI frame (or an invalid reference if no sheet is open, so check it with IsValid). GetFocus returns the control that has focus, which may not even be a window.
The script calls Open(w_doc) twice in a row. How many w_doc windows are open afterwards?
- One — the second Open just activates the existing window
- None — the second call closes the first
- One, and the second call raises a runtime error
- Two independent instances
Opening a window by its class name reuses the global instance; if it is already open it is activated. To get several instances, declare variables of the window type (w_doc lw_doc) and call Open(lw_doc) for each.
OpenWithParm(w_edit, lstr_param) passes a structure lstr_param. How does w_edit read it in its Open event?
- lstr_param = Message.StructureParm
- lstr_param = Message.DoubleParm
- lstr_param = Message.StringParm
- lstr_param = Message.PowerObjectParm
Structures and objects arrive in Message.PowerObjectParm (assigned to a variable of the right structure type); strings use StringParm and numbers DoubleParm. There is no StructureParm property.
Which statement about a child window is true?
- It is modal and blocks the rest of the application
- It is the only window type that can have its own menu
- It can be moved anywhere on the desktop
- It stays inside its parent window's area and moves with the parent
A child window is clipped to its parent and moves with it; it cannot have a menu and is never the active window. A popup window can move outside its parent, and a response window is the modal one.
Error handling and debugging10
What does li_ret contain if the user clicks No?
li_ret = MessageBox("Save", "Save changes?", Question!, YesNo!)- 0
- 2
- FALSE
- -1
MessageBox returns the number of the button pressed: with YesNo! that is 1 for Yes and 2 for No (with YesNoCancel!, Cancel is 3). It returns an integer, not a boolean, so testing for 0 or FALSE never matches.
What is ls_log after this code, if of_load() throws a RuntimeError?
ls_log = ""
TRY
ls_log += "A"
lnv_loader.of_load()
ls_log += "B"
CATCH (RuntimeError e)
ls_log += "C"
FINALLY
ls_log += "D"
END TRY- ACB
- ACD
- AC
- ABCD
After the exception the rest of the TRY block ("B") is skipped, the matching CATCH runs, and FINALLY always runs at the end. Forgetting that FINALLY still runs after a handled exception gives "AC".
Which object's event runs when a runtime error (such as a null object reference) is not caught by any TRY/CATCH?
- The DataWindow's DBError event
- The application object's SystemError event
- The Close event of the current window
- The active window's Error event
Unhandled runtime errors trigger SystemError on the application object, where the global Error object describes the problem. DataWindows have their own Error and DBError events, but those are for DataWindow expression and database errors, not general script errors.
In the PowerBuilder debugger, how do you make execution stop at a particular line of a script?
- Compile the target with a Full Build
- Add the keyword STOP at that line
- Add a MessageBox call; the debugger stops at every MessageBox
- Set a breakpoint on that line and run the application in debug mode
Breakpoints are set by double-clicking a line in the debugger's source view (or with the context menu); when you run in debug mode execution pauses there, and you can inspect variables and step through. PowerScript has no STOP statement.
You create n_ex_invalid inherited from Exception and THROW it inside of_load() without catching it there. What else should be done?
- Wrap the THROW in a FINALLY block
- Nothing; any exception can be thrown without declaration
- Inherit n_ex_invalid from Throwable instead
- Declare n_ex_invalid in the Throws clause of of_load's prototype
Exceptions that do not descend from RuntimeError must be declared in the method's THROWS clause when the method does not handle them itself — like checked exceptions in Java. RuntimeError descendants need no declaration, which is why "nothing needed" is a tempting but wrong answer here.
In the application's SystemError event, which global object holds the error number, text, object and line of the runtime error?
- Error
- Exception
- Message
- SQLCA
The global Error object has properties such as Number, Text, Object, ObjectEvent and Line, filled in for SystemError. Message is for passing parameters between windows, and SQLCA for database results.
lnv_obj was declared but never created. What is ls after this code?
TRY
lnv_obj.of_run()
CATCH (NullObjectError e1)
ls = "null"
CATCH (RuntimeError e2)
ls = "runtime"
END TRY- "null"
- "nullruntime"
- "runtime"
- An empty string, because SystemError handles it
Calling a function on an uncreated object throws NullObjectError, a descendant of RuntimeError. CATCH clauses are tested in order and only the first match runs, so put specific exception types before their ancestors.
Why do many SystemError event scripts end with HALT CLOSE?
- HALT CLOSE is needed to write the error to the Windows event log
- HALT CLOSE restarts the application automatically
- Once SystemError has a script, PowerBuilder no longer stops the application itself, so the script must end it if continuing is unsafe
- Without it, SystemError runs in an endless loop
With no SystemError script, PowerBuilder shows a default error box and ends the application. When you write a script, control returns after it and the application keeps running in a possibly broken state; HALT CLOSE runs the application's Close event and ends it cleanly.
The user clicks Cancel. What is li_ret?
li_ret = MessageBox("Exit", "Save changes before closing?", &
Question!, YesNoCancel!, 2)- 3
- 0
- -1
- 2
With YesNoCancel! the buttons are numbered Yes = 1, No = 2, Cancel = 3. The last argument (2) only sets the default button to No; it does not change the return value of Cancel.
You are paused in the debugger inside a function and want to run the rest of it and stop back in the calling script. Which command do you use?
- Step In
- Start
- Step Out
- Step Over
Step Out finishes the current function or event and pauses at the caller. Step In enters the next called function, Step Over runs the next line without entering calls, and Start/Continue runs until the next breakpoint.
Modern PowerBuilder10
Which company originally created PowerBuilder, releasing version 1.0 in the early 1990s?
- SAP
- Sybase
- Appeon
- Powersoft
PowerBuilder was created by Powersoft (version 1.0 in 1991). Sybase bought Powersoft in 1995, SAP acquired Sybase in 2010, and Appeon took over development of PowerBuilder in 2016.
Which company develops new versions of PowerBuilder (PowerBuilder 2017 and later)?
- Embarcadero
- Microsoft
- Appeon
- Oracle
Since 2016 Appeon develops and sells PowerBuilder under an agreement with SAP; PowerBuilder 2017 was its first release. Embarcadero makes Delphi, a similar-era RAD tool, which is the usual mix-up.
What does Appeon PowerServer do for a PowerBuilder client/server application?
- Replaces the DataWindow with Java Swing tables
- Runs the unchanged client/server .exe on a terminal server
- Deploys it as an installable cloud app whose data access runs through a C#/.NET Web API on a server
- Converts the application into a static HTML website
PowerServer turns an existing PowerBuilder app into a cloud architecture: the client is installed from a URL and runs natively, while DataWindow retrieves/updates and embedded SQL are executed by an automatically generated .NET Web API, so the client no longer needs database drivers or a direct database connection.
Which RESTClient function retrieves JSON from a web service URL straight into a DataWindow?
- dw_1.Retrieve(ls_url)
- dw_1.ImportJson(ls_url)
- lnv_client.Retrieve(dw_1, ls_url)
- lnv_client.SendGetRequest(dw_1, ls_url)
RESTClient.Retrieve(dwcontrol, url) calls the service and loads the JSON response into the DataWindow, mapping keys to columns. dw_1.Retrieve takes retrieval arguments, not a URL, and ImportJson expects a JSON string, not an address.
Why does the "solution" format introduced in PowerBuilder 2022 work better with Git than the classic workspace with .pbl files?
- Each object's source is stored as a separate text file in folders instead of inside binary .pbl files
- It stores the whole application in one large XML file
- It compiles objects into .NET assemblies that Git can diff
- It keeps source code in a database table instead of files
Classic .pbl libraries are binary containers, so source control needed export/import tricks. In a solution, objects are plain text source files (.srw, .sru, .srd ...), so Git can track, diff and merge them directly.
Which was the first PowerBuilder version released by Appeon?
- PowerBuilder 2019
- PowerBuilder 12.6
- PowerBuilder 2017
- PowerBuilder 10
PowerBuilder 12.6 was the last release under SAP/Sybase; Appeon's first was PowerBuilder 2017, followed by 2017 R2/R3, 2019, 2021, 2022 and later. The year-based naming started with Appeon.
When does JSONParser.LoadString(ls_json) indicate success?
- When it returns the root item handle
- When it returns TRUE
- When it returns an empty string; otherwise it returns the error message
- When it returns 1
LoadString returns "" on success and an error description if the JSON is invalid. After that you get the root with GetRootItem() and read values with functions like GetItemString(handle, key). Checking for 1 or TRUE, as with many other functions, is the trap.
After lnv_http.SendRequest("GET", ls_url) succeeds, how do you get the response text from an HTTPClient object?
- ls_body = lnv_http.Response
- ls_body = lnv_http.ReadAll()
- ls_body = Message.StringParm
- lnv_http.GetResponseBody(ls_body)
HTTPClient fills the body into a string passed by reference with GetResponseBody, and GetResponseStatusCode() gives the HTTP status (check for 200). The other members do not exist.
Which DataWindow function (PowerBuilder 2017 R2 and later) returns the DataWindow's data as a JSON string?
- GenerateJson()
- GetJson()
- ToJson()
- ExportJson()
ExportJson serializes the DataWindow data as JSON (options control which buffers and format), and ImportJson loads JSON back into it — useful with HTTPClient and RESTClient.
Which PowerScript objects (PowerBuilder 2019 R2 and later) let you load a .NET assembly and call methods of its classes directly?
- OLEObject and OLECustomControl
- DotNetAssembly and DotNetObject
- RESTClient and JSONParser
- ConnectionObject and Proxy
DotNetAssembly loads the assembly and DotNetObject represents an instance of a .NET class whose methods you call from PowerScript. OLEObject is the older COM route, which required a COM-visible wrapper; RESTClient and JSONParser are for web services.
Как проходить тест
- Выберите темы и уровень — лёгкий уровень проверяет определения и задачи в одно действие, средний — стандартные вычисления, сложный — многошаговые задачи и теорию.
- Отвечайте касанием или с клавиатуры: 1–4 или A–D, Enter — следующий вопрос.
- Читайте объяснения — после ошибки разбор открывается сразу, после верного ответа его можно раскрыть кнопкой «Почему».
- Работайте над ошибками — «Повторить ошибки» в конце теста или режим «Только мои ошибки» потом: ответы запоминаются в этом браузере.
Незавершённый тест сохраняется — после перезагрузки страницы можно продолжить с того же вопроса.
Темы теста
- PowerBuilder basics 10
- PowerScript syntax 10
- Events and functions 10
- Inheritance and objects 10
- DataWindow basics 10
- DataWindow programming 10
- Database and transactions 10
- Windows and controls 10
- Error handling and debugging 10
- Modern PowerBuilder 10
Другие тесты
Тест по линейной алгебре160 вопросовТест по дифференциальным уравнениям130 вопросовТест по теории вероятностей и статистике130 вопросовТест по SAS100 вопросовТест по языку R100 вопросовТест по LaTeX100 вопросовТест по системам компьютерной алгебры100 вопросовТест по Fortran120 вопросовТест по языку C100 вопросовТест по COBOL100 вопросовТест по MATLAB100 вопросовТест по UNIX100 вопросов
