Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends
mozSqlConnectionMysql Class Reference

#include <mozSqlConnectionMysql.h>

Inheritance diagram for mozSqlConnectionMysql:
Inheritance graph
[legend]
Collaboration diagram for mozSqlConnectionMysql:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 mozSqlConnectionMysql ()
virtual ~mozSqlConnectionMysql ()
NS_DECL_ISUPPORTS NS_IMETHOD Init (const nsAString &aHost, PRInt32 aPort, const nsAString &aDatabase, const nsAString &aUsername, const nsAString &aPassword)
NS_IMETHODIMP GetServerVersion (nsAString &aServerVersion)
NS_IMETHOD GetPrimaryKeys (const nsAString &aSchema, const nsAString &aTable, mozISqlResult **_retval)
void init (in AString aHost, in long aPort, in AString aDatabase, in AString aUsername, in AString aPassword)
 Set up the connection.
mozISqlResult executeQuery (in AString aQuery)
 Execute an SQL query synchronously and return the query result.
long executeUpdate (in AString aUpdate)
 Execute an SQL update synchronously and return the number of updated rows.
mozISqlRequest asyncExecuteQuery (in AString aQuery, in nsISupports aContext, in mozISqlRequestObserver aObserver)
 Execute an SQL query asynchronously and return a request.
mozISqlRequest asyncExecuteUpdate (in AString aQuery, in nsISupports aContext, in mozISqlRequestObserver aObserver)
 Execute an SQL update asynchronously and return a request.
void beginTransaction ()
 Begin a transaction.
void commitTransaction ()
 Commit the current transaction.
void rollbackTransaction ()
 Rollback (cancel) the current transaction.
mozISqlResult getPrimaryKeys (in AString aSchema, in AString aTable)
 Return the primary keys of a given table.
NS_IMETHOD Run ()=0
 Defines an entry point for a newly created thread.
void run ()

Public Attributes

NS_DECL_MOZISQLCONNECTIONMYSQL
MYSQL * 
mConnection
NS_DECL_ISUPPORTS
NS_DECL_MOZISQLCONNECTION
friend class 
mozSqlRequest
readonly attribute AString serverVersion
 A string holding the name and/or version info of the database.
readonly attribute AString errorMessage
 The most recent error message.
readonly attribute long lastID
 The ID of the most recently added record.

Protected Member Functions

virtual nsresult RealExec (const nsAString &aQuery, mozISqlResult **aResult, PRInt32 *aAffectedRows)
virtual nsresult CancelExec ()
virtual nsresult GetIDName (nsAString &aIDName)
nsresult CancelRequest (mozISqlRequest *aRequest)

Protected Attributes

nsString mServerVersion
nsString mErrorMessage
PRInt32 mLastID
PRLockmLock
PRCondVarmCondVar
PRLockmExecLock
nsCOMPtr< nsIThreadmThread
nsCOMArray< mozISqlRequestmRequests
nsCOMPtr< mozISqlRequestmCurrentRequest
PRBool mShutdown
PRBool mWaiting

Friends

class mozSqlResult

Detailed Description

Definition at line 51 of file mozSqlConnectionMysql.h.


Constructor & Destructor Documentation

Definition at line 40 of file mozSqlConnectionMysql.cpp.

Definition at line 45 of file mozSqlConnectionMysql.cpp.

{
  if (mConnection)
    mysql_close(mConnection);
}

Member Function Documentation

mozISqlRequest mozISqlConnection::asyncExecuteQuery ( in AString  aQuery,
in nsISupports  aContext,
in mozISqlRequestObserver  aObserver 
) [inherited]

Execute an SQL query asynchronously and return a request.

An observer may be used to track when the query has completed.

Parameters:
aQuerythe SQL string of the query to execute
aContextextra argument that will be passed to the observer
aObserverobserver that will be notified when the query is done
Returns:
a request object
mozISqlRequest mozISqlConnection::asyncExecuteUpdate ( in AString  aQuery,
in nsISupports  aContext,
in mozISqlRequestObserver  aObserver 
) [inherited]

Execute an SQL update asynchronously and return a request.

An observer may be used to track when the query has completed.

Parameters:
aQuerythe SQL string of the update to execute
aContextextra argument that will be passed to the observer
aObserverobserver that will be notified when the update is done
Returns:
a request object

