Saturday, February 2, 2019

1. What is normalization? Explain different levels of normalization?
Check out the article Q100139 from Microsoft knowledge base and of
course, there's much more information available in the net. It'll be a
good idea to get a hold of any RDBMS fundamentals text book,
especially the one by C. J. Date. Most of the times, it will be okay
if you can explain till third normal form.
 2. What is denormalization and when would you go for it?
 As the name indicates, denormalization is the reverse process of
normalization. It's the controlled introduction of redundancy in to
the database design. It helps improve the query performance as the
number of joins could be reduced.
 3. How do you implement one-to-one, one-to-many and many-to-many
relationships while designing tables?
 One-to-One relationship can be implemented as a single table and
rarely as two tables with primary and foreign key relationships.
One-to-Many relationships are implemented by splitting the data into
two tables with primary key and foreign key relationships.
Many-to-Many relationships are implemented using a junction table with
the keys from both the tables forming the composite primary key of the
junction table.
 
It will be a good idea to read up a database designing fundamentals
text book.
 4. What's the difference between a primary key and a unique key?
 Both primary key and unique enforce uniqueness of the column on which
they are defined. But by default primary key creates a clustered index
on the column, where are unique creates a nonclustered index by
default. Another major difference is that, primary key doesn't allow
NULLs, but unique key allows one NULL only.
 5. What are user defined datatypes and when you should go for them?
 User defined datatypes let you extend the base SQL Server datatypes by
providing a descriptive name, and format to the database. Take for
example, in your database, there is a column called Flight_Num which
appears in many tables. In all these tables it should be varchar(8).
In this case you could create a user defined datatype called
Flight_num_type of varchar(8) and use it across all your tables.
 
See sp_addtype, sp_droptype in books online.
 5. What is bit datatype and what's the information that can be stored
inside a bit column?
 Bit datatype is used to store boolean information like 1 or 0 (true or
false). Untill SQL Server 6.5 bit datatype could hold either a 1 or 0
and there was no support for NULL. But from SQL Server 7.0 onwards,
bit datatype can represent a third state, which is NULL.
 6. Define candidate key, alternate key, composite key.
 A candidate key is one that can identify each row of a table uniquely.
Generally a candidate key becomes the primary key of the table. If the
table has more than one candidate key, one of them will become the
primary key, and the rest are called alternate keys.
 
A key formed by combining at least two or more columns is called
composite key.
 7. What are defaults? Is there a column to which a default can't be bound?
 A default is a value that will be used by a column, if no value is
supplied to that column while inserting data. IDENTITY columns and
timestamp columns can't have defaults bound to them. See CREATE
DEFUALT in books online.
 
Back to top
SQL Server architecture       (top)
 
8. What is a transaction and what are ACID properties?
 
A transaction is a logical unit of work in which, all the steps must
be performed or none. ACID stands for Atomicity, Consistency,
Isolation, Durability. These are the properties of a transaction. For
more information and explanation of these properties, see SQL Server
books online or any RDBMS fundamentals text book.
 
Explain different isolation levels
 
An isolation level determines the degree of isolation of data between
concurrent transactions. The default SQL Server isolation level is
Read Committed. Here are the other isolation levels (in the ascending
order of isolation): Read Uncommitted, Read Committed, Repeatable
Read, Serializable. See SQL Server books online for an explanation of
the isolation levels. Be sure to read about SET TRANSACTION ISOLATION
LEVEL, which lets you customize the isolation level at the connection
level.
 
CREATE INDEX myIndex ON myTable(myColumn)
 
9. What type of Index will get created after executing the above statement?
 
Non-clustered index. Important thing to note: By default a clustered
index gets created on the primary key, unless specified otherwise.
 
What's the maximum size of a row?
 
8060 bytes. Don't be surprised with questions like 'what is the
maximum number of columns per table'. Check out SQL Server books
online for the page titled: "Maximum Capacity Specifications".
 
10. Explain Active/Active and Active/Passive cluster configurations
 
Hopefully you have experience setting up cluster servers. But if you
don't, at least be familiar with the way clustering works and the two
clusterning configurations Active/Active and Active/Passive. SQL
Server books online has enough information on this topic and there is
a good white paper available on Microsoft site.
 
11. Explain the architecture of SQL Server
 
This is a very important question and you better be able to answer it
if consider yourself a DBA. SQL Server books online is the best place
to read about SQL Server architecture. Read up the chapter dedicated
to SQL Server Architecture.
 
12. What is lock escalation?
 
Lock escalation is the process of converting a lot of low level locks
(like row locks, page locks) into higher level locks (like table
locks). Every lock is a memory structure too many locks would mean,
more memory being occupied by locks. To prevent this from happening,
SQL Server escalates the many fine-grain locks to fewer coarse-grain
locks. Lock escalation threshold was definable in SQL Server 6.5, but
from SQL Server 7.0 onwards it's dynamically managed by SQL Server.
 
13. What's the difference between DELETE TABLE and TRUNCATE TABLE commands?
 
DELETE TABLE is a logged operation, so the deletion of each row gets
logged in the transaction log, which makes it slow. TRUNCATE TABLE
also deletes all the rows in a table, but it won't log the deletion of
each row, instead it logs the deallocation of the data pages of the
table, which makes it faster. Of course, TRUNCATE TABLE can be rolled
back.
 
14. Explain the storage models of OLAP
 
Check out MOLAP, ROLAP and HOLAP in SQL Server books online for more
infomation.
 
15. What are the new features introduced in SQL Server 2000 (or the latest
release of SQL Server at the time of your interview)? What changed
between the previous version of SQL Server and the current version?
 
This question is generally asked to see how current is your knowledge.
Generally there is a section in the beginning of the books online
titled "What's New", which has all such information. Of course,
reading just that is not enough, you should have tried those things to
better answer the questions. Also check out the section titled
"Backward Compatibility" in books online which talks about the changes
that have taken place in the new version.
 
16. What are constraints? Explain different types of constraints.
 
Constraints enable the RDBMS enforce the integrity of the database
automatically, without needing you to create triggers, rule or defaults.
 
Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY
 
For an explanation of these constraints see books online for the pages
titled: "Constraints" and "CREATE TABLE", "ALTER TABLE"
 
17.  Whar is an index? What are the types of indexes? How many clustered
indexes can be created on a table? I create a separate index on each
column of a table. what are the advantages and disadvantages of this
approach?
 
Indexes in SQL Server are similar to the indexes in books. They help
SQL Server retrieve the data quicker.
 
Indexes are of two types. Clustered indexes and non-clustered indexes.
When you craete a clustered index on a table, all the rows in the
table are stored in the order of the clustered index key. So, there
can be only one clustered index per table. Non-clustered indexes have
their own storage separate from the table data storage. Non-clustered
indexes are stored as B-tree structures (so do clustered indexes),
with the leaf level nodes having the index key and it's row locater.
The row located could be the RID or the Clustered index key, depending
up on the absence or presence of clustered index on the table.
 
If you create an index on each column of a table, it improves the
query performance, as the query optimizer can choose from all the
existing indexes to come up with an efficient execution plan. At the
same t ime, data modification operations (such as INSERT, UPDATE,
DELETE) will become slow, as every time data changes in the table, all
the indexes need to be updated. Another disadvantage is that, indexes
need disk space, the more indexes you have, more disk space is used.
 
Back to top
Database administration       (top)
 
18. What is RAID and what are different types of RAID configurations?
 
RAID stands for Redundant Array of Inexpensive Disks, used to provide
fault tolerance to database servers. There are six RAID levels 0
through 5 offering different levels of performance, fault tolerance.
MSDN has some information about RAID levels and for detailed
information, check out the RAID advisory board's homepage
 
