KjwMsSql Class Reference
[Database (SQL) handling]

KjwMsSql is the mssql implementation of the KjwSql abstract class. More...

Inheritance diagram for KjwMsSql:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 KjwMsSql ($hostname, $portnum, $username, $password, $database)
 Construct a KjwMsSql object.
 destroy ()
 Destructor performing cleanup.
 connect ()
 Connect to the SQL server.
 disconnect ()
 Disconnect from the SQL server.
 beginWork ()
 Begin a transaction / atomic operation.
 execute ($query)
 Execute a query.
 executeLowLevel ($query)
 A variant on the execute() method that does not reset/reselect the database and does not set the last_insert_id or error messages.
 _execute_1 ($query)
 Low level execute method internals, part 1.
 _execute_2 ($query)
 Low level execute method internals, part 2.
 _execute_3 ($query)
 Low level execute method internals, part 3.
 _execute_4 ($sybase_result, $is_insert_update, $is_select)
 Low level execute method internals, part 4.
 safeQuote ($mixed)
 Makes sure that any variable is quoted like its correct type should be.
 nameQuote ($string)
 Quote a name for an object (column or table).
 affectedRows ()
 How many rows were affected (touched) by the last INSERT, UPDATE, REPLACE or DELETE query.
 insertId ()
 Returns the id of the last INSERT clause that uses an IDENTITY/SEQUENCE/AUTO_INCREMENT value.
 getLastMessage ()
 Returns the last info/error messages as a string.
 _clearLastMessage ()
 Clear stored messages.
 _messageHandler ($message, $severity, $state, $lineNumber, $description)
 Message handler.

Public Attributes

 $_dbconn
 Database resource.
 $_quotedDbname
 Database name, quoted.
 $_insertId
 Insert ID / Identity ID of last query (insert/update).
 $_affectedRows
 Count of rows affected with last query (insert/update).
 $_messages
 Server error messages.


Detailed Description

KjwMsSql is the mssql implementation of the KjwSql abstract class.

Uses the KJW_DIE_ON_TRANSIENT_ERROR define.

Todo:
Currently, you need to use executeLowLevel if you're using USE <new_database>. Should fix so execute "sees" it as well, and update own $database.

Definition at line 34 of file KjwMsSql.php.


Member Function Documentation

KjwMsSql::_clearLastMessage (  ) 

Clear stored messages.

Used internally only.

Definition at line 305 of file KjwMsSql.php.

Referenced by _execute_3().

KjwMsSql::_execute_1 ( query  ) 

Low level execute method internals, part 1.

Parameters:
$query The query to execute.
Returns:
Whether we're connected to the database, boolean.

Definition at line 172 of file KjwMsSql.php.

References KjwSql::_setLastQuery(), and connect().

Referenced by execute(), and executeLowLevel().

KjwMsSql::_execute_2 ( query  ) 

Low level execute method internals, part 2.

Parameters:
$query The query to execute.
Returns:
An updated query string, whether the query is an insert/update and whether the query is a select.

Definition at line 188 of file KjwMsSql.php.

Referenced by execute().

KjwMsSql::_execute_3 ( query  ) 

Low level execute method internals, part 3.

Parameters:
$query The query to execute.
Returns:
A sybase result resource, this can be a boolean as well.

Definition at line 216 of file KjwMsSql.php.

References _clearLastMessage(), KjwSql::_getLastQuery(), KjwObject::croak(), and getLastMessage().

Referenced by execute(), and executeLowLevel().

KjwMsSql::_execute_4 ( sybase_result,
is_insert_update,
is_select 
)

Low level execute method internals, part 4.

Parameters:
$sybase_result A sybase resource.
$is_insert_update True if the query was an insert or update statement.
$is_select True if the query was a select statement.
Returns:
A KjwSqlResultSet (KjwSqlMsResultSet).

Definition at line 241 of file KjwMsSql.php.

Referenced by execute().

KjwMsSql::_messageHandler ( message,
severity,
state,
lineNumber,
description 
)

Message handler.

We need to use this because the sybase_get_last_message stores only the latest message in a series of messages. Could be semi-private.. no one should reference it by name, but others should call it because it is a callback.

sybase_min_client_severity and sybase_min_server_severity decide which messages get passed to this callback.

Parameters:
$message The error number.
$severity The error severity (integer, likely 10 or above).
$state Some kind of state (what\?).
$lineNumber Line number.
$description The error message as a string.

Definition at line 324 of file KjwMsSql.php.

KjwMsSql::affectedRows (  ) 

How many rows were affected (touched) by the last INSERT, UPDATE, REPLACE or DELETE query.