Begin a transaction.

Updates made during the transaction will not be made permanent until it is committed using commitTransaction.

nsresult mozSqlConnectionMysql::CancelExec ( ) [protected, virtual]

Implements mozSqlConnection.

Definition at line 167 of file mozSqlConnectionMysql.cpp.

{
  unsigned long id = mysql_thread_id(mConnection);
  mysql_kill(mConnection, id);

  if (mysql_errno(mConnection)) {
    mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));
    return NS_ERROR_FAILURE;
  }

  mysql_ping(mConnection);

  return NS_OK;
}
nsresult mozSqlConnection::CancelRequest ( mozISqlRequest aRequest) [protected, inherited]

Definition at line 263 of file mozSqlConnection.cpp.

{
  PR_Lock(mLock);
  if (mCurrentRequest == aRequest)
    CancelExec();
  else {
    if (mRequests.RemoveObject(aRequest))
      ((mozSqlRequest*)aRequest)->mStatus = mozISqlRequest::STATUS_CANCELLED;
  }
  PR_Unlock(mLock);

  return NS_OK;
}

Here is the call graph for this function:

Commit the current transaction.

mozISqlResult mozISqlConnection::executeQuery ( in AString  aQuery) [inherited]

Execute an SQL query synchronously and return the query result.

Parameters:
aQuerythe SQL string of the query to execute
Returns:
the result of the query
long mozISqlConnection::executeUpdate ( in AString  aUpdate) [inherited]

Execute an SQL update synchronously and return the number of updated rows.

Parameters:
aUpdatethe update to execute
Returns:
the result of the query
nsresult mozSqlConnectionMysql::GetIDName ( nsAString &  aIDName) [protected, virtual]

Implements mozSqlConnection.

Definition at line 183 of file mozSqlConnectionMysql.cpp.

{
  aIDName.Truncate();

  return NS_OK;
}
NS_IMETHODIMP mozSqlConnectionMysql::GetPrimaryKeys ( const nsAString &  aSchema,
const nsAString &  aTable,
mozISqlResult **  _retval 
)

Definition at line 105 of file mozSqlConnectionMysql.cpp.

{
  // XXX this can be done with 'show columns from <table>', but it can't be
  //     filtered just for primary keys, which are listed in column 3

  return NS_ERROR_NOT_IMPLEMENTED;
}
mozISqlResult mozISqlConnection::getPrimaryKeys ( in AString  aSchema,
in AString  aTable 
) [inherited]

Return the primary keys of a given table.

Parameters:
aSchemathe schema
aTablethe table name of the keys to retrieve
Returns:
the result which holds the keys
NS_IMETHODIMP mozSqlConnectionMysql::GetServerVersion ( nsAString &  aServerVersion)

Definition at line 91 of file mozSqlConnectionMysql.cpp.

{
  if (!mConnection)
    return NS_ERROR_NOT_INITIALIZED;

  if (mServerVersion.IsEmpty()){
    mServerVersion.Assign(NS_ConvertUTF8toUCS2(mysql_get_server_info(mConnection)));
  }
  aServerVersion.Assign(mServerVersion);

  return NS_OK;
}
NS_IMETHODIMP mozSqlConnectionMysql::Init ( const nsAString &  aHost,
PRInt32  aPort,
const nsAString &  aDatabase,
const nsAString &  aUsername,
const nsAString &  aPassword 
)

Definition at line 60 of file mozSqlConnectionMysql.cpp.

{
  if (mConnection)
    return NS_OK;

  if (aPort == -1)
    aPort = 0;

  mConnection = mysql_init((MYSQL *) nsnull);
  if (!mConnection){
    return NS_ERROR_FAILURE;
  }

  if (!mysql_real_connect(mConnection, 
                          NS_ConvertUCS2toUTF8(aHost).get(),
                          NS_ConvertUCS2toUTF8(aUsername).get(),
                          NS_ConvertUCS2toUTF8(aPassword).get(),
                          NS_ConvertUCS2toUTF8(aDatabase).get(),
                          aPort, nsnull, 0)){
    mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));
    mConnection = nsnull;

    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}
void mozISqlConnection::init ( in AString  aHost,
in long  aPort,
in AString  aDatabase,
in AString  aUsername,
in AString  aPassword 
) [inherited]