19. What are the steps you will take to improve performance of a poor
performing query?
 
This is a very open ended question and there could be a lot of reasons
behind the poor performance of a query. But some general issues that
you could talk about would be: No indexes, table scans, missing or out
of date statistics, blocking, excess recompilations of stored
procedures, procedures and triggers without SET NOCOUNT ON, poorly
written query with unnecessarily complicated joins, too much
normalization, excess usage of cursors and temporary tables.
 
Some of the tools/ways that help you troubleshooting performance
problems are: SET SHOWPLAN_ALL ON, SET SHOWPLAN_TEXT ON, SET
STATISTICS IO ON, SQL Server Profiler, Windows NT /2000 Performance
monitor, Graphical execution plan in Query Analyzer.
 
Download the white paper on performance tuning SQL Server from
Microsoft web site. Don't forget to check out sql-server-performance.com
 
20. What are the steps you will take, if you are tasked with securing an
SQL Server?
 
Again this is another open ended question. Here are some things you
could talk about: Preferring NT authentication, using server, databse
and application roles to control access to the data, securing the
physical database files using NTFS permissions, using an unguessable
SA password, restricting physical access to the SQL Server, renaming
the Administrator account on the SQL Server computer, disabling the
Guest account, enabling auditing, using multiprotocol encryption,
setting up SSL, setting up firewalls, isolating SQL Server from the
web server etc.
 
Read the white paper on SQL Server security from Microsoft website.
Also check out My SQL Server security best practices
 
21. What is a deadlock and what is a live lock? How will you go about
resolving deadlocks?
 
Deadlock is a situation when two processes, each having a lock on one
piece of data, attempt to acquire a lock on the other's piece. Each
process  would wait indefinitely for the other to release the lock,
unless one of the user processes is terminated. SQL Server detects
deadlocks and terminates one user's process.
 
A livelock is one, where a  request for an exclusive lock is
repeatedly denied because a series of overlapping shared locks keeps
interfering. SQL Server detects the situation after four denials and
refuses further shared locks. A livelock also occurs when read
transactions monopolize a table or page, forcing a write transaction
to wait indefinitely.
 
Check out SET DEADLOCK_PRIORITY and "Minimizing Deadlocks"  in SQL
Server books online. Also check out the article Q169960 from Microsoft
knowledge base.
 
22. What is blocking and how would you troubleshoot it?
 
Blocking happens when one connection from an application holds a lock
and a second connection requires a conflicting lock type. This forces
the second connection to wait, blocked on the first.
 
Read up the following topics in SQL Server books online: Understanding
and avoiding blocking, Coding efficient transactions.
 
23. Explain CREATE DATABASE syntax
 
Many of us are used to craeting databases from the Enterprise Manager
or by just issuing the command: CREATE DATABAE MyDB. But what if you
have to create a database with two filegroups, one on drive C and the
other on drive D with log on drive E with an initial size of 600 MB
and with a growth factor of 15%? That's why being a DBA you should be
familiar with the CREATE DATABASE syntax. Check out SQL Server books
online for more information.
 
24. How to restart SQL Server in single user mode? How to start SQL Server
in minimal configuration mode?
 
SQL Server can be started from command line, using the SQLSERVR.EXE.
This EXE has some very important parameters with which a DBA should be
familiar with. -m is used for starting SQL Server in single user mode
and -f is used to start the SQL Server in minimal confuguration mode.
Check out SQL Server books online for more parameters and their
explanations.
 
25. As a part of your job, what are the DBCC commands that you commonly
use for database maintenance?
 
DBCC CHECKDB, DBCC CHECKTABLE, DBCC CHECKCATALOG, DBCC CHECKALLOC,
DBCC SHOWCONTIG, DBCC SHRINKDATABASE, DBCC SHRINKFILE etc. But there
are a whole load of DBCC commands which are very useful for DBAs.
Check out SQL Server books online for more information.
 
26. What are statistics, under what circumstances they go out of date, how
do you update them?
 
Statistics determine the selectivity of the indexes. If an indexed
column has unique values then the selectivity of that index is more,
as opposed to an index with non-unique values. Query optimizer uses
these indexes in determining whether to choose an index or not while
executing a query.
 
Some situations under which you should update statistics:
1) If there is significant change in the key values in the index
2) If a large amount of data in an indexed column has been added,
changed, or removed (that is, if the distribution of key values has
changed), or the table has been truncated using the TRUNCATE TABLE
statement and then repopulated
3) Database is upgraded from a previous version
 
Look up SQL Server books online for the following commands: UPDATE
STATISTICS, STATS_DATE, DBCC SHOW_STATISTICS, CREATE STATISTICS, DROP
STATISTICS, sp_autostats, sp_createstats, sp_updatestats
 
27. What are the different ways of moving data/databases between servers
and databases in SQL Server?
 
There are lots of options available, you have to choose your option
depending upon your requirements. Some of the options you have are:
BACKUP/RESTORE, dettaching and attaching databases, replication, DTS,
BCP, logshipping, INSERT...SELECT, SELECT...INTO, creating INSERT
scripts to generate data.
 
28. Explian different types of BACKUPs avaialabe in SQL Server? Given a
particular scenario, how would you go about choosing a backup plan?
 
Types of backups you can create in SQL Sever 7.0+ are Full database
backup, differential database backup, transaction log backup,
filegroup backup. Check out the BACKUP and RESTORE commands in SQL
Server books online. Be prepared to write the commands in your
interview. Books online also has information on detailed
backup/restore architecture and when one should go for a particular
kind of backup.
 
29. What is database replicaion? What are the different types of
replication you can set up in SQL Server?
 
Replication is the process of copying/moving data between databases on
the same or different servers. SQL Server supports the following types
of replication scenarios:
 
    * Snapshot replication
    * Transactional replication (with immediate updating subscribers,
with queued updating subscribers)
    * Merge replication
 
See SQL Server books online for indepth coverage on replication. Be
prepared to explain how different replication agents function, what
are the main system tables used in replication etc.
 
30. How to determine the service pack currently installed on SQL Server?
 
The global variable @@Version stores the build number of the
sqlservr.exe, which is used to determine the service pack installed.
To know more about this process visit SQL Server service packs and
versions.
 
Back to top
Database programming       (top)
 
31. What are cursors? Explain different types of cursors. What are the
disadvantages of cursors? How can you avoid cursors?
 
Cursors allow row-by-row prcessing of the resultsets.
 
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See
books online for more information.
 
Disadvantages of cursors: Each time you fetch a row from the cursor,
it results in a network roundtrip, where as a normal SELECT query
makes only one rowundtrip, however large the resultset is. Cursors are
also costly because they require more resources and temporary storage
(results in more IO operations). Furthere, there are restrictions on
the SELECT statements that can be used with some types of cursors.
 
Most of the times, set based operations can be used instead of
cursors. Here is an example:
 
If you have to give a flat hike to your employees using the following
criteria:
 
Salary between 30000 and 40000 -- 5000 hike
Salary between 40000 and 55000 -- 7000 hike
Salary between 55000 and 65000 -- 9000 hike
 
In this situation many developers tend to use a cursor, determine each
employee's salary and update his salary according to the above
formula. But the same can be achieved by multiple update statements or
can be combined in a single UPDATE statement as shown below:
 
UPDATE tbl_emp SET salary =
CASE WHEN salary BETWEEN 30000 AND 40000 THEN salary + 5000
WHEN salary BETWEEN 40000 AND 55000 THEN salary + 7000
WHEN salary BETWEEN 55000 AND 65000 THEN salary + 10000
END
 
Another situation in which developers tend to use cursors: You need to
call a stored procedure when a column in a particular row meets
certain condition. You don't have to use cursors for this. This can be
achieved using WHILE loop, as long as there is a unique key to
identify each row. For examples of using WHILE loop for row by row
processing
 
