Member Function Conventions
The names of the member functions of the SourcePro DB classes follow certain conventions.
*Functions that produce objects are named according to the object that is produced. In the example below, an RWDBDatabase produces an RWDBTable, and the RWDBTable produces an RWDBReader:
 
RWDBTable myTable = myDatabase.table("myTable");
RWDBReader rdr = myTable.reader();
*Functions that provide access to data members (accessors) get their names from the name of the data member, and take no arguments. Functions that set the value of a data member (mutators) also get their name from the data member, but require a single argument:
 
RWCString tableName = myTable.name(); // accessor
myTable.name("aNewName"); // mutator
*Functions that provide type conversions are called asType(), where Type is the name of the type you are converting to. Here we are converting an RWDBValue into an RWCString:
 
RWDBValue val;
cout << val.asString();
*Classes that are closely tied to SQL concepts often have member function names that suggest their SQL syntax. For example:
 
RWDBTable myTable = myDatabase.table("myTable"); //producer
RWDBSelector select = myDatabase.selector(); //producer
select.where(myTable["key"] == 100); // SQL "WHERE" clause
Finally, we have freely overloaded the extraction, or shift-out operator >>, and the insertion or shift-in operator <<. The insertion operator is used to add elements to objects sequentially; the extraction operator is used to remove elements from objects sequentially. Assume we have a parts table in a database, with columns partID, partName, and supplier, and the following piece of SQL code:
 
SELECT partID, partName
FROM parts
WHERE supplier = 'Acme Parts'
The following example implements this SQL code fragment in Interface Module code, then prints the results. Notice how the insertion and extraction operators are used on //1 and //2.
 
RWDBTable parts = myDatabase.table("parts");
RWDBSelector select = myDatabase.selector();
 
select << parts["partID"] << parts["partName"]; //1
select.where(parts["supplier"] == "Acme Parts");
 
long partID;RWCString partName;
 
RWDBReader reader = select.reader();
while(reader()) {
reader >> partID >> partName; //2
cout << partID << "\t" << partName << endl;
}
The insertion operators on //1 add parts.partID and parts.partName to the select list of the selector. The extraction operators on //2 take results from the reader and assign them to the local variables partID and partName.