It's unspecified if an UPDATE count includes updates that weren't actual changes. I.e. either the WHERE-match-count is returned, or only the subset where the update was a change.

Returns:
The number of rows affected.
Note:
Don't try to be funny and do SELECT or whatever queries before calling this.

Reimplemented from KjwSql.

Definition at line 279 of file KjwMsSql.php.

KjwMsSql::connect (  ) 

Connect to the SQL server.

Returns:
True.
Todo:
Put timing on connect, so we don't have to wait 60secs on firewalled server.

Reimplemented from KjwSql.

Definition at line 67 of file KjwMsSql.php.

References $kjw_suppressed_error, KjwObject::croak(), KjwObject::getError(), getLastMessage(), nameQuote(), and KjwObject::setError().

Referenced by _execute_1().

KjwMsSql::destroy (  ) 

Destructor performing cleanup.

Don't rely on this being called ever. The user must call it by hand.

Reimplemented from KjwSql.

Definition at line 61 of file KjwMsSql.php.

References disconnect().

KjwMsSql::disconnect (  ) 

Disconnect from the SQL server.

Returns:
Success boolean.

Reimplemented from KjwSql.

Definition at line 109 of file KjwMsSql.php.

Referenced by destroy().

KjwMsSql::execute ( query  ) 

Execute a query.

Parameters:
$query The query to execute.
Returns:
Returns a boolean specifying success or a KjwResult object on a select/show/describe/explain.

Reimplemented from KjwSql.

Definition at line 124 of file KjwMsSql.php.

References _execute_1(), _execute_2(), _execute_3(), and _execute_4().

Referenced by beginWork().

KjwMsSql::executeLowLevel ( query  ) 

A variant on the execute() method that does not reset/reselect the database and does not set the last_insert_id or error messages.

The normal execute does extra stuff to keep the behaviour compatible with the KjwSql standard. This one does not. You'll have to live with sybase_* and T-SQL specific weirdness.

If you use "USE <database>" statements in your queries, you want to use this one. *Note* *that* *you* *cannot* *use* *multiple* *KjwSql* *objects* *safely* when you're using this function. This one is perfect for executing a batch of create statements.

Parameters:
$query The query to execute.
Returns:
A success boolean, no resultset is ever returned.

Definition at line 152 of file KjwMsSql.php.

References _execute_1(), and _execute_3().

KjwMsSql::getLastMessage (  ) 

Returns the last info/error messages as a string.

Returns:
A message.

Definition at line 298 of file KjwMsSql.php.

Referenced by _execute_3(), and connect().

KjwMsSql::insertId (  ) 

Returns the id of the last INSERT clause that uses an IDENTITY/SEQUENCE/AUTO_INCREMENT value.

Returns:
The new id.
Note:
Don't try to be funny and do SELECT or whatever queries before calling this.

Reimplemented from KjwSql.

Definition at line 288 of file KjwMsSql.php.

KjwMsSql::KjwMsSql ( hostname,
portnum,
username,
password,
database 
)

Construct a KjwMsSql object.

Parameters:
$hostname Server name or IP.
$portnum Port number of 0 if default.
$username User name.
$password Password.
$database Database name.

Definition at line 50 of file KjwMsSql.php.

References KjwSql::KjwSql(), and nameQuote().

KjwMsSql::nameQuote ( string  ) 

Quote a name for an object (column or table).

For MySQL this would be by surrounding the name with backticks.

Parameters:
$string An identifier (column or table name) to be quoted.
Returns:
The quoted identifier.

Reimplemented from KjwSql.

Definition at line 273 of file KjwMsSql.php.

Referenced by connect(), and KjwMsSql().

KjwMsSql::safeQuote ( mixed  ) 

Makes sure that any variable is quoted like its correct type should be.

Integers and booleans are returned as integers. Strings are returned as quoted strings with all quotes escaped. If the escaping mechanism is not known, all <32 and >127 characters REMOVED, otherwise the escaping for the specific database make is used.

Parameters:
$mixed The variable that needs to be returned as a safe entity.
Returns:
A quoted/escaped entity.

Reimplemented from KjwSql.

Definition at line 262 of file KjwMsSql.php.


Member Data Documentation

KjwMsSql::$_affectedRows

Count of rows affected with last query (insert/update).

Definition at line 38 of file KjwMsSql.php.

KjwMsSql::$_insertId

Insert ID / Identity ID of last query (insert/update).

Definition at line 37 of file KjwMsSql.php.


The documentation for this class was generated from the following file:

Generated on Wed Apr 8 22:16:35 2009 for KjwLib-php45 by  doxygen 1.5.8