Write down the general syntax for a SELECT statements covering all the
options.
 
Here's the basic syntax: (Also checkout SELECT in books online for
advanced syntax).
 
SELECT select_list
[INTO new_table_]
FROM table_source
[WHERE search_condition]
[GROUP BY group_by__expression]
[HAVING search_condition]
[ORDER BY order__expression [ASC | DESC] ]
 
32. What is a join and explain different types of joins.
 
Joins are used in queries to explain how different tables are related.
Joins also let you select data from a table depending upon data from
another table.
 
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs.
OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL
OUTER JOINS.
 
33. Can you have a nested transaction?
 
Yes, very much. Check out BEGIN TRAN, COMMIT, ROLLBACK, SAVE TRAN and
@@TRANCOUNT
 
34. What is an extended stored procedure? Can you instantiate a COM object
by using T-SQL?
 
An extended stored procedure is a function within a DLL (written in a
programming language like C, C++ using Open Data Services (ODS) API)
that can be called from T-SQL, just the way we call normal stored
procedures using the EXEC statement. See books online to learn how to
create extended stored procedures and how to add them to SQL Server.
 
Yes, you can instantiate a COM (written in languages like VB, VC++)
object from T-SQL by using sp_OACreate stored procedure. Also see
books online for sp_OAMethod, sp_OAGetProperty, sp_OASetProperty,
sp_OADestroy. For an example of creating a COM object in VB and
calling it from T-SQL, see 'My code library' section of this site.
 
35. What is the system function to get the current user's user id?
 
USER_ID(). Also check out other system functions like USER_NAME(),
SYSTEM_USER, SESSION_USER, CURRENT_USER, USER, SUSER_SID(), HOST_NAME().
 
36. What are triggers? How many triggers you can have on a table? How to
invoke a trigger on demand?
 
Triggers are special kind of stored procedures that get executed
automatically when an INSERT, UPDATE or DELETE operation takes place
on a table.
 
In SQL Server 6.5 you could define only 3 triggers per table, one for
INSERT, one for UPDATE and one for DELETE. From SQL Server 7.0
onwards, this restriction is gone, and you could create multiple
triggers per each action. But in 7.0 there's no way to control the
order in which the triggers fire. In SQL Server 2000 you could specify
which trigger fires first or fires last using sp_settriggerorder
 
Triggers can't be invoked on demand. They get triggered only when an
associated action (INSERT, UPDATE, DELETE) happens on the table on
which they are defined.
 
Triggers are generally used to implement business rules, auditing.
Triggers can also be used to extend the referential integrity checks,
but wherever possible, use constraints for this purpose, instead of
triggers, as constraints are much faster.
 
Till SQL Server 7.0, triggers fire only after the data modification
operation happens. So in a way, they are called post triggers. But in
SQL Server 2000 you could create pre triggers also. Search SQL Server
2000 books online for INSTEAD OF triggers.
 
Also check out books online for 'inserted table', 'deleted table' and
COLUMNS_UPDATED()
 
37. There is a trigger defined for INSERT operations on a table, in an
OLTP system. The trigger is written to instantiate a COM object and
pass the newly insterted rows to it for some custom processing. What
do you think of this implementation? Can this be implemented better?
 
Instantiating COM objects is a time consuming process and since you
are doing it from within a trigger, it slows down the data insertion
process. Same is the case with sending emails from triggers. This
scenario can be better implemented by logging all the necessary data
into a separate table, and have a job which periodically checks this
table and does the needful.
 
38. What is a self join? Explain it with an example.
 
Self join is just like any other join, except that two instances of
the same table will be joined in the query. Here is an example:
Employees table which contains rows for normal employees as well as
managers. So, to find out the managers of all the employees, you need
a self join.
 
CREATE TABLE emp
(
empid int,
mgrid int,
empname char(10)
)
 
INSERT emp SELECT 1,2,'Vyas'
INSERT emp SELECT 2,3,'Mohan'
INSERT emp SELECT 3,NULL,'Shobha'
INSERT emp SELECT 4,2,'Shridhar'
INSERT emp SELECT 5,2,'Sourabh'
 
SELECT t1.empname [Employee], t2.empname [Manager]
FROM emp t1, emp t2
WHERE t1.mgrid = t2.empid
 
Here's an advanced query using a LEFT OUTER JOIN that even returns the
employees without managers (super bosses)
 
SELECT t1.empname [Employee], COALESCE(t2.empname, 'No manager') [Manager]
FROM emp t1
LEFT OUTER JOIN
emp t2
ON
t1.mgrid = t2.empid
39. What is the difference between Function and Stored Procedure.

Stored Procedure (SP)
Function (UDF - User Defined Function)
SP can return zero, single or multiple values.
Function must return a single value (which may be a scalar or a table).
We can use transaction in SP.
We can't use transaction in UDF.
SP can have input/output parameter.
Only input parameter.
We can call function from SP.
We can't call SP from function.
We can't use SP in SELECT/ WHERE/ HAVING statement.
We can use UDF in SELECT/ WHERE/ HAVING statement.
We can use exception handling using Try-Catch block in SP.
We can't use Try-Catch block in UDF.

40. What is the difference between Trigger and Stored Procedure.


   
1.       We can execute a stored procedure whenever we want with the help of the exec command, but a trigger can only be executed whenever an event (insert, delete, and update) is fired on the table on which the trigger is defined.
  
2.       We can call a stored procedure from inside another stored procedure but we can't directly call another trigger within a trigger. We can only achieve nesting of triggers in which the action (insert, delete, and update) defined within a trigger can initiate execution of another trigger defined on the same table or a different table.
 
3.       Stored procedures can be scheduled through a job to execute on a predefined time, but we can't schedule a trigger.
 
4.       Stored procedure can take input parameters, but we can't pass parameters as input to a trigger.
  
5.       Stored procedures can return values but a trigger cannot return a value.
  
6.       We can use Print commands inside a stored procedure for debugging purposes but we can't use print commands inside a trigger.
  
7.       We can use transaction statements like begin transaction, commit transaction, and rollback inside a stored procedure but we can't use transaction statements inside a trigger.
  
8.       We can call a stored procedure from the front end (.asp files, .aspx files, .ascx files, etc.) but we can't call a trigger from these files.
   
9.       Stored procedures are used for performing tasks. Stored procedures are normally used for performing user specified tasks. They can have parameters and return multiple results set.
  
10.    The Triggers for auditing work: Triggers normally are used for auditing work. They can be used to trace the activities of table events.


 

PowerBuilder frequently asked questions by top companies


PowerBuilder frequently asked questions by top companies

Question 1

What is the difference between SetTrans() and SetTransObject()?

Answer 


In simple terms, SetTrans() gives you no control on the transactions. It automatically connects to and disconnects from the database after each Retrieve() and Update() function. It is useful when the number of connections are limited, but, you can't use this for multi-table update. On the other hand SetTransObject() gives you full control over the transactions. It is your responsibility to connect to and disconnect from the database and also, you need to issue COMMIT/ROLLBACK statements. This method is more efficient since there is no connect/disconnect overhead for each database operation.

Question 2


List all the buffers that a DataWindow control maintains.

Answer

Primary!, Delete!, Filter!, Original!, and one buffer for the edit control.

Question 3


When the DataWindow is set to ReadOnly, What buffers PowerBuilder maintains for the DataWindow Control?

Answer


PowerBuilder maintains all the four buffers, i.e., Primary!, Delete!, Filter!, Original!.

Question 4


How do you change the SQL Statement of a DataWindow at run-time?

Answer