Set up the connection.

This is called by the SQL service. There is no need to call this method directly.

Parameters:
aHostthe host name.
aPortthe port at which the host is listening.
aDatabasethe real database name to connect to.
aUsernamethe username to connect as.
aPasswordthe password to use in authentification phase.
nsresult mozSqlConnectionMysql::RealExec ( const nsAString &  aQuery,
mozISqlResult **  aResult,
PRInt32 aAffectedRows 
) [protected, virtual]

Implements mozSqlConnection.

Definition at line 116 of file mozSqlConnectionMysql.cpp.

{
  if (!mConnection)
    return NS_ERROR_NOT_INITIALIZED;

  if (mysql_query(mConnection, NS_ConvertUCS2toUTF8(aQuery).get())){
    mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));

    return NS_ERROR_FAILURE;
  }

  if (!aResult){
    if (!aAffectedRows)
      return NS_ERROR_NULL_POINTER;

    my_ulonglong numrows = (PRInt32)mysql_affected_rows(mConnection);
    *aAffectedRows = ((numrows == (my_ulonglong)-1) ? 0 : (PRInt32)numrows);

    return NS_OK;
  }
  
  *aResult = nsnull;

  MYSQL_RES *rowresults = mysql_store_result(mConnection);
  if (!rowresults){
    mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));

    return NS_ERROR_FAILURE;
  }

  mozSqlResult *mozresult = new mozSqlResultMysql(this, aQuery);
  if (!mozresult){
    mysql_free_result(rowresults);
    return NS_ERROR_OUT_OF_MEMORY;
  }

  ((mozSqlResultMysql*)mozresult)->SetResult(rowresults);
  nsresult rv = mozresult->Init();
  if (NS_FAILED(rv)){
    delete mozresult;
    return rv;
  }

  *aResult = mozresult;
  NS_ADDREF(*aResult);

  return NS_OK;
}

Here is the call graph for this function:

Rollback (cancel) the current transaction.

void nsIRunnable::run ( ) [inherited]
NS_IMETHOD nsIRunnable::Run ( ) [pure virtual, inherited]

Friends And Related Function Documentation

friend class mozSqlResult [friend, inherited]

Definition at line 64 of file mozSqlConnection.h.


Member Data Documentation

readonly attribute AString mozISqlConnection::errorMessage [inherited]

The most recent error message.

Definition at line 63 of file mozISqlConnection.idl.

The ID of the most recently added record.

Definition at line 68 of file mozISqlConnection.idl.

PRCondVar* mozSqlConnection::mCondVar [protected, inherited]

Definition at line 79 of file mozSqlConnection.h.

NS_DECL_MOZISQLCONNECTIONMYSQL MYSQL* mozSqlConnectionMysql::mConnection

Definition at line 70 of file mozSqlConnectionMysql.h.

Definition at line 83 of file mozSqlConnection.h.

nsString mozSqlConnection::mErrorMessage [protected, inherited]

Definition at line 75 of file mozSqlConnection.h.

PRLock* mozSqlConnection::mExecLock [protected, inherited]

Definition at line 80 of file mozSqlConnection.h.

PRInt32 mozSqlConnection::mLastID [protected, inherited]

Definition at line 76 of file mozSqlConnection.h.

PRLock* mozSqlConnection::mLock [protected, inherited]

Definition at line 78 of file mozSqlConnection.h.

NS_DECL_ISUPPORTS NS_DECL_MOZISQLCONNECTION friend class mozSqlConnection::mozSqlRequest [inherited]

Definition at line 63 of file mozSqlConnection.h.

Definition at line 82 of file mozSqlConnection.h.

Definition at line 74 of file mozSqlConnection.h.

PRBool mozSqlConnection::mShutdown [protected, inherited]

Definition at line 84 of file mozSqlConnection.h.

nsCOMPtr<nsIThread> mozSqlConnection::mThread [protected, inherited]

Definition at line 81 of file mozSqlConnection.h.

PRBool mozSqlConnection::mWaiting [protected, inherited]

Definition at line 85 of file mozSqlConnection.h.

readonly attribute AString mozISqlConnection::serverVersion [inherited]

A string holding the name and/or version info of the database.

Definition at line 58 of file mozISqlConnection.idl.


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