You can either use the Modify() or .Object notation to change the SQL statement of a DataWindow control. In the SQLPreview event, you can change it using SetSQLPreview(). Outside SQLPreview event, you can call SetSQLSelect().

Question 5


The new .Object notation syntax for the DataWindow control replaces the Modify() function. Explain.

Answer


No, it doesn't completely replace Modify() function. You can create objects such as rectangle, text objects in the DataWindow object using the CREATE statement in the Modify() function. This can't be done with the .Object notation. It is also not possible to refer to the data by column name dynamically, which can be done using Modify().

Question 6


Describe where you can't use .Object notation for a DataWindow control instead of the Modify()?

Answer


You can't create objects in the DataWindow object dynamically using the .Object notation.

Question 7


How do you change the DataWindow object of a DataWindow control at run-time?

Answer


DataWindow_Control_Name.DataObject = 'New_DataWindow_Object_Name'


Question 8


What will happen if you pass extra retrieve arguments to the Retrieve() function for the DataWindow control?

Answer


PowerBuilder ignores extra arguments.

Question 9


What will happen if you pass no arguments to the DataWindow's Retrieve() function, when the DataWindow is expecting some arguments?

Answer


PowerBuilder prompts you for the arguments at run-time.

Question 10


Can you use an array as an argument to the DataWindow's Retrieve() function? If yes, How and where it is useful?

Answer


Yes, you can use PowerBuilder array as an argument to the Retrieve() function. This is useful when you use IN clause in the SELECT statement of the DataWindow's source.

 

Question 11


What would be the row status in the destination DataWindow when a row is copied from another DataWindow using RowsCopy() function?
 
Answer


NewModified!


 

Question 12


What would be the row status in the destination DataWindow when a row is copied from another DataWindow using RowsMove() function?

Answer


NewModified!

Question 13


I would like to allow the user to print selected rows. How it can be done?

Answer


Have a hidden DataWindow control or a DataStore and assign the same DataWindow object that you are using to display on the window. Copy selected rows to the DataStore or the hidden DataWindow control (You can use RowsCopy() function) and print the DataStore or the hidden DataWindow control.

Question 14


What are the different statuses a row in a DataWindow can have?

Answer


New!, NewModified!, DataModified!, NotModified!

Question 15


What are the different statuses a column in a DataWindow row can have?

Answer


DataModified!, NotModified!

Question 16


Explain the use of AcceptText() function.

Answer


This function applies the content of the edit control to the primary buffer after validating the data. PowerBuilder applies the edit control content to the Primary buffer whenever user press tab or click on another column within the DataWindow. if the user change the value of a single column and doesn't press either tab or click on another column, PowerBuilder will not copy the changed data, that means the changes will not be applied in the database. Calling the AcceptText() function solves this problem. You can also specify to the Update() via argument to call AcceptText() internally before applying the changes to the database.

Question 17


When you update the DataWindow, what would be the each row status in the DataWindow when the update is successful?

Answer


NotModified!

Question 18


You have deleted few rows, say 10 rows from a DataWindow, and update the DataWindow. How many rows would be available in the Deleted buffer after successful update?

Answer


Zero Rows.

Question 19


Explain the advantages and disadvantages of calling AcceptText() function from the ItemChanged event of a DataWindow control.

Answer


AcceptText() function shouldn't be called from ItemChanged event. This is because, AcceptText() function triggers the ItemChanged event. That means, calling AcceptText() in the ItemChanged event will go into a loop. So, there are only disadvantages, no advantages. If you really need to call AcceptText() from ItemChanged event, create a user-defined event and post that event from the ItemChanged event.

Question 20


How do you change the default DataWindow error message title?

Answer


Assign the application object's 'DataWindowMessageTitle' attribute with the new DataWindow error box title.

Question 21


Assume, you have marked a field as 'Required'. At run-time user tabs into that field and tabs out without entering a value in that field. Will PowerBuilder force the user for specifying a value? If not, how do you force the user for specifying the value?

Answer


As long as the user do not change (In this context, do not enter the data) the column's value, PowerBuilder do not force entering a value. The solution to this problem is, Call FindRequired() function before you update the DataWindow.

Question 22


Explain the DataWindow validation.
 

Answer


PowerBuilder checks whether the data is changed or not by comparing the edit control value with primary buffer. It checks for the data type correctness, if the data is changed. Wrong data type will trigger ItemError event. When the data passes the data type checking, it executes the validation rule. Invalid data will trigger ItemError event. Correct data will trigger ItemChanged event. If the ItemChanged event returns zero, it will trigger ItemFocusChanged event, otherwise ItemError will be triggered. Depending on the ItemError event's return value, either the cursor remains in the same column or will go to the next higher tab sequence's field (In this case, ItemFocusChanged event will be triggered).


Question 23


When two DataWindow are being shared, what exactly would be shared and are there any restrictions?

Answer


The presentation is not shared. The data (buffers including Delete! and Filter!) and the sort criteria is shared. There are few restrictions, which include, Crosstab DataWindow windows can't share data, the client and the server in the distributed computing mechanism can't share data. you can turn on the query mode only for the primary DataWindow. If a DataWindow is sharing data with a nested DataWindow, the handle to the nested DataWindow becomes invalid with each retrieval. So, GetChild() and ShareData() need to be called each time a nested DataWindow is retrieved.

Question 24


What is difference between 'prompt for criteria' and 'Query Mode'?

Answer


'Prompt For Criteria' as the name says, prompts for the criteria--for all those columns that were marked--in its own display dialog box and ignores the DataWindow you have painted. It also ignores the tab sequence number, i.e., prompts even if the tab sequence is zero. 'QueryMode' is more flexible than the 'Prompt for Criteria', and it uses the DataWindow you have painted. It allows querying on all non-zero tab sequence columns in the DataWindow and you do not mark any column for this purpose. The former one promts for the values every time Retrieve() is called, where as the later one takes values only when you turn it on--by enabling QUERYMODE property.

Question 25


Say, you have a DataWindow which returns 10,000 rows. After retrieving few rows, say, 100 rows, you have decided not to retrieve the rest of the rows. Explain different methods of canceling the result set.

Answer


There are two ways to accomplish this. In the first method, you can call DBCancel() to cancel the query from a CommandButton Clicked event or in other event. However, once PowerBuilder starts retrieving the data, it will not give the control to the user till it completes retrieval. So, you need to put some code/comments in RetrieveRow event which will yield a little bit.
In the second method, you can just return 1 from the RetrieveRow event.

Question 26


Say, you have a DataWindow with two fields, emp_name, emp_address. Now, the focus is on the emp_name field. When the user press tab, what would be the return value of GetColumnName() from A.) ItemChanged and B.) ItemFocusChanged events?

Answer


GetColumnName() returns 'emp_name' in the ItemChanged event and 'emp_address' in the ItemFocusChanged event.

Question 27


Explain the steps that are required to update a multiple-table DataWindow?

Answer


In short, using the Modify function or .Object notation, you need to make one table updatable. You also need to set the primary keys for that table. Then update the DataWindow with FALSE argument for the reset option in the Update() function. After successful update, make the second table updatable and the first one not-updatable. Now call Update() function with TRUE for the reset option (If there are more than two tables, use the TRUE option to the last table to be updated). Commit after successful update and Rollback on unsuccessful update.

Question 28


What you have to do if you want the PowerBuilder to prompt for the sort criteria at run-time?

Answer


Set the sort criteria to NULL value using the SetSort() function and call Sort() function.

Question 29


How many times PowerBuilder will retrieve data from the child DataWindow in the following situation. A DataWindow has a field with DDDW edit style. There are 1000 rows in the parent DataWindow.

Answer


It retrieves only once. The thumb rule here is that, PowerBuilder retrieves data from the child DataWindow only when the child DataWindow do not have data in it.

Question 30


What command/function you use to select a row?

Answer


SelectRow() function.

Question 31


If there are 10 rows selected in a DataWindow, and if you call DeleteRow() function, how many rows will be deleted? Explain.

Answer


DeleteRow() has nothing to do with the row selection. It deletes only one row that you specify as the argument to it. If you want to delete all the selected rows, you need to call DeleteRow() in a loop for each selected row (You can find the selected row by calling GetSelectedRow() function).

Question 32


You have defined a composite DataWindow 'd_master' which has two DataWindows 'd_emp_info', 'd_emp_paychecks'. 'd_emp_info' takes one argument and 'd_emp_paychecks' takes two arguments. 'd_master' is placed in 'DataWindow_1' DataWindow control. DataWindow_1.Retrieve( Arg1, Arg2, Arg3 ) will retrieve data without prompting. Do you agree? Explain.

Answer


PowerBuilder prompts for the retrieval arguments. This is because, you can't specify retrieval arguments in the Retrieve() function for the nested DataWindows. Instead, you need to set Nested_Arguments attribute using the Modify() function or .Object notation.

Question 33


What will happen when you pass a wrong argument to the Modify() function?

Answer


Returns the error code, but doesn't trigger any event such as DataWindow dbError or Error. However, doing the same using .OBJECT notation will generate error and trigger DataWindow Error event.

Question 34


What will happen when you use a wrong expression for a DataWindow in the .Object notation?

Answer


Will trigger Error event of the DataWindow control.

Question 35


What is the difference between 'Error' and 'dbError' events in a DataWindow control?

Answer


DbError event is fired when a database related error occurs. Error event at the DataWindow control level is triggered when a wrong expression is encountered in the .Object notation, or a OLE/OCX related error occurs. For database errors, if you do not write any code in DBError event, PowerBuilder displays the error in its own dialog box. In the later case, if you do not code to DataWindow ERROR event, it will fire Application SystemError event. If there is no code in that event, PowerBuilder displays the error message and terminates the application.


Question 36


Explain the following error: 'Row(s) changed between retrieve and update'. Also explain how you will get rid of that error?

Answer


PowerBuilder reports this error when some one/process updates the row after you retrieve it but before apply the changes. POWERBUILDER detects this type of error when you include the TimeStamp column in the DataWindow or use the 'Key columns and Updatable columns' in the WHERE criteria. We can't avoid this error. The solution to this problem would be, reselect the row that caused the error and display it to the user with appropriate message and then update the database again. You can use ReSelectRow() function to get the latest values for the error row.

Question 37


What is concurrency control? How do you control it from the PowerBuilder?

Answer


When multiple users are working on the same data, we have to make sure that we don't corrupt others changes, either by updating their changes without looking at them or by any other means. When we apply changes to the database, we have to make sure that no body changed the data between your read and update. This can be controlled (not exactly controlling, but, we can detect) using the appropriate WHERE clause option in the update properties in the DataWindow painter.

Question 38


Explain different ways of generating a serial number for a column in a table. Explain ways in PowerBuilder and in the database. Which method you recommend?

Answer


This has to be controlled from the database, not from the PowerBuilder. This is because, a unique serial number generated by a POWERBUILDER client may not be unique for other user or when it is put in the database. If the database supports auto incrementing (Different database vendors implement it in different ways, for ex: sybase implements using Identity column property, Watcom calls AutoIncrement, Oracle selects from a special table), then there is no problem. Otherwise, you can use a single row single column table to generate serial no. The method you choose might depend on the performance issues and number of expected inserts and other factors.

Question 39


I want to execute a stored procedure that is defined in the database, using the function call notation. What I need to do?

Answer


Define a function that refers to the stored procedure, in the transaction object and start using the function. It is something like declaring an external function, however, you can't declare a function for a stored procedure at any object other than a transaction object.

Question 40


Explain the steps involved in inserting your a layer between 'transaction' object and 'SQLCA'.

Answer


Create a standard class user object by inheriting from 'Transaction' object. Define the attributes and functions that you need. Now, ask the SQLCA to be of type YourTransactionObject instead of TRANSACTION object. This you can do in the application painter.

Question 41


Write the code to protect existing data from changes by the user in a DataWindow and allow adding new rows.

Answer


DataWindow_1.Object.Column1.Protect = '1~tIf(IsRowNew(),0,1)'

Question 42


Explain the method you follow when you want to skip printing all pages that are divisible by 7 (seven)?

Answer


Well, you can write code for the PrintPage event of a DataWindow control. Check whether the page number is divisible by seven, if so, then return 1.

Question 43


I want to use the value passed in the retrieval arguments in the DataWindow. What I need to do?

Answer


If you are using PowerBuilder version 4.0 or above, you should be able to see the retrieval arguments under in the 'Columns' listbox in the 'Expression' dialog box. So, you can use it as if it is a column.

Question 44


The following situation triggers 'SystemError' event at the application object. Explain. You are trying to update a table on which you don't have update privilege.

Answer


This will not trigger the SystemError event, since it is a database & DataWindow related error. It triggers DataWindow DbError event. If there is no script for that event, PowerBuilder displays the error message in the default way.

Question 45


You got 'Row(s) changed between retrieve and update' error. Now, you want to select the latest value of that changed row. How you do that?

Answer


Use ReSelectRow() function.

Question 46


In a DataWindow, there are few fields with validation rules, and few fields with script in the ItemChanged event. I want to display custom error message when data doesn't go through the ItemChanged event, but want to display default error messages when the data doesn't go through the validation rules. What should I do?

Answer


Well, define an instance variable. Turn it one when you decide the data is invalid in the ItemChanged event. In the ItemError event, return appropriate return code depending on the instance variable value and reset the instance variable to it's default value appropriately.

Question 47


I want to find out all the fields that doesn't have values and have 'Required' attribute turned on. What should I do?

Answer


Call FindRequired() function before you call Update() function.

Question 48


Can I store some data in the DataWindow? If yes, How?

Answer


Select Rows/Data from the menu when you are in the DataWindow painter design mode and add data to the DataWindow and save the DataWindow. The data now is stored as part of the DataWindow definition.
 
Question 49


What I need to do if I want the child DataWindow shouldn't retrieve the data automatically?

Answer


Store an empty row in the child DataWindow. PowerBuilder do not retrieve data from the child DataWindow since it sees data inside it. You can store data in the child DataWindow, by selecting Rows/Data from the menu when you are in the DataWindow painter design mode.

Question 50


How many DataWindow can share the data from a DataWindow?

Answer


There is no limitation on how many DataWindows can share data from the first primary DataWindow or from the secondary DataWindow that work as primary DataWindow for other DataWindows.

Question 51


What is the difference between a DataWindow and a DataStore object?

Answer


DataStore is nothing but a DataWindow without interaction related events and functions. DataStore has less overhead compared to DataWindow since the DataStore object do not have interaction related overhead. You can use DataStore as a parameter to a remote object function/event in the distributed computing and OLE automation, where as DataWindow can not be used in those situations.

Question 52


Can a DataWindow share the data from a DataStore?

Answer Yes.


Question 53


I have a table in which one column is of 'LongBinary' data type. Can I update this column using DataWindow? If yes, How?

Answer


A regular DataWindow do not support BLOB data types such as 'Long Binary', Sybase's Image & Text data type columns. You need to use 'DATABASE BLOB' object in the DataWindow object. You can update the database normally when you follow these steps.

Question 54


What is the difference between a 'Computed Column' and 'Computed Field'?

Answer


'Computed Column' is a column that you define as part of the SELECT statement. These values are calculated by the database and sent to the PowerBuilder client. 'Computed Field's' we define in the DataWindow bands and PowerBuilder calculates these values, not the database. Depending on your computing model 'Fat Client' or 'Thin Client' you can decide which one to use. If it is 'Fat Client' model, use 'Computed Fields', otherwise use 'Computed Columns'.

Question 55


Can you change the value of a 'Computed Field' at run-time?

Answer


No, you can't the Computed field value directly. However, you can change the column value that are part of the Computed field expression, by that Computed field value will be changed automatically.

 
Question 56

What is a Dynamic DataWindow and how do you create a Dynamic DataWindow?

Answer


Dynamic DataWindow is the DataWindow that is not painted at design-time, instead it is created at run-time. This is useful when you don't know the exact columns that you need to include in the DataWindow at design time. You need to use SyntaxFromSQL() function and Create() function to create a DataWindow dynamically.

Question 57


How can I search a DataWindow?

Answer


Use Find() function.

Question 58


In a DataWindow validation rule, how can I refer to the data that is entered by the user?

Answer


Call GetText() function in the validation rule to get the data entered by the user. If you want to paint the same in the Database painter, you can use @name where name can be any text. PowerBuilder automatically converts @name to GetText() in the DataWindow validation rule when you paint a DataWindow that uses that column.

Question 59


Explain how 'Retrieve Only Needed' works.

Answer


By default, PowerBuilder displays the first row on the screen when it completes retrieving all the result set. That means, if there is huge result set, user has to wait for long time to see the first row on the screen. If you turn on 'RetrieveOnlyAsNeeded' property, PowerBuilder retrieves only those rows that fit on one screen. That means, user will see the data quickly. When the user scrolls, PowerBuilder retrieves again (as many rows as required). This option might affect the database server performance also, since the result is queued at the database till PowerBuilder client completes retrieving.

Question 60


What should I do if I want to display rows as soon as they are retrieved from a DataWindow?

Answer


Write code in the RetrieveRow event, at least a single line comment. And also set the 'Async' attribute in the DbParm property of the transaction object.

Question 61


Say, you have a DataWindow 'd_emp' which has a field 'emp' with DDLB edit style. When you read the field value using GetItemxxxxxxxx() function, what value is returned, 'Display Value' or 'Data Value'? What you need to do to get other value?

Answer


Use the LookupDisplay() function.

Question 62


How do you handle variable length text fields in a DataWindow?

Answer


Set the 'AutoSizeHeight' property in the detail band of the DataWindow when you are in the DataWindow painter design mode.

 
Question 63

How to retrieve multiple result set of a stored procedure in a single DataWindow?

Answer


A DataWindow can retrieve only one result set at a time. If you want to retrieve other result sets also, you can change the result set number either by Modify() function or using .Object notation. When you change the result set, make sure the number of columns and data types match with the existing DataWindow definition.

Question 64


How to retrieve a particular result set of a stored procedure in a DataWindow?

Answer


You need to suffix the result set number to the stored procedure name separated by semicolon.

Question 65


How to load a text file in a DataWindow?

Answer


Well, you can use ImportFile() function.

Question 66


What is a CrossTab presentation Style DataWindow? What are the places you can use this type of DataWindow?

Answer


Crosstab presentation style DataWindow allows to shorten the length of the report and display the data in a two-dimensional spreadsheet like report. One dimension displays in columns and the other as rows.

Question 67


How do you update a 'Group' presentation style DataWindow?

Answer


A DataWindow with 'Group' presentation style can't be updated.

Question 68


How do you update a 'OLE' presentation style DataWindow?

Answer


OLE presentation style DataWindow is only for display, you can't update that DataWindow.

Question 69


What are code tables and how you can use them in a DataWindow?

Answer


Code tables are used for translation. Typical use of code table is to display long description about the data, say, 'New York' and store the abbreviation in the database, say, 'NY'. You can use code tables in the DataWindow for the EditMask edit style only.

Question 70


What is the difference between a 'column name' and 'database column name'. Can you change any of these at painting time? If yes, How?

Answer


'Column Name' is the name of the column in the DataWindow. You always refer to this name when you want to change the column attributes. You can change the column name in the DataWindow. The 'Database column name' is the name of the column in the database and you can't change this name. Typically, this name is prefixed with the database and table and owner name. You can see both column and database column names by selecting 'Rows/Columns' in the DataWindow when you are in the DataWindow design mode.

Question 71


You have a DataWindow that has 100 rows. I want to append the rows to the existing rows when I retrieve next time in that DataWindow. Explain the required steps to do this.

Answer


Return 2 in the RetrieveStart event of that DataWindow control.

Question 72


What is the event from which I can see the exact SQL statement that is being sent to the database by PowerBuilder?

Answer


SQLPreview event of the DataWindow control.

Question 73


How to refer to a DataWindow column by the column number in the 'Describe()' and 'Modify()' functions.

Answer


You need to prefix the column number with pound (#). For example, DataWindow_1.Modify( '#10.TabSequence=0' ) sets the column number ten's tab order to zero.

Question 74


How to update a DataWindow that has 'Stored Procedure' as the data source?

Answer


Go to the update properites of the DataWindow by selecting Rows/Update properties from the menu when you are in the design mode in the DataWindow painter. Type the table name to update in the 'Table' prompt. Make sure the column names and data types are same.

Question 75


What are the uses of a DataWindow with 'External' data source?

Answer


'External' DataWindows are useful when you want to use the power of DataWindows, even though you are not retrieving the data from the database. Some of the features which would be more difficult to implement without using a DataWindow are, sorting, filtering, printing, exporting data into different formats, print previewing/zooming and so on.

Question 76


How many 'OLE DATABASE' columns you can use in one DataWindow?

Answer


Well, you can paint as many OLE Database BLOBs as you wish in a DataWindow. However, the update is not going to take place when you place more than one OLE Database BLOB object in a DataWindow.

Question 77


What are different types of windows available in PowerBuilder?

Answer


There are six different types of windows available in PowerBuilder. Those are Main, Popup, Child, Response, MDI Frame, MDI Frame with Microhelp.

 
Question 78

If I create a response window and open that window in an MDI frame using OpenSheet(), what will happen?

Answer


When you open a window in a MDI frame using OpenSheet() or OpenSheetWithParm() functions, that window get the sheet properties, irrespective of the window type. That means, when you open the response window using one of those functions, the window will behave like any other sheet, i.e., gets maximize, minimize, close controls on the title bar.

Question 79


Explain how a popup window is different from a child window?

Answer


Popup window can go beyond the parent window borders and Popup window is always on the top. On the other hand, the Child window can't go beyond parent window borders. Child window is never considered as an Active window from the programming perceptive.

Question 80


What is MDI_1?

Answer


MDI_1 control represents the 'Client Area' in a 'MDI frame' or 'MDI frame with Microhelp'. That means, all the window area other than 'Titlebar', 'Menu', Microhelp statusbar' is MDI_1. When you paint any object in the MDI window, you need to resize the client area programmatically by referencing MDI_1, otherwise, MDI_1 control size is not determined. That means, we can't see any sheet that we open in the client area, unless we resize the MDI_1 control.

Question 81


What should I do if I want to paint a window control in a MDI Frame window?

Answer


You need to resize the MDI_1 control. Window's resize event is the good candidate to write the script for MDI_1 control re-sizing. You need to reduce the size of the MDI_1 control by the size of all the controls that you have placed in the window.

Question 82


Can I have multiple MDI frame windows in the same application?

Answer


Well, technically, you can have multiple MDI windows in the same application. You can call Open() function twice, one for each MDI window. Please note that, the user might think that, two applications are running, since two different windows will appear with different menus.

Question 83


I need to declare an Instance variable for a DataWindow control ONLY, in a window. What should I do?

Answer


When you declare an instance variable at a window, it is accessible to all controls in the window. First of all, you can't declare an Instance/Shared variable for a specific control in a window. If you have the need of that, you need to create a user object of that specific control and declare instance/shared variables in the user object. Then place the user object in the window. In summary, a window control can't have it's own instance/shared variables, but the user object can (in the user object painter ONLY, not in Window Painter).

Question 84


Can I have a global and local variable with the same name?

Answer


Yes, You can have global and local/instance variable with the same name.

Question 85


You have declared a global variable xyz and a local variable xyz in the clicked event of a CommandButton. When you refer to xyz in the CommandButton's clicked event, which variable is referred? Global or Local?

Answer


Well, when you refer to xyz variable, POWERBUILDER search for the variable in local, instance/shared, instance/shared at the ancestor, global order. That means, in this case, the local variable is referred. To refer to the global variable which has the same name of a local variable, you need to prefix double colon before the variable name.

Question 86


How a 'Shared Variable' is different from a 'Instance Variable'?

Answer


Well, the value of an instance variable in each instance is independent of other instances. Instance variables are created when the object is created and will be destroyed when the object is destroyed. On the other hand, the shared variable is shared between different instances of the variable. That means, changing the shared variable in one instance will affect other instances. The shared variable is created when the FIRST instance of the object is created and is destroyed when the application is closed. You can't refer to an object's shared variable when none of the instance is open, even though the shared variables exists in the memory.

Question 87


Tell me some situations where you need to use shared variables.

Answer


One typical situation would be, counting the number of instances of a sheet. Another situation will be, you can use the shared variable to prevent the user updating the same record from multiple instances of the same window with different values.

Question 88


When a function argument is declared 'By ReadOnly', what you can do on that variable and what you can't do?

Answer


You can refer to that argument, you can change the value of the argument. But, you can't assign another object to that object. For example, say, a DataWindow is passed as a 'By ReadOnly' argument. You can change the value of any column/row of that DataWindow, but you can't say: arg_DataWindow = Another_DataWindow. In this case, you are assigning another object to this object. That means, you are asking to change the pointer to refer to the new object instead of the original object, which is not allowed when the argument is passed by 'By ReadOnly'.

Question 89


What is the difference between passing a function argument 'By Value' and 'By Reference'?

Answer


When an argument is passed 'By Value', the changed value of the argument in the called function will not be available in the calling object. On the other hand, when the argument is passed 'By Reference', the changed value of the argument in the called object IS AVAILABLE in the calling object. In case of 'By Value', POWERBUILDER sends a copy of the object, where as a pointer is send when passed by 'By Reference'.

Question 90


Can you declare CONSTANTS in PowerBuilder?

Answer


From version 5.0 onwards, you can declare constants in POWERBUILDER. For example: CONSTANT APPEND_TO_ROWS 2. When you want to append to the existing rows in the DataWindow when you retrieve next time, write 'return APPEND_TO_ROWS' instead of 'return 2'. Using constants you can make the code more readable and also more efficient (in some places).

Question 91


Explain the use of ANY data type.

Answer


ANY data type was introduced in version 4.0. You can use this data type when you really not sure about the return value of function. For example, OLE 2.0 control and in OLE automation. You really don't know what object/error code will be returned by the OLE client. Sometimes, those are compatible with POWERBUILDER data types. In those cases, you can use this variable to store the return value and CAST it to another data type before you operate on the value.

Question 92


How do you declare a function that returns nothing?

Answer


Type '(None)' without quotations in the 'Return Value' prompt when you are in the function painter.

Question 93


How to execute the ancestor event's script from the descendant's event?

Answer


You can use CALL SUPER::EVENT_NAME syntax.

Question 94


What will happen when you TRIGGER a non-existing event?

Answer


If you trigger a non-existing event using the old syntax, TriggerEvent(), nothing happens. In the new syntax, you can't trigger a non-existing event unless you use DYNAMIC keyword. When you trigger the event dynamically, NULL value will be returned.

Question 95


What will happen when you TRIGGER an event that doesn't have any script?

Answer


Nothing will happen. You are not allowed to capture the return value of an event which returns nothing. NULL value is returned when you trigger an event which has no script.

Question 96


What is the difference between TriggerEvent() and PostEvent()?

Answer


TriggerEvent() executes the specified event's script right away. PostEvent() posts the requests in the operating system's queue. This doesn't mean the posted event's script will be executed after completing the current script execution. It might execute right away also, it depends on how many requests are in the Operations system's message queue.

Question 97


What is the difference between TriggerEvent() and Send()?

Answer


TriggerEvent() JUST executes the specified event's script, but, it do not really trigger the event. For example, triggering the window's 'Close' event will execute the script written for that event, but, will not close the window. If you use Send() function, it does both, i.e., executes the script and closes the window also.

 
Question 98

How PowerBuilder executes events? Bottom-to-Top or Top-to-Bottom?

Answer Top-to-Bottom


Question 99


In the inheritence hirerachy, How PowerBuilder search for a function? Top-to-Bottom or Bottom-to-Top?

Answer


Bottom-to-Top

Question 100


Explain different levels of attribute/method protection available in PowerBuilder?

Answer


Public, Protected, Private, PrivateRead, PrivateWrite, ProtectedRead, ProtectedWrite

Question 101


How do you pass a value to a window at opening time?

Answer


Use either OpenWithParm() or OpenSheetWithParm() function depending on whether you are trying to open a window as a window or a sheet.

Question 102


Explain what a 'Message' object is and How it is useful in the programming?

Answer


'Message' object contains the messages that are sent by the operating system and sent by the POWERBUILDER scripts. It always contains only one message, that is the latest one. When you use OpenWithParm(), OpenSheetWithParm(), OpenUserObjectWithParm(), those parameters are placed in the 'Message' object and you can access those parameters in the opening object from the 'Message' object. Changing the values of the 'Message' object affects the event execution. For example, changing the 'ReturnValue' of the Message object in the window's CloseQuery event to 1 will stop the window being closed.

Question 103


What is the difference between 'Close' and 'CloseQuery' event?

Answer


POWERBUILDER triggers 'CloseQuery' event before it triggers 'Close' event. If 'CloseQuery' event's script is not executed successfully (in terms of return value), 'Close' event will never trigger.

Question 104


Explain typical scripting that you do in the 'CloseQuery' event?

Answer


Typical scripting would be, checking for unsaved work and prompting the user for the same and take action depending on the user's response.

Question 105


What should I do if I want to use '-' (hyphen) in identifiers in PowerScript?

Answer


Add 'DashesInIdentifiers=1' without quotations to the [POWERBUILDER] section in the POWERBUILDER.INI file.
 
Question 106

Explain different debugging mechanisms in PowerBuilder.

Answer


First mechanism would be obviously the debug painter. You can also use TRACE flag to log all the ODBC calls, /PBDEBUG to log the POWERBUILDER script execution.

Question 107


What should I do if I want to call a Windows SDK API?

Answer


You need to declare the Windows SDK API as an external function either locally or globally depending on your need. Then only you can refer to that function in PowerScript. If you have the same function name in PowerScript also, you can alias the external function in the declaration.

Question 108


List three PowerBuilder pronouns that we use to reduce hard-coding.

Answer


THIS, PARENT, PARENTWINDOW

Question 109


How 'Parent' is different from 'ParentWindow'?

Answer


'Parent' pronoun is used to refer to the object in which the current object is. For example, referring to 'Parent' in a CommandButton's script will refer to the window in which the CommandButton is placed. This is used in window control's scripts and functions. On the other hand, 'ParentWindow' is used to refer to the window for which the current menu is attached.

Question 110


What should I do if I want to display an User Object at specific location in a window dynamically?

Answer


You can specify the X and Y co-ordinates in the OpenUserObject() and OpenUserObjectWithParm() functions.

Question 111


Did you ever use Handle()? Where and How?

Answer


Handle() function gives the handle number of a given window. In simple terms, it is the number that identifies a window uniquely. You can use this function to check whether a particular window is open or not. Especially useful when you want to check whether another instance of the same application is running or not. You can use this function along with FindWindow() Windows API call.

Question 112


I want to find out whether the PowerBuilder application is still connected to the database or not. What should I do in the PowerScript?

Answer


Use DbHandle() function.

 
Question 113

I have a window which has a menu associated with. For some reason, I deleted the menu. Now, I am getting error when I try to open the window. What should I do?

Answer


If you remember the menu name, just create a dummy menu with the previous menu name. Now you should be able to open the window. Then, you can de-reference the menu from the window. If you don't remember the menu name, export the window and look in the exported file for the menu name. If you know really, you can edit the exported file and import it back otherwise, just note down the menu name and follow the first method.

Question 114


There is a ancestor window 'w_1' with one SingleLineEdit control 'sle_1'. Now, I created another window 'w_2' by inheriting from the 'w_1' window. In 'w_2' I changed the window background color to Pink. Then, I went back to 'w_1' and changed the window background color to Blue and 'sle_1' background color to Red. What color changes will reflect in 'w-2' window?

Answer


The thumb rule is that, if you have done any changes to a specific attribute in the descendent, then any further changes to the same attribute in the ancestor WILL NOT affect in the descendent. That means, since you have changed the window background color in the descendent, ancestor's background color change do not affect the descendent. You haven't changed the background color for the sle_1 in the descendent, So, the background color change for the sle_1 in the ancestor will reflect in the descendent also.

Question 115


What are PowerBuilder system tables and how they are useful for a PowerBuilder programmer?

Answer


There are five POWERBUILDER system tables, 'PBCatCol', 'PBCatEdt', 'PBCatFmt', 'PBCattbl', 'PBCatVld'. These tables store all the table, column specific information and POWERBUILDER extended attributes. These tables are created in the connected database by POWERBUILDER when the first user connects for the first time. These tables allow you defining extended attributes such as validation rule, edit style, display style, etc.. Once you create the extended attributes, these values are by default used when you create a DataWindow, which will reduce a lot of work and makes dws more consistent.

Question 116


How do you synchronize Database tables with the PowerBuilder catalog?

Answer


In the database painter, there is an option to synchronize POWERBUILDER system tables with actual table/column information.

Question 117


What is a validation rule? How PowerBuilder validation rule is different from the Database (validation) rules?

Answer


Validation rule specifies valid values for a specific column. It allows you to specify different valid values depending on the content of other columns. Validation rules defined in POWERBUILDER are used only POWERBUILDER clients. If another application connects to the database from Excel or Delphi, the database is not going to validate the data, since, the validation rule is not defined in the database. Please note that, the validation is done by POWERBUILDER not by the connected database. On the other hand, if you define the validation rule in the database, database will validate the value irrespective of the client type. In this case the validation is done by the connected database not by PowerBuilder.

 
Question 118

Explain different ways of executing a database stored procedure from PowerBuilder.

Answer


You can source the stored procedure to a DataWindow. You can also execute in the embedded and dynamic SQL. With version 5.0, you can declare a function for the stored procedure in the transaction object and execute the stored procedure as if you are executing a function.

Question 119


What is a proxy object and what is a remote object?

Answer


Proxy object represents the remote object in the distributed computing. Whenever you create a custom class user object, you can specify the proxy name. POWERBUILDER automatically saves the proxy object whenever you save user object. You place the actual user object in the server application and keep the proxy object in the client application. Before you act on the proxy object, you need to call SetConnect() function to connect to the server object.

Question 120


What is DDE?

Answer


DDE means Dynamic Data Exchange. This technology allows two different applications talk to each other under MS-Windows environment and exchange data between them.

Question 121


List few DDE related events.

Answer


'HotLinkAlarm', 'RemoteExec', 'RemoteHotlinkStart', 'RemoteHotlinkStop', 'RemoteRequest', 'RemoteSend'.

Question 122


What is the PowerBuilder object that has DDE related events?

Answer


Window

Question 123


What is difference between 'Cold Link' and 'Hot Link'?

Answer


In case of Hot link, the changed data is sent to the client automatically by the server. In case of 'Cold Link', the changed data is available to the DDE client only when it requests for that.

Question 124


What is the difference between 'In-Place editing' and 'Off-site editing'?

Answer


In case of 'Off-Site Editing', the OLE Server allows you editing in a separate window other than the OLE client application window. In case of 'In-Place Editing', the OLE server gets activated in the OLE Client application window and all the menu options will change accordingly. In this model, user feels that he is working in a single application even though he is using a different application.

 
Question 125

What is OCX control? Explain the required steps involved in CREATING an OCX control in PowerBuilder?

Answer


OCX is a OLE control which implements the component based architecture. You can use OCX control in any application that supports OLE 2.0. This increases the object reusability. You can use the OCX control in POWERBUILDER, but, you can't create a OCX control in POWERBUILDER in version 5.0.

Question 126


What is the difference between 'Embedding' and 'Linking' in the OLE context?

Answer


When you embed an object, the embedded object will be saved as part of the OLE container object. That means, any future changes to the actual object will not reflect in the embedded object. This also increases the storage requirement. Embedded object allows In-Place editing. In case of 'Linking', the original object resides where it was and a link information is stored in the OLE container object. That means, any future changes to the actual object will automatically reflect in the OLE container object. Linked objects are always invoked for editing off-site.

Question 127


What is 'AutoInstantiate' and where it is useful?

Answer


The user object that has 'AutoInstantiate' attribute turned on, will automatically creates an instance of that object whenever the object is declared. You need to use the CREATE statement to create the object after declaration when this property is not set. This attributes is available only for custom class user objects.

Question 128


What are the different places you can use OCX control in PowerBuilder?

Answer


You can use OCX control in a window, in a user object and in a DataWindow.

Question 129


Several times I heard 'Registry' in the technical meetings. What exactly 'Registry' is?

Answer


Registry is a MS-Windows database that contains information about each application. The application populates the information about it self using Windows API calls. Previously, application specific information such as application preferences, settings are stored in .INI file which is an ASCII file. Even though there was registry under MS-Windows 3.x, it wasn't really used by most of the applications and it was just used to store DDE and OLE specific information. The data is stored in the registry in the directory like hierarchy format.

Question 130


Explain the steps required to create a C++ user object in PowerBuilder?

Answer


Basically, you need to invoke the user object painter for C++ user object type. You need to declare any instance/shared variables and functions. While declaring functions, you just declare the function interface, not the function code. You need to write the actual code for functions in the C++ Editor which comes with POWERBUILDER. When you save the user object. POWERBUILDER automatically save the user object as a DLL and you need to deploy this DLL along with your application.

 
Question 131

We have migrated all our applications from Visual Basic to PowerBuilder. I would like to use those VBX controls, instead of re-coding in PowerBuilder. Is it possible? If Yes, are there any restrictions?

Answer


If you are using POWERBUILDER versions prior to 5.0, you can create a user object of type VBX and reuse your VBX control. The limitation is that, only Visual Basic v1.0 specific VBXes are supported by POWERBUILDER. In POWERBUILDER 5.0, you can't use VBX any more. Actually, it would be better stop using VBX and migrate to OCX which allows deploying your applications in 32-bit environment.

Question 132


The OCX control I planned to use has a 'Clicked' event. The OLE 2.0 control in PowerBuilder already has 'Clicked' event. What should I do?

Answer


When you are in the design mode, delete the duplicate events by selecting 'Declare/User Events' from the menu. This will solve the run-time problems.