Compare commits
2 Commits
SQL_ADDON_
...
mozilla
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a637f81f7f | ||
|
|
6cfadae5d1 |
@@ -1,19 +0,0 @@
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
base \
|
||||
pgsql \
|
||||
build
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += \
|
||||
sqltest \
|
||||
tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,11 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
DIRS = \
|
||||
public \
|
||||
src \
|
||||
resources
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,19 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = sql
|
||||
|
||||
XPIDLSRCS = \
|
||||
mozISqlConnection.idl \
|
||||
mozISqlRequest.idl \
|
||||
mozISqlDataSource.idl \
|
||||
mozISqlInputStream.idl \
|
||||
mozISqlRequestObserver.idl \
|
||||
mozISqlResult.idl \
|
||||
mozISqlResultEnumerator.idl \
|
||||
mozISqlService.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,124 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlResult;
|
||||
interface mozISqlRequest;
|
||||
interface mozISqlRequestObserver;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(f16397a4-1ecb-4e08-84f8-27750c04b779)]
|
||||
interface mozISqlConnection : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute AString serverVersion;
|
||||
|
||||
/**
|
||||
* The most recent error message.
|
||||
*/
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
/**
|
||||
* The ID of the most recently added record.
|
||||
*/
|
||||
readonly attribute long lastID;
|
||||
|
||||
/**
|
||||
* Set up the connection.
|
||||
*
|
||||
* @param aHost The host name.
|
||||
* @param aPort The port at which the host is listening.
|
||||
* @param aDatabase The real database name to connect to.
|
||||
* @param aUsername The username to connect as.
|
||||
* @param aPassword The password to use in authentification phase.
|
||||
*/
|
||||
void init(in AString aHost,
|
||||
in long aPort,
|
||||
in AString aDatabase,
|
||||
in AString aUsername,
|
||||
in AString aPassword);
|
||||
|
||||
/**
|
||||
* Execute the query synchronously and return database result.
|
||||
*
|
||||
* @param aQuery The query to execute.
|
||||
*/
|
||||
mozISqlResult executeQuery(in AString aQuery);
|
||||
|
||||
/**
|
||||
* Execute the update synchronously and return number of updated rows.
|
||||
*
|
||||
* @param aUpdate The update to execute.
|
||||
*/
|
||||
long executeUpdate(in AString aUpdate);
|
||||
|
||||
mozISqlRequest asyncExecuteQuery(in AString aQuery,
|
||||
in nsISupports aContext,
|
||||
in mozISqlRequestObserver aObserver);
|
||||
|
||||
mozISqlRequest asyncExecuteUpdate(in AString aQuery,
|
||||
in nsISUpports aContext,
|
||||
in mozISqlRequestObserver aObserver);
|
||||
|
||||
/**
|
||||
* Begin transaction.
|
||||
*/
|
||||
void beginTransaction();
|
||||
|
||||
/**
|
||||
* Commit transaction.
|
||||
*/
|
||||
void commitTransaction();
|
||||
|
||||
/**
|
||||
* Rollback transaction.
|
||||
*/
|
||||
void rollbackTransaction();
|
||||
|
||||
/**
|
||||
* Get primary keys.
|
||||
*
|
||||
* @param aSchema The schema.
|
||||
* @param aTable The table name.
|
||||
*/
|
||||
mozISqlResult getPrimaryKeys(in AString aSchema, in AString aTable);
|
||||
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIRDFResource;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(3c0a954f-b595-46a4-932c-3660f55e2e10)]
|
||||
interface mozISqlDataSource : nsISupports
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieve the RDF resource associated with the specified row.
|
||||
*
|
||||
* @param aRowIndex The row index.
|
||||
*/
|
||||
|
||||
nsIRDFResource getResourceAtIndex(in long aRowIndex);
|
||||
|
||||
/**
|
||||
* Retrieve the index associated with specified RDF resource.
|
||||
*
|
||||
* @param aResource The resource.
|
||||
*/
|
||||
long getIndexOfResource(in nsIRDFResource aResource);
|
||||
|
||||
};
|
||||
@@ -1,52 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(555f2485-ba82-4c5c-9dd2-d801104dc09e)]
|
||||
interface mozISqlInputStream : nsISupports
|
||||
{
|
||||
|
||||
AString getColumnHeader(in long aColumnIndex);
|
||||
|
||||
void setColumnHeader(in long aColumnIndex, in AString aLabel);
|
||||
|
||||
};
|
||||
@@ -1,77 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlConnection;
|
||||
interface mozISqlRequestObserver;
|
||||
interface mozISqlResult;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(f67cb817-5e07-49ff-aacc-5c80585c5031)]
|
||||
interface mozISqlRequest : nsISupports
|
||||
{
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
readonly attribute mozISqlResult result;
|
||||
|
||||
readonly attribute long affectedRows;
|
||||
|
||||
readonly attribute long lastID;
|
||||
|
||||
|
||||
readonly attribute AString query;
|
||||
|
||||
readonly attribute nsISupports ctxt;
|
||||
|
||||
readonly attribute mozISqlRequestObserver observer;
|
||||
|
||||
|
||||
const long STATUS_NONE = 0;
|
||||
const long STATUS_EXECUTED = 1;
|
||||
const long STATUS_COMPLETE = 2;
|
||||
const long STATUS_ERROR = 3;
|
||||
const long STATUS_CANCELLED = 4;
|
||||
|
||||
readonly attribute long status;
|
||||
|
||||
void cancel();
|
||||
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlRequest;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(9e950bc0-e252-41ef-ac6f-3e3c4acd9dd8)]
|
||||
interface mozISqlRequestObserver : nsISupports
|
||||
{
|
||||
|
||||
void onStartRequest(in mozISqlRequest aRequest,
|
||||
in nsISupports aContext);
|
||||
|
||||
void onStopRequest(in mozISqlRequest aRequest,
|
||||
in nsISupports aContext);
|
||||
|
||||
};
|
||||
@@ -1,87 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlConnection;
|
||||
interface mozISqlResultEnumerator;
|
||||
interface mozISqlInputStream;
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(08c220b0-7140-456a-89e9-c94609a7392d)]
|
||||
interface mozISqlResult : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute mozISqlConnection connection;
|
||||
|
||||
readonly attribute AString query;
|
||||
|
||||
readonly attribute AString tableName;
|
||||
|
||||
readonly attribute long rowCount;
|
||||
|
||||
readonly attribute long columnCount;
|
||||
|
||||
AString getColumnName(in long aColumnIndex);
|
||||
|
||||
long getColumnIndex(in AString aColumnName);
|
||||
|
||||
const long TYPE_STRING = 1;
|
||||
const long TYPE_INT = 2;
|
||||
const long TYPE_FLOAT = 3;
|
||||
const long TYPE_DECIMAL = 4;
|
||||
const long TYPE_DATE = 5;
|
||||
const long TYPE_TIME = 6;
|
||||
const long TYPE_DATETIME = 7;
|
||||
const long TYPE_BOOL = 8;
|
||||
|
||||
long getColumnType(in long aColumnIndex);
|
||||
|
||||
AString getColumnTypeAsString(in long aColumnIndex);
|
||||
|
||||
long getColumnDisplaySize(in long aColumnIndex);
|
||||
|
||||
mozISqlResultEnumerator enumerate();
|
||||
|
||||
mozISqlInputStream open();
|
||||
|
||||
void reload();
|
||||
|
||||
};
|
||||
@@ -1,126 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIVariant;
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(dcc0d29e-2b44-460e-b39f-89121ff8b963)]
|
||||
interface mozISqlResultEnumerator : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
boolean next();
|
||||
|
||||
boolean previous();
|
||||
|
||||
void beforeFirst();
|
||||
|
||||
void first();
|
||||
|
||||
void last();
|
||||
|
||||
void relative(in long aRows);
|
||||
|
||||
void absolute(in long aRowIndex);
|
||||
|
||||
|
||||
boolean isNull(in long aColumnIndex);
|
||||
|
||||
nsIVariant getVariant(in long aColumnIndex);
|
||||
|
||||
AString getString(in long aColumnIndex);
|
||||
|
||||
long getInt(in long aColumnIndex);
|
||||
|
||||
float getFloat(in long aColumnIndex);
|
||||
|
||||
float getDecimal(in long aColumnIndex);
|
||||
|
||||
long long getDate(in long aColumnIndex);
|
||||
|
||||
boolean getBool(in long aColumnIndex);
|
||||
|
||||
|
||||
void setNull(in long aColumnIndex);
|
||||
|
||||
void setDefault(in long aColumnIndex);
|
||||
|
||||
void copy(in long aColumnIndex);
|
||||
|
||||
void setVariant(in long aColumnIndex, in nsIVariant aValue);
|
||||
|
||||
void setString(in long aColumnIndex, in AString aValue);
|
||||
|
||||
void setInt(in long aColumnIndex, in long aValue);
|
||||
|
||||
void setFloat(in long aColumnIndex, in float aValue);
|
||||
|
||||
void setDecimal(in long aColumnIndex, in float aValue);
|
||||
|
||||
void setDate(in long aColumnIndex, in long long aValue);
|
||||
|
||||
void setBool(in long aColumnIndex, in boolean aValue);
|
||||
|
||||
|
||||
void setNullValues();
|
||||
|
||||
void setDefaultValues();
|
||||
|
||||
void copyValues();
|
||||
|
||||
|
||||
boolean canInsert();
|
||||
|
||||
boolean canUpdate();
|
||||
|
||||
boolean canDelete();
|
||||
|
||||
long insertRow();
|
||||
|
||||
long updateRow();
|
||||
|
||||
long deleteRow();
|
||||
|
||||
readonly attribute AString currentCondition;
|
||||
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlConnection;
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(1ceb35b7-daa8-4ce4-ac67-125fb17cb019)]
|
||||
interface mozISqlService : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
void addAlias(in ACString aURI,
|
||||
in AString aName,
|
||||
in AString aType,
|
||||
in AString aHostname,
|
||||
in long aPort,
|
||||
in AString aDatabase);
|
||||
|
||||
boolean hasAlias(in ACString aURI);
|
||||
|
||||
void getAlias(in ACString aURI,
|
||||
out AString aName,
|
||||
out AString aType,
|
||||
out AString aHostname,
|
||||
out long aPort,
|
||||
out AString aDatabase);
|
||||
|
||||
void updateAlias(in ACString aURI,
|
||||
in AString aName,
|
||||
in AString aType,
|
||||
in AString aHostname,
|
||||
in long aPort,
|
||||
in AString aDatabase);
|
||||
|
||||
void removeAlias(in ACString aURI);
|
||||
|
||||
mozISqlConnection getConnection(in ACString aURI);
|
||||
|
||||
mozISqlConnection getNewConnection(in ACString aURI);
|
||||
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,39 +0,0 @@
|
||||
var sqlService = null;
|
||||
|
||||
var name;
|
||||
var type;
|
||||
var hostname;
|
||||
var port;
|
||||
var database;
|
||||
|
||||
function init() {
|
||||
sqlService = Components.classes["@mozilla.org/sql/service;1"]
|
||||
.getService(Components.interfaces.mozISqlService);
|
||||
|
||||
name = document.getElementById("name");
|
||||
type = document.getElementById("type");
|
||||
hostname = document.getElementById("hostname");
|
||||
port = document.getElementById("port");
|
||||
database = document.getElementById("database");
|
||||
|
||||
if (window.arguments) {
|
||||
// get original values
|
||||
var uri = window.arguments[0];
|
||||
sqlService.getAlias(uri, name, type, hostname, port, database);
|
||||
}
|
||||
}
|
||||
|
||||
function onAccept() {
|
||||
if (window.arguments) {
|
||||
// update an existing alias
|
||||
var uri = window.arguments[0];
|
||||
sqlService.updateAlias(uri, name.value, type.value, hostname.value,
|
||||
port.value, database.value);
|
||||
}
|
||||
else {
|
||||
// add a new database
|
||||
var uri = "urn:aliases:" + name.value;
|
||||
sqlService.addAlias(uri, name.value, type.value, hostname.value,
|
||||
port.value, database.value);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://sql/locale/aliasDialog.dtd">
|
||||
|
||||
<dialog id="aliasDialog"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&window.title;"
|
||||
width="250" height="180"
|
||||
buttons="accept,cancel" buttonpack="center"
|
||||
ondialogaccept="return onAccept(event);"
|
||||
onload="init()">
|
||||
|
||||
<script type="application/x-javascript" src="aliasDialog.js"/>
|
||||
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="&name.label;"/>
|
||||
<textbox id="name"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&type.label;"/>
|
||||
<textbox id="type"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&hostname.label;"/>
|
||||
<textbox id="hostname"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&port.label;"/>
|
||||
<textbox id="port"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&database.label;"/>
|
||||
<textbox id="database"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
</dialog>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the packages being supplied by this jar -->
|
||||
<RDF:Seq about="urn:mozilla:package:root">
|
||||
<RDF:li resource="urn:mozilla:package:sql"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- package information -->
|
||||
<RDF:Description about="urn:mozilla:package:sql"
|
||||
chrome:displayName="SQL support"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:authorURL="http://www.mozilla.org/projects/sql/index.html"
|
||||
chrome:name="sql"
|
||||
chrome:extension="true"
|
||||
chrome:settingsURL="chrome://sql/content/sqlSettings.xul"
|
||||
chrome:description="Allow applications to directly connect to SQL databases.">
|
||||
</RDF:Description>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,36 +0,0 @@
|
||||
var sqlService = null;
|
||||
|
||||
function getSqlService() {
|
||||
if (! sqlService)
|
||||
sqlService = Components.classes["@mozilla.org/sql/service;1"]
|
||||
.getService(Components.interfaces.mozISqlService);
|
||||
return sqlService;
|
||||
}
|
||||
|
||||
function getSelectedAlias() {
|
||||
var tree = document.getElementById("aliasesTree");
|
||||
return tree.builderView.getResourceAtIndex(tree.currentIndex).Value;
|
||||
}
|
||||
|
||||
function updateButtons() {
|
||||
var tree = document.getElementById("aliasesTree");
|
||||
const buttons = ["updateButton", "removeButton"];
|
||||
for (i = 0; i < buttons.length; i++)
|
||||
document.getElementById(buttons[i]).disabled = tree.currentIndex < 0;
|
||||
}
|
||||
|
||||
function addAlias() {
|
||||
window.openDialog("aliasDialog.xul", "addAlias", "chrome,modal=yes,resizable=no,centerscreen");
|
||||
}
|
||||
|
||||
function updateAlias() {
|
||||
var alias = getSelectedAlias();
|
||||
window.openDialog("aliasDialog.xul", "updateDatabase", "chrome,modal=yes,resizable=no,centerscreen", alias);
|
||||
}
|
||||
|
||||
function removeAlias() {
|
||||
var sqlService = getSqlService();
|
||||
var alias = getSelectedAlias();
|
||||
sqlService.removeAlias(alias);
|
||||
updateButtons();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://sql/locale/sqlSettings.dtd">
|
||||
|
||||
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&header.label;"
|
||||
width="450" height="350">
|
||||
|
||||
<script type="application/x-javascript" src="sqlSettings.js"/>
|
||||
|
||||
<groupbox flex="1">
|
||||
<caption label="&aliases.label;"/>
|
||||
<hbox flex="1">
|
||||
<tree id="aliasesTree" flex="1"
|
||||
seltype="single"
|
||||
datasources="rdf:sql" ref="SQL:AliasesRoot" flags="dont-build-content"
|
||||
onselect="updateButtons()">
|
||||
<treecols>
|
||||
<treecol id="nameCol" flex="1" label="&nameCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#name"
|
||||
sortActive="true" sortDirection="ascending"/>
|
||||
<treecol id="typeCol" flex="1" label="&typeCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#type"/>
|
||||
<treecol id="hostnameCol" flex="1" label="&hostnameCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#hostname"/>
|
||||
<treecol id="portCol" flex="1" label="&portCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#port"/>
|
||||
<treecol id="databaseCol" flex="1" label="&databaseCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#database"/>
|
||||
</treecols>
|
||||
<template>
|
||||
<treechildren>
|
||||
<treeitem uri="rdf:*">
|
||||
<treerow>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#type"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#hostname"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#port"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#database"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
</template>
|
||||
</tree>
|
||||
<vbox>
|
||||
<button id="addButton" label="&add.label;" oncommand="addAlias()"/>
|
||||
<button id="updateButton" label="&update.label;" disabled="true" oncommand="updateAlias()"/>
|
||||
<button id="removeButton" label="&remove.label;" disabled="true" oncommand="removeAlias()"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
|
||||
</dialog>
|
||||
@@ -1,9 +0,0 @@
|
||||
sql.jar:
|
||||
content/sql/contents.rdf (content/contents.rdf)
|
||||
content/sql/sqlSettings.xul (content/sqlSettings.xul)
|
||||
content/sql/sqlSettings.js (content/sqlSettings.js)
|
||||
content/sql/aliasDialog.xul (content/aliasDialog.xul)
|
||||
content/sql/aliasDialog.js (content/aliasDialog.js)
|
||||
locale/en-US/sql/contents.rdf (locale/en-US/contents.rdf)
|
||||
locale/en-US/sql/sqlSettings.dtd (locale/en-US/sqlSettings.dtd)
|
||||
locale/en-US/sql/aliasDialog.dtd (locale/en-US/aliasDialog.dtd)
|
||||
@@ -1,7 +0,0 @@
|
||||
<!ENTITY window.title "Alias">
|
||||
|
||||
<!ENTITY name.label "Name:">
|
||||
<!ENTITY type.label "Type:">
|
||||
<!ENTITY hostname.label "Hostname:">
|
||||
<!ENTITY port.label "Port:">
|
||||
<!ENTITY database.label "Database:">
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the locales being supplied by this package -->
|
||||
<RDF:Seq about="urn:mozilla:locale:root">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- locale information -->
|
||||
<RDF:Description about="urn:mozilla:locale:en-US"
|
||||
chrome:displayName="English(US)"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:name="en-US"
|
||||
chrome:previewURL="http://www.mozilla.org/locales/en-US.gif">
|
||||
<chrome:packages>
|
||||
<RDF:Seq about="urn:mozilla:locale:en-US:packages">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US:sql"/>
|
||||
</RDF:Seq>
|
||||
</chrome:packages>
|
||||
</RDF:Description>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,12 +0,0 @@
|
||||
<!ENTITY header.label "SQL support">
|
||||
|
||||
<!ENTITY aliases.label "Aliases">
|
||||
<!ENTITY nameCol.label "Name">
|
||||
<!ENTITY typeCol.label "Type">
|
||||
<!ENTITY hostnameCol.label "Hostname">
|
||||
<!ENTITY portCol.label "Port">
|
||||
<!ENTITY databaseCol.label "Database">
|
||||
|
||||
<!ENTITY add.label "Add alias">
|
||||
<!ENTITY update.label "Update alias">
|
||||
<!ENTITY remove.label "Remove alias">
|
||||
@@ -1,33 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = sql
|
||||
LIBRARY_NAME = sqlbase_s
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
unicharutil \
|
||||
locale \
|
||||
necko \
|
||||
rdf \
|
||||
windowwatcher \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozSqlConnection.cpp \
|
||||
mozSqlRequest.cpp \
|
||||
mozSqlResult.cpp \
|
||||
mozSqlService.cpp
|
||||
|
||||
EXPORTS = \
|
||||
mozSqlConnection.h \
|
||||
mozSqlRequest.h \
|
||||
mozSqlResult.h \
|
||||
mozSqlService.h
|
||||
|
||||
FORCE_STATIC_LIB=1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,237 +0,0 @@
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "mozSqlRequest.h"
|
||||
#include "mozSqlConnection.h"
|
||||
|
||||
mozSqlConnection::mozSqlConnection()
|
||||
: mLock(nsnull),
|
||||
mCondVar(nsnull),
|
||||
mThread(nsnull),
|
||||
mShutdown(PR_FALSE),
|
||||
mWaiting(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mExecLock = PR_NewLock();
|
||||
}
|
||||
|
||||
mozSqlConnection::~mozSqlConnection()
|
||||
{
|
||||
mRequests.Clear();
|
||||
|
||||
if (mCondVar)
|
||||
PR_DestroyCondVar(mCondVar);
|
||||
PR_DestroyLock(mExecLock);
|
||||
if (mLock)
|
||||
PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
// We require a special implementation of Release, which knows about
|
||||
// a circular strong reference
|
||||
NS_IMPL_THREADSAFE_ADDREF(mozSqlConnection)
|
||||
NS_IMPL_THREADSAFE_QUERY_INTERFACE3(mozSqlConnection,
|
||||
mozISqlConnection,
|
||||
nsIRunnable,
|
||||
nsISupportsWeakReference)
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
mozSqlConnection::Release()
|
||||
{
|
||||
PR_AtomicDecrement((PRInt32*)&mRefCnt);
|
||||
// Delete if the last reference is our strong circular reference.
|
||||
if (mThread && mRefCnt == 1) {
|
||||
PR_Lock(mLock);
|
||||
mRequests.Clear();
|
||||
mShutdown = PR_TRUE;
|
||||
if (mWaiting)
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
else
|
||||
CancelExec();
|
||||
PR_Unlock(mLock);
|
||||
return 0;
|
||||
}
|
||||
else if (mRefCnt == 0) {
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetServerVersion(nsAString& aServerVersion)
|
||||
{
|
||||
aServerVersion = mServerVersion;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetErrorMessage(nsAString& aErrorMessage)
|
||||
{
|
||||
aErrorMessage = mErrorMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetLastID(PRInt32* aLastID)
|
||||
{
|
||||
*aLastID = mLastID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::Init(const nsAString & aHost, PRInt32 aPort,
|
||||
const nsAString & aDatabase, const nsAString & aUsername,
|
||||
const nsAString & aPassword)
|
||||
{
|
||||
// descendants have to implement this themselves
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::ExecuteQuery(const nsAString& aQuery, mozISqlResult** _retval)
|
||||
{
|
||||
PR_Lock(mExecLock);
|
||||
nsresult rv = RealExec(aQuery, _retval, nsnull);
|
||||
PR_Unlock(mExecLock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::ExecuteUpdate(const nsAString& aUpdate, PRInt32* _retval)
|
||||
{
|
||||
PR_Lock(mExecLock);
|
||||
nsresult rv = RealExec(aUpdate, nsnull, _retval);
|
||||
PR_Unlock(mExecLock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::AsyncExecuteQuery(const nsAString& aQuery, nsISupports* aCtxt,
|
||||
mozISqlRequestObserver* aObserver,
|
||||
mozISqlRequest **_retval)
|
||||
{
|
||||
if (!mThread) {
|
||||
mLock = PR_NewLock();
|
||||
mCondVar = PR_NewCondVar(mLock);
|
||||
NS_NewThread(getter_AddRefs(mThread), this, 0, PR_UNJOINABLE_THREAD);
|
||||
}
|
||||
|
||||
mozSqlRequest* request = new mozSqlRequest(this);
|
||||
if (! request)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
request->mIsQuery = PR_TRUE;
|
||||
request->mQuery = aQuery;
|
||||
request->mCtxt = aCtxt;
|
||||
|
||||
nsresult rv = NS_GetProxyForObject(NS_CURRENT_EVENTQ,
|
||||
NS_GET_IID(mozISqlRequestObserver),
|
||||
aObserver,
|
||||
PROXY_SYNC | PROXY_ALWAYS,
|
||||
getter_AddRefs(request->mObserver));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PR_Lock(mLock);
|
||||
mRequests.AppendObject(request);
|
||||
if (mWaiting && mRequests.Count() == 1)
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
PR_Unlock(mLock);
|
||||
|
||||
NS_ADDREF(*_retval = request);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::AsyncExecuteUpdate(const nsAString& aQuery, nsISupports* aCtxt,
|
||||
mozISqlRequestObserver* aObserver,
|
||||
mozISqlRequest **_retval)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::BeginTransaction()
|
||||
{
|
||||
PRInt32 affectedRows;
|
||||
return ExecuteUpdate(NS_LITERAL_STRING("begin"), &affectedRows);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::CommitTransaction()
|
||||
{
|
||||
PRInt32 affectedRows;
|
||||
return ExecuteUpdate(NS_LITERAL_STRING("commit"), &affectedRows);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::RollbackTransaction()
|
||||
{
|
||||
PRInt32 affectedRows;
|
||||
return ExecuteUpdate(NS_LITERAL_STRING("rollback"), &affectedRows);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval)
|
||||
{
|
||||
// descendants have to implement this themselves
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::Run()
|
||||
{
|
||||
while(!mShutdown) {
|
||||
PR_Lock(mLock);
|
||||
|
||||
while (mRequests.Count()) {
|
||||
mCurrentRequest = mRequests[0];
|
||||
mRequests.RemoveObjectAt(0);
|
||||
|
||||
|
||||
mozSqlRequest* r = (mozSqlRequest*)mCurrentRequest.get();
|
||||
|
||||
r->mObserver->OnStartRequest(mCurrentRequest, r->mCtxt);
|
||||
|
||||
r->mStatus = mozISqlRequest::STATUS_EXECUTED;
|
||||
|
||||
PR_Unlock(mLock);
|
||||
|
||||
nsresult rv = ExecuteQuery(r->mQuery, getter_AddRefs(r->mResult));
|
||||
|
||||
PR_Lock(mLock);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
r->mStatus = mozISqlRequest::STATUS_COMPLETE;
|
||||
else {
|
||||
r->mStatus = mozISqlRequest::STATUS_ERROR;
|
||||
GetErrorMessage(r->mErrorMessage);
|
||||
}
|
||||
|
||||
r->mObserver->OnStopRequest(mCurrentRequest, r->mCtxt);
|
||||
|
||||
mCurrentRequest = nsnull;
|
||||
|
||||
}
|
||||
|
||||
mWaiting = PR_TRUE;
|
||||
PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
mWaiting = PR_FALSE;
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnection::CancelRequest(mozISqlRequest* aRequest)
|
||||
{
|
||||
PR_Lock(mLock);
|
||||
if (mCurrentRequest == aRequest)
|
||||
CancelExec();
|
||||
else {
|
||||
if (mRequests.RemoveObject(aRequest))
|
||||
((mozSqlRequest*)aRequest)->mStatus = mozISqlRequest::STATUS_CANCELLED;
|
||||
}
|
||||
PR_Unlock(mLock);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef mozSqlConnection_h
|
||||
#define mozSqlConnection_h
|
||||
|
||||
#include "prcvar.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "mozISqlConnection.h"
|
||||
#include "mozISqlRequest.h"
|
||||
#include "mozISqlResult.h"
|
||||
|
||||
class mozSqlConnection : public mozISqlConnection,
|
||||
public nsIRunnable,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
mozSqlConnection();
|
||||
virtual ~mozSqlConnection();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLCONNECTION
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
friend class mozSqlRequest;
|
||||
friend class mozSqlResult;
|
||||
|
||||
protected:
|
||||
virtual nsresult RealExec(const nsAString& aQuery,
|
||||
mozISqlResult** aResult, PRInt32* aAffectedRows) = 0;
|
||||
virtual nsresult CancelExec() = 0;
|
||||
virtual nsresult GetIDName(nsAString& aIDName) = 0;
|
||||
|
||||
nsresult CancelRequest(mozISqlRequest* aRequest);
|
||||
|
||||
nsString mServerVersion;
|
||||
nsString mErrorMessage;
|
||||
PRInt32 mLastID;
|
||||
|
||||
PRLock* mLock;
|
||||
PRCondVar* mCondVar;
|
||||
PRLock* mExecLock;
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
nsCOMArray<mozISqlRequest> mRequests;
|
||||
nsCOMPtr<mozISqlRequest> mCurrentRequest;
|
||||
PRBool mShutdown;
|
||||
PRBool mWaiting;
|
||||
};
|
||||
|
||||
#endif // mozSqlConnection_h
|
||||
@@ -1,86 +0,0 @@
|
||||
#include "mozSqlConnection.h"
|
||||
#include "mozSqlRequest.h"
|
||||
|
||||
mozSqlRequest::mozSqlRequest(mozISqlConnection* aConnection)
|
||||
: mAffectedRows(-1),
|
||||
mIsQuery(PR_TRUE),
|
||||
mStatus(mozISqlRequest::STATUS_NONE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mConnection = do_GetWeakReference(aConnection);
|
||||
}
|
||||
|
||||
mozSqlRequest::~mozSqlRequest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(mozSqlRequest,
|
||||
mozISqlRequest);
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetErrorMessage(nsAString & aErrorMessage)
|
||||
{
|
||||
aErrorMessage = mErrorMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetResult(mozISqlResult * *aResult)
|
||||
{
|
||||
NS_IF_ADDREF(*aResult = mResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetAffectedRows(PRInt32 *aAffectedRows)
|
||||
{
|
||||
*aAffectedRows = mAffectedRows;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetLastID(PRInt32* aLastID)
|
||||
{
|
||||
*aLastID = mLastID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetQuery(nsAString & aQuery)
|
||||
{
|
||||
aQuery = mQuery;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetCtxt(nsISupports * *aCtxt)
|
||||
{
|
||||
NS_IF_ADDREF(*aCtxt = mCtxt);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetObserver(mozISqlRequestObserver * *aObserver)
|
||||
{
|
||||
NS_IF_ADDREF(*aObserver = mObserver);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetStatus(PRInt32 *aStatus)
|
||||
{
|
||||
*aStatus = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::Cancel()
|
||||
{
|
||||
nsCOMPtr<mozISqlConnection> connection = do_QueryReferent(mConnection);
|
||||
if (!connection)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mozISqlConnection* connectionRaw = connection.get();
|
||||
return ((mozSqlConnection*)connectionRaw)->CancelRequest(this);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef mozSqlRequest_h
|
||||
#define mozSqlRequest_h
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIWeakReference.h"
|
||||
#include "mozISqlConnection.h"
|
||||
#include "mozISqlResult.h"
|
||||
#include "mozISqlRequest.h"
|
||||
#include "mozISqlRequestObserver.h"
|
||||
|
||||
class mozSqlRequest : public mozISqlRequest
|
||||
{
|
||||
public:
|
||||
mozSqlRequest(mozISqlConnection* aConnection);
|
||||
virtual ~mozSqlRequest();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLREQUEST
|
||||
|
||||
friend class mozSqlConnection;
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIWeakReference> mConnection;
|
||||
|
||||
nsString mErrorMessage;
|
||||
nsCOMPtr<mozISqlResult> mResult;
|
||||
PRInt32 mAffectedRows;
|
||||
PRInt32 mLastID;
|
||||
|
||||
PRBool mIsQuery;
|
||||
nsString mQuery;
|
||||
nsCOMPtr<nsISupports> mCtxt;
|
||||
nsCOMPtr<mozISqlRequestObserver> mObserver;
|
||||
|
||||
PRInt32 mStatus;
|
||||
|
||||
};
|
||||
|
||||
#endif // mozSqlRequest_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,367 +0,0 @@
|
||||
#ifndef mozSqlResult_h
|
||||
#define mozSqlResult_h
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsFixedSizeAllocator.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFRemoteDataSource.h"
|
||||
#include "nsIDateTimeFormat.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "mozISqlConnection.h"
|
||||
#include "mozISqlDataSource.h"
|
||||
#include "mozISqlResult.h"
|
||||
#include "mozISqlResultEnumerator.h"
|
||||
#include "mozISqlInputStream.h"
|
||||
|
||||
#define CELL_FLAG_NULL 0x80
|
||||
#define CELL_FLAG_DEFAULT 0x40
|
||||
#define CELL_FLAG_MASK ~(CELL_FLAG_NULL | CELL_FLAG_DEFAULT)
|
||||
|
||||
class ColumnInfo {
|
||||
public:
|
||||
static ColumnInfo*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
PRUnichar* aName,
|
||||
PRInt32 aType,
|
||||
PRInt32 aSize,
|
||||
PRInt32 aMod,
|
||||
nsIRDFResource* aProperty) {
|
||||
void* place = aAllocator.Alloc(sizeof(ColumnInfo));
|
||||
return place ? ::new(place) ColumnInfo(aName, aType, aSize, aMod, aProperty) : nsnull;
|
||||
}
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aAllocator, ColumnInfo* aColumnInfo) {
|
||||
aColumnInfo->~ColumnInfo();
|
||||
aAllocator.Free(aColumnInfo, sizeof(ColumnInfo));
|
||||
}
|
||||
|
||||
ColumnInfo(PRUnichar* aName, PRInt32 aType, PRInt32 aSize, PRInt32 aMod, nsIRDFResource* aProperty)
|
||||
: mName(aName),
|
||||
mType(aType),
|
||||
mSize(aSize),
|
||||
mMod(aMod),
|
||||
mProperty(aProperty) {
|
||||
NS_IF_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
~ColumnInfo() {
|
||||
if (mName)
|
||||
nsMemory::Free(mName);
|
||||
NS_IF_RELEASE(mProperty);
|
||||
}
|
||||
|
||||
PRUnichar* mName;
|
||||
PRInt32 mType;
|
||||
PRInt32 mSize;
|
||||
PRInt32 mMod;
|
||||
nsIRDFResource* mProperty;
|
||||
|
||||
private:
|
||||
// Hide so that only Create() and Destroy() can be used to
|
||||
// allocate and deallocate from the heap
|
||||
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
|
||||
static void operator delete(void*, size_t) {}
|
||||
};
|
||||
|
||||
class Cell {
|
||||
public:
|
||||
static Cell*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
PRInt32 aType) {
|
||||
void* place = aAllocator.Alloc(sizeof(Cell));
|
||||
return place ? ::new(place) Cell(aType) : nsnull;
|
||||
}
|
||||
|
||||
static Cell*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
PRInt32 aType,
|
||||
Cell* aSrcCell) {
|
||||
void* place = aAllocator.Alloc(sizeof(Cell));
|
||||
if (! place)
|
||||
return nsnull;
|
||||
Cell* newCell = ::new(place) Cell(aType);
|
||||
Copy(aSrcCell, newCell);
|
||||
return newCell;
|
||||
}
|
||||
|
||||
static void
|
||||
Copy(Cell* aSrcCell, Cell* aDestCell) {
|
||||
if (aSrcCell->IsNull())
|
||||
aDestCell->SetNull(PR_TRUE);
|
||||
else {
|
||||
aDestCell->SetNull(PR_FALSE);
|
||||
PRInt32 type = aSrcCell->GetType();
|
||||
if (type == mozISqlResult::TYPE_STRING)
|
||||
aDestCell->SetString(nsCRT::strdup(aSrcCell->mString));
|
||||
else if (type == mozISqlResult::TYPE_INT)
|
||||
aDestCell->mInt = aSrcCell->mInt;
|
||||
else if (type == mozISqlResult::TYPE_FLOAT ||
|
||||
type == mozISqlResult::TYPE_DECIMAL)
|
||||
aDestCell->mFloat = aSrcCell->mFloat;
|
||||
else if (type == mozISqlResult::TYPE_DATE ||
|
||||
type == mozISqlResult::TYPE_TIME ||
|
||||
type == mozISqlResult::TYPE_DATETIME)
|
||||
aDestCell->mDate = aSrcCell->mDate;
|
||||
else if (type == mozISqlResult::TYPE_BOOL)
|
||||
aDestCell->mBool = aSrcCell->mBool;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aAllocator, Cell* aCell) {
|
||||
aCell->~Cell();
|
||||
aAllocator.Free(aCell, sizeof(Cell));
|
||||
}
|
||||
|
||||
Cell(PRInt32 aType)
|
||||
: mString(nsnull),
|
||||
mType(aType | CELL_FLAG_NULL) {
|
||||
}
|
||||
|
||||
~Cell() {
|
||||
if ((GetType() == mozISqlResult::TYPE_STRING) && mString) {
|
||||
nsMemory::Free(mString);
|
||||
}
|
||||
}
|
||||
|
||||
void SetString(PRUnichar* aString) {
|
||||
if (mString)
|
||||
nsMemory::Free(mString);
|
||||
mString = aString;
|
||||
}
|
||||
|
||||
PRInt32 GetType() {
|
||||
return mType & CELL_FLAG_MASK;
|
||||
}
|
||||
|
||||
void SetNull(PRBool aNull) {
|
||||
mType &= CELL_FLAG_MASK;
|
||||
if (aNull)
|
||||
mType |= CELL_FLAG_NULL;
|
||||
}
|
||||
|
||||
void SetDefault(PRBool aDefault) {
|
||||
mType &= CELL_FLAG_MASK;
|
||||
if (aDefault)
|
||||
mType |= CELL_FLAG_DEFAULT;
|
||||
}
|
||||
|
||||
PRBool IsNull() {
|
||||
return mType & CELL_FLAG_NULL;
|
||||
}
|
||||
|
||||
PRBool IsDefault() {
|
||||
return mType & CELL_FLAG_DEFAULT;
|
||||
}
|
||||
|
||||
union {
|
||||
PRUnichar* mString;
|
||||
PRInt32 mInt;
|
||||
float mFloat;
|
||||
PRInt64 mDate;
|
||||
PRBool mBool;
|
||||
};
|
||||
|
||||
private:
|
||||
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
|
||||
static void operator delete(void*, size_t) {}
|
||||
|
||||
PRInt8 mType;
|
||||
};
|
||||
|
||||
class Row {
|
||||
public:
|
||||
static Row*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
nsIRDFResource* aSource,
|
||||
nsVoidArray& aColumnInfo) {
|
||||
void* place = aAllocator.Alloc(sizeof(Row));
|
||||
if (! place)
|
||||
return nsnull;
|
||||
Row* newRow = ::new(place) Row(aSource, aColumnInfo.Count());
|
||||
for (PRInt32 i = 0; i < aColumnInfo.Count(); i++) {
|
||||
Cell* newCell = Cell::Create(aAllocator, ((ColumnInfo*)aColumnInfo[i])->mType);
|
||||
newRow->mCells[i] = newCell;
|
||||
}
|
||||
return newRow;
|
||||
}
|
||||
|
||||
static Row*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
nsIRDFResource* aSource,
|
||||
nsVoidArray& aColumnInfo,
|
||||
Row* aSrcRow) {
|
||||
void* place = aAllocator.Alloc(sizeof(Row));
|
||||
if (! place)
|
||||
return nsnull;
|
||||
Row* newRow = ::new(place) Row(aSource, aColumnInfo.Count());
|
||||
for (PRInt32 i = 0; i < aColumnInfo.Count(); i++) {
|
||||
Cell* srcCell = aSrcRow->mCells[i];
|
||||
Cell* newCell = Cell::Create(aAllocator, ((ColumnInfo*)aColumnInfo[i])->mType, srcCell);
|
||||
newRow->mCells[i] = newCell;
|
||||
}
|
||||
return newRow;
|
||||
}
|
||||
|
||||
static void
|
||||
Copy(PRInt32 aColumnCount, Row* aSrcRow, Row* aDestRow) {
|
||||
for (PRInt32 i = 0; i < aColumnCount; i++) {
|
||||
Cell* srcCell = aSrcRow->mCells[i];
|
||||
Cell* destCell = aDestRow->mCells[i];
|
||||
Cell::Copy(srcCell, destCell);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aAllocator, PRInt32 aColumnCount, Row* aRow) {
|
||||
for (PRInt32 i = 0; i < aColumnCount; i++)
|
||||
Cell::Destroy(aAllocator, aRow->mCells[i]);
|
||||
aRow->~Row();
|
||||
aAllocator.Free(aRow, sizeof(*aRow));
|
||||
}
|
||||
|
||||
Row(nsIRDFResource* aSource, PRInt32 aColumnCount)
|
||||
: mSource(aSource)
|
||||
{
|
||||
NS_IF_ADDREF(mSource);
|
||||
mCells = new Cell*[aColumnCount];
|
||||
}
|
||||
|
||||
~Row() {
|
||||
delete[] mCells;
|
||||
NS_IF_RELEASE(mSource);
|
||||
}
|
||||
|
||||
nsIRDFResource* mSource;
|
||||
Cell** mCells;
|
||||
private:
|
||||
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
|
||||
static void operator delete(void*, size_t) {}
|
||||
};
|
||||
|
||||
class mozSqlResult : public mozISqlResult,
|
||||
public mozISqlDataSource,
|
||||
public nsIRDFDataSource,
|
||||
public nsIRDFRemoteDataSource
|
||||
{
|
||||
public:
|
||||
mozSqlResult(mozISqlConnection* aConnection,
|
||||
const nsAString& aQuery);
|
||||
nsresult Init();
|
||||
nsresult Rebuild();
|
||||
virtual ~mozSqlResult();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLRESULT
|
||||
|
||||
NS_DECL_MOZISQLDATASOURCE
|
||||
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
|
||||
NS_DECL_NSIRDFREMOTEDATASOURCE
|
||||
|
||||
friend class mozSqlResultEnumerator;
|
||||
friend class mozSqlResultStream;
|
||||
|
||||
protected:
|
||||
virtual nsresult BuildColumnInfo() = 0 ;
|
||||
virtual nsresult BuildRows() = 0;
|
||||
virtual void ClearNativeResult() = 0;
|
||||
|
||||
void ClearColumnInfo();
|
||||
void ClearRows();
|
||||
|
||||
nsresult EnsureTableName();
|
||||
nsresult EnsurePrimaryKeys();
|
||||
|
||||
void AppendValue(Cell* aCell, nsAutoString& aValues);
|
||||
nsresult AppendKeys(Row* aRow, nsAutoString& aKeys);
|
||||
nsresult GetValues(Row* aRow, mozISqlResult** aResult, PRBool aUseID);
|
||||
nsresult CopyValues(mozISqlResult* aResult, Row* aRow);
|
||||
|
||||
virtual nsresult CanInsert(PRBool* _retval) = 0;
|
||||
virtual nsresult CanUpdate(PRBool* _retval) = 0;
|
||||
virtual nsresult CanDelete(PRBool* _retval) = 0;
|
||||
|
||||
nsresult InsertRow(Row* aSrcRow, PRInt32* _retval);
|
||||
nsresult UpdateRow(PRInt32 aRowIndex, Row* aSrcRow, PRInt32* _retval);
|
||||
nsresult DeleteRow(PRInt32 aRowIndex, PRInt32* _retval);
|
||||
nsresult GetCondition(Row* aRow, nsAString& aCurrentCondition);
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIDateTimeFormat* gFormat;
|
||||
static nsIRDFResource* kSQL_ResultRoot;
|
||||
static nsIRDFResource* kNC_Child;
|
||||
static nsIRDFLiteral* kNullLiteral;
|
||||
static nsIRDFLiteral* kTrueLiteral;
|
||||
static nsIRDFLiteral* kFalseLiteral;
|
||||
|
||||
nsCOMPtr<mozISqlConnection> mConnection;
|
||||
nsString mErrorMessage;
|
||||
nsString mQuery;
|
||||
nsString mTableName;
|
||||
nsFixedSizeAllocator mAllocator;
|
||||
nsAutoVoidArray mColumnInfo;
|
||||
nsVoidArray mRows;
|
||||
nsObjectHashtable mSources;
|
||||
nsCOMArray<nsIRDFObserver> mObservers;
|
||||
nsCOMPtr<mozISqlResultEnumerator> mPrimaryKeys;
|
||||
PRInt32 mCanInsert;
|
||||
PRInt32 mCanUpdate;
|
||||
PRInt32 mCanDelete;
|
||||
};
|
||||
|
||||
class mozSqlResultEnumerator : public mozISqlResultEnumerator,
|
||||
public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
mozSqlResultEnumerator(mozSqlResult* aResult);
|
||||
virtual ~mozSqlResultEnumerator();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLRESULTENUMERATOR
|
||||
|
||||
NS_DECL_NSISIMPLEENUMERATOR
|
||||
|
||||
private:
|
||||
mozSqlResult* mResult;
|
||||
PRInt32 mCurrentIndex;
|
||||
Row* mCurrentRow;
|
||||
Row* mBuffer;
|
||||
};
|
||||
|
||||
class mozSqlResultStream : public mozISqlInputStream,
|
||||
public nsIInputStream
|
||||
{
|
||||
public:
|
||||
mozSqlResultStream(mozSqlResult* aResult);
|
||||
virtual ~mozSqlResultStream();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLINPUTSTREAM
|
||||
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
|
||||
protected:
|
||||
nsresult EnsureBuffer();
|
||||
|
||||
private:
|
||||
mozSqlResult* mResult;
|
||||
char* mBuffer;
|
||||
PRUint32 mLength;
|
||||
PRUint32 mPosition;
|
||||
};
|
||||
|
||||
#endif // mozSqlResult_h
|
||||
@@ -1,624 +0,0 @@
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "rdf.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIRDFXMLSink.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "mozSqlService.h"
|
||||
#include "mozSqlConnection.h"
|
||||
|
||||
#define SQL_NAMESPACE_URI "http://www.mozilla.org/SQL-rdf#"
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
|
||||
nsIRDFService* mozSqlService::gRDFService;
|
||||
nsIRDFContainerUtils* mozSqlService::gRDFContainerUtils;
|
||||
|
||||
nsIRDFResource* mozSqlService::kSQL_AliasesRoot;
|
||||
nsIRDFResource* mozSqlService::kSQL_Name;
|
||||
nsIRDFResource* mozSqlService::kSQL_Type;
|
||||
nsIRDFResource* mozSqlService::kSQL_Hostname;
|
||||
nsIRDFResource* mozSqlService::kSQL_Port;
|
||||
nsIRDFResource* mozSqlService::kSQL_Database;
|
||||
|
||||
|
||||
mozSqlService::mozSqlService()
|
||||
: mConnectionCache(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
mozSqlService::~mozSqlService()
|
||||
{
|
||||
gRDFService->UnregisterDataSource(this);
|
||||
|
||||
delete mConnectionCache;
|
||||
|
||||
NS_IF_RELEASE(kSQL_AliasesRoot);
|
||||
NS_IF_RELEASE(kSQL_Name);
|
||||
NS_IF_RELEASE(kSQL_Type);
|
||||
NS_IF_RELEASE(kSQL_Hostname);
|
||||
NS_IF_RELEASE(kSQL_Port);
|
||||
NS_IF_RELEASE(kSQL_Database);
|
||||
|
||||
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
|
||||
gRDFContainerUtils = nsnull;
|
||||
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
||||
gRDFService = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3(mozSqlService,
|
||||
mozISqlService,
|
||||
nsIRDFDataSource,
|
||||
nsIRDFRemoteDataSource);
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetErrorMessage(nsAString& aErrorMessage)
|
||||
{
|
||||
aErrorMessage = mErrorMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlService::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService),
|
||||
(nsISupports**) &gRDFService);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID, NS_GET_IID(nsIRDFContainerUtils),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING("SQL:AliasesRoot"),
|
||||
&kSQL_AliasesRoot);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "name"),
|
||||
&kSQL_Name);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "type"),
|
||||
&kSQL_Type);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "hostname"),
|
||||
&kSQL_Hostname);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "port"),
|
||||
&kSQL_Port);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "database"),
|
||||
&kSQL_Database);
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = file->AppendNative(NS_LITERAL_CSTRING("sql.rdf"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString sql;
|
||||
NS_GetURLSpecFromFile(file, sql);
|
||||
|
||||
rv = gRDFService->GetDataSourceBlocking(sql.get(), getter_AddRefs(mInner));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mInner);
|
||||
if (sink) {
|
||||
nsCOMPtr<nsIAtom> prefix = getter_AddRefs(NS_NewAtom("SQL"));
|
||||
sink->AddNameSpace(prefix, NS_ConvertASCIItoUCS2(SQL_NAMESPACE_URI));
|
||||
}
|
||||
|
||||
return gRDFService->RegisterDataSource(this, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::AddAlias(const nsACString& aURI,
|
||||
const nsAString& aName,
|
||||
const nsAString& aType,
|
||||
const nsAString& aHostname,
|
||||
PRInt32 aPort,
|
||||
const nsAString& aDatabase)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> rdfLiteral;
|
||||
nsCOMPtr<nsIRDFInt> rdfInt;
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aName).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Name, rdfLiteral, PR_TRUE);
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aType).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Type, rdfLiteral, PR_TRUE);
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aHostname).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Hostname, rdfLiteral, PR_TRUE);
|
||||
|
||||
gRDFService->GetIntLiteral(aPort, getter_AddRefs(rdfInt));
|
||||
mInner->Assert(resource, kSQL_Port, rdfInt, PR_TRUE);
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aDatabase).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Database, rdfLiteral, PR_TRUE);
|
||||
|
||||
nsresult rv = EnsureAliasesContainer();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
mAliasesContainer->AppendElement(resource);
|
||||
|
||||
Flush();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasAlias(const nsACString& aURI, PRBool* _retval)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsresult rv = EnsureAliasesContainer();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRInt32 aliasIndex;
|
||||
mAliasesContainer->IndexOf(resource, &aliasIndex);
|
||||
|
||||
*_retval = aliasIndex != -1;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetAlias(const nsACString& aURI,
|
||||
nsAString& aName,
|
||||
nsAString& aType,
|
||||
nsAString& aHostname,
|
||||
PRInt32* aPort,
|
||||
nsAString& aDatabase)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFNode> rdfNode;
|
||||
nsCOMPtr<nsIRDFLiteral> rdfLiteral;
|
||||
nsCOMPtr<nsIRDFInt> rdfInt;
|
||||
const PRUnichar* value;
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aName.Assign(value);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aType.Assign(value);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aHostname.Assign(value);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfInt = do_QueryInterface(rdfNode);
|
||||
rdfInt->GetValue(aPort);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aDatabase.Assign(value);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::UpdateAlias(const nsACString& aURI,
|
||||
const nsAString& aName,
|
||||
const nsAString& aType,
|
||||
const nsAString& aHostname,
|
||||
PRInt32 aPort,
|
||||
const nsAString& aDatabase)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFNode> rdfNode;
|
||||
nsCOMPtr<nsIRDFLiteral> rdfLiteral;
|
||||
nsCOMPtr<nsIRDFInt> rdfInt;
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aName).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Name, rdfNode, rdfLiteral);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aType).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Type, rdfNode, rdfLiteral);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aHostname).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Hostname, rdfNode, rdfLiteral);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetIntLiteral(aPort, getter_AddRefs(rdfInt));
|
||||
mInner->Change(resource, kSQL_Port, rdfNode, rdfInt);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aDatabase).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Database, rdfNode, rdfLiteral);
|
||||
|
||||
Flush();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::RemoveAlias(const nsACString &aURI)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFNode> rdfNode;
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Name, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Type, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Hostname, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Port, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Database, rdfNode);
|
||||
|
||||
nsresult rv = EnsureAliasesContainer();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
mAliasesContainer->RemoveElement(resource, PR_TRUE);
|
||||
|
||||
Flush();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetConnection(const nsACString &aURI, mozISqlConnection **_retval)
|
||||
{
|
||||
nsCStringKey key(aURI);
|
||||
nsCOMPtr<nsIWeakReference> weakRef;
|
||||
nsCOMPtr<mozISqlConnection> conn;
|
||||
|
||||
if (mConnectionCache) {
|
||||
weakRef = getter_AddRefs(NS_STATIC_CAST(nsIWeakReference*, mConnectionCache->Get(&key)));
|
||||
if (weakRef) {
|
||||
conn = do_QueryReferent(weakRef);
|
||||
if (conn)
|
||||
NS_ADDREF(*_retval = conn);
|
||||
}
|
||||
}
|
||||
|
||||
if (! *_retval) {
|
||||
nsresult rv = GetNewConnection(aURI, getter_AddRefs(conn));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
weakRef = do_GetWeakReference(conn);
|
||||
|
||||
if (! mConnectionCache)
|
||||
mConnectionCache = new nsSupportsHashtable(16);
|
||||
mConnectionCache->Put(&key, weakRef);
|
||||
|
||||
NS_ADDREF(*_retval = conn);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetNewConnection(const nsACString &aURI, mozISqlConnection **_retval)
|
||||
{
|
||||
PRBool hasAlias;
|
||||
HasAlias(aURI, &hasAlias);
|
||||
if (!hasAlias)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsAutoString name;
|
||||
nsAutoString type;
|
||||
nsAutoString hostname;
|
||||
PRInt32 port;
|
||||
nsAutoString database;
|
||||
GetAlias(aURI, name, type, hostname, &port, database);
|
||||
|
||||
nsCAutoString contractID(
|
||||
NS_LITERAL_CSTRING("@mozilla.org/sql/connection;1?type=") +
|
||||
NS_ConvertUCS2toUTF8(type));
|
||||
|
||||
nsCOMPtr<mozISqlConnection> conn = do_CreateInstance(contractID.get());
|
||||
if (! conn)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
||||
nsCOMPtr<nsIPrompt> prompter;
|
||||
watcher->GetNewPrompter(0, getter_AddRefs(prompter));
|
||||
|
||||
PRBool retval;
|
||||
do {
|
||||
nsXPIDLString username;
|
||||
nsXPIDLString password;
|
||||
prompter->PromptUsernameAndPassword(
|
||||
nsnull, // in wstring dialogTitle
|
||||
nsnull, // in wstring text
|
||||
getter_Copies(username),
|
||||
getter_Copies(password),
|
||||
nsnull, // in wstring checkMsg
|
||||
nsnull, // inout boolean checkValue
|
||||
&retval
|
||||
);
|
||||
|
||||
if (retval) {
|
||||
rv = conn->Init(hostname, port, database, username, password);
|
||||
if (NS_FAILED(rv)) {
|
||||
conn->GetErrorMessage(mErrorMessage);
|
||||
prompter->Alert(nsnull, mErrorMessage.get());
|
||||
}
|
||||
}
|
||||
} while(retval && NS_FAILED(rv));
|
||||
|
||||
NS_IF_ADDREF(*_retval = conn);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetURI(char** aURI)
|
||||
{
|
||||
if (!aURI)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aURI = nsCRT::strdup("rdf:sql");
|
||||
if (!(*aURI))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetSource(nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
nsIRDFResource** aSource)
|
||||
{
|
||||
return mInner->GetSource(aProperty, aTarget, aTruthValue, aSource);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetSources(nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
nsISimpleEnumerator** aSources) {
|
||||
return mInner->GetSources(aProperty, aTarget, aTruthValue, aSources);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetTarget(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
PRBool aTruthValue,
|
||||
nsIRDFNode** aTarget) {
|
||||
return mInner->GetTarget(aSource, aProperty, aTruthValue, aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetTargets(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
PRBool aTruthValue,
|
||||
nsISimpleEnumerator** aTargets) {
|
||||
return mInner->GetTargets(aSource, aProperty, aTruthValue, aTargets);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Assert(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue)
|
||||
{
|
||||
return mInner->Assert(aSource, aProperty, aTarget, aTruthValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Unassert(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return mInner->Unassert(aSource, aProperty, aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Change(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aOldTarget,
|
||||
nsIRDFNode* aNewTarget)
|
||||
{
|
||||
return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Move(nsIRDFResource* aOldSource,
|
||||
nsIRDFResource* aNewSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasAssertion(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
PRBool* hasAssertion)
|
||||
{
|
||||
return mInner->HasAssertion(aSource, aProperty, aTarget, aTruthValue, hasAssertion);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::AddObserver(nsIRDFObserver* aObserver)
|
||||
{
|
||||
return mInner->AddObserver(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::RemoveObserver(nsIRDFObserver* aObserver)
|
||||
{
|
||||
return mInner->RemoveObserver(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasArcIn(nsIRDFNode* aNode,
|
||||
nsIRDFResource* aArc,
|
||||
PRBool* _retval)
|
||||
{
|
||||
return mInner->HasArcIn(aNode, aArc, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasArcOut(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aArc,
|
||||
PRBool* _retval)
|
||||
{
|
||||
return mInner->HasArcOut(aSource, aArc, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::ArcLabelsIn(nsIRDFNode* aNode,
|
||||
nsISimpleEnumerator** aLabels)
|
||||
{
|
||||
return mInner->ArcLabelsIn(aNode, aLabels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::ArcLabelsOut(nsIRDFResource* aSource,
|
||||
nsISimpleEnumerator** aLabels)
|
||||
{
|
||||
return mInner->ArcLabelsIn(aSource, aLabels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetAllResources(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetAllCmds(nsIRDFResource* aSource,
|
||||
nsISimpleEnumerator** aCommands)
|
||||
{
|
||||
return mInner->GetAllCmds(aSource, aCommands);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::IsCommandEnabled(nsISupportsArray* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray* aArguments,
|
||||
PRBool* aResult)
|
||||
{
|
||||
return mInner->IsCommandEnabled(aSources, aCommand, aArguments, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::DoCommand(nsISupportsArray* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray* aArguments)
|
||||
{
|
||||
return mInner->DoCommand(aSources, aCommand, aArguments);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::BeginUpdateBatch()
|
||||
{
|
||||
return mInner->BeginUpdateBatch();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::EndUpdateBatch()
|
||||
{
|
||||
return mInner->EndUpdateBatch();
|
||||
}
|
||||
|
||||
|
||||
// nsIRDFRemoteDataSource
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetLoaded(PRBool* aResult)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->GetLoaded(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Init(const char* aURI)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Refresh(PRBool aBlocking)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Refresh(aBlocking);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Flush()
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Flush();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::FlushTo(const char *aURI)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->FlushTo(aURI);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
mozSqlService::EnsureAliasesContainer()
|
||||
{
|
||||
if (! mAliasesContainer) {
|
||||
PRBool isContainer;
|
||||
nsresult rv = gRDFContainerUtils->IsContainer(mInner, kSQL_AliasesRoot, &isContainer);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!isContainer) {
|
||||
rv = gRDFContainerUtils->MakeSeq(mInner, kSQL_AliasesRoot, getter_AddRefs(mAliasesContainer));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
mAliasesContainer = do_CreateInstance(NS_RDF_CONTRACTID "/container;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mAliasesContainer->Init(mInner, kSQL_AliasesRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef mozSqlService_h
|
||||
#define mozSqlService_h
|
||||
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFRemoteDataSource.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFContainerUtils.h"
|
||||
#include "mozISqlService.h"
|
||||
|
||||
#define MOZ_SQLSERVICE_CLASSNAME "SQL service"
|
||||
#define MOZ_SQLSERVICE_CID \
|
||||
{0x1ceb35b7, 0xdaa8, 0x4ce4, {0xac, 0x67, 0x12, 0x5f, 0xb1, 0x7c, 0xb0, 0x19}}
|
||||
#define MOZ_SQLSERVICE_CONTRACTID "@mozilla.org/sql/service;1"
|
||||
#define MOZ_SQLDATASOURCE_CONTRACTID "@mozilla.org/rdf/datasource;1?name=sql"
|
||||
|
||||
class mozSqlService : public mozISqlService,
|
||||
public nsIRDFDataSource,
|
||||
public nsIRDFRemoteDataSource
|
||||
{
|
||||
public:
|
||||
mozSqlService();
|
||||
virtual ~mozSqlService();
|
||||
nsresult Init();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_MOZISQLSERVICE
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
NS_DECL_NSIRDFREMOTEDATASOURCE
|
||||
|
||||
protected:
|
||||
nsresult EnsureAliasesContainer();
|
||||
|
||||
private:
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIRDFContainerUtils* gRDFContainerUtils;
|
||||
|
||||
static nsIRDFResource* kSQL_AliasesRoot;
|
||||
static nsIRDFResource* kSQL_Name;
|
||||
static nsIRDFResource* kSQL_Type;
|
||||
static nsIRDFResource* kSQL_Hostname;
|
||||
static nsIRDFResource* kSQL_Port;
|
||||
static nsIRDFResource* kSQL_Database;
|
||||
|
||||
nsString mErrorMessage;
|
||||
nsCOMPtr<nsIRDFDataSource> mInner;
|
||||
nsCOMPtr<nsIRDFContainer> mAliasesContainer;
|
||||
nsSupportsHashtable* mConnectionCache;
|
||||
|
||||
};
|
||||
|
||||
#endif /* mozSqlService_h */
|
||||
@@ -1,21 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
XPI_FILE = sql-$(shell date +%Y%m%d)-$(OS_ARCH).xpi
|
||||
|
||||
xpi:
|
||||
zip -j $(DIST)/$(XPI_FILE) $(srcdir)/install.js
|
||||
cd $(DIST); zip -r $(XPI_FILE) \
|
||||
bin/components/sql.xpt \
|
||||
bin/components/sqlpgsql.xpt \
|
||||
bin/components/$(LIB_PREFIX)sql$(DLL_SUFFIX) \
|
||||
bin/chrome/sql.jar
|
||||
@@ -1,58 +0,0 @@
|
||||
// this function verifies disk space in kilobytes
|
||||
function verifyDiskSpace(dirPath, spaceRequired)
|
||||
{
|
||||
var spaceAvailable;
|
||||
|
||||
// Get the available disk space on the given path
|
||||
spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
|
||||
|
||||
// Convert the available disk space into kilobytes
|
||||
spaceAvailable = parseInt(spaceAvailable / 1024);
|
||||
|
||||
// do the verification
|
||||
if(spaceAvailable < spaceRequired)
|
||||
{
|
||||
logComment("Insufficient disk space: " + dirPath);
|
||||
logComment(" required : " + spaceRequired + " K");
|
||||
logComment(" available: " + spaceAvailable + " K");
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
var srDest = 200;
|
||||
|
||||
var err = initInstall("SQL Support", "SQL", "0.1");
|
||||
logComment("initInstall: " + err);
|
||||
|
||||
var fProgram = getFolder("Program");
|
||||
logComment("fProgram: " + fProgram);
|
||||
|
||||
if (verifyDiskSpace(fProgram, srDest))
|
||||
{
|
||||
err = addDirectory("Program", "0.1", "bin", fProgram, "", true);
|
||||
|
||||
logComment("addDirectory() returned: " + err);
|
||||
|
||||
var chromeFolder = getFolder("Chrome", "sql.jar");
|
||||
registerChrome(CONTENT | DELAYED_CHROME, chromeFolder, "content/sql/");
|
||||
registerChrome(LOCALE | DELAYED_CHROME, chromeFolder, "locale/en-US/sql/");
|
||||
|
||||
err = getLastError();
|
||||
if (err == ACCESS_DENIED) {
|
||||
alert("Unable to write to program directory " + fProgram + ".\n You will need to restart the browser with administrator/root privileges to install this software. After installing as root (or administrator), you will need to restart the browser one more time to register the installed software.\n After the second restart, you can go back to running the browser without privileges!");
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else if (err != SUCCESS) {
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else {
|
||||
performInstall();
|
||||
logComment("performInstall() returned: " + err);
|
||||
}
|
||||
}
|
||||
else
|
||||
cancelInstall(INSUFFICIENT_DISK_SPACE);
|
||||
@@ -1,40 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = sql
|
||||
MODULE_NAME = sqlModule
|
||||
LIBRARY_NAME = sql
|
||||
SHORT_LIBNAME = sql
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
rdf \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozSqlModule.cpp
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)sqlbase_s.$(LIB_SUFFIX)
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(MOZ_UNICHARUTIL_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_ENABLE_PGSQL
|
||||
DEFINES += -DMOZ_ENABLE_PGSQL
|
||||
SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)sqlpgsql_s.$(LIB_SUFFIX)
|
||||
EXTRA_DSO_LDOPTS += -L$(MOZ_PGSQL_LIBS) -lpq
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifdef MOZ_ENABLE_PGSQL
|
||||
INCLUDES += -I$(MOZ_PGSQL_INCLUDES)
|
||||
endif
|
||||
@@ -1,33 +0,0 @@
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "mozSqlService.h"
|
||||
#ifdef MOZ_ENABLE_PGSQL
|
||||
#include "mozSqlConnectionPgsql.h"
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozSqlService, Init)
|
||||
#ifdef MOZ_ENABLE_PGSQL
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSqlConnectionPgsql)
|
||||
#endif
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ MOZ_SQLSERVICE_CLASSNAME,
|
||||
MOZ_SQLSERVICE_CID,
|
||||
MOZ_SQLSERVICE_CONTRACTID,
|
||||
mozSqlServiceConstructor
|
||||
},
|
||||
{ MOZ_SQLSERVICE_CLASSNAME,
|
||||
MOZ_SQLSERVICE_CID,
|
||||
MOZ_SQLDATASOURCE_CONTRACTID,
|
||||
mozSqlServiceConstructor
|
||||
},
|
||||
#ifdef MOZ_ENABLE_PGSQL
|
||||
{ MOZ_SQLCONNECTIONPGSQL_CLASSNAME,
|
||||
MOZ_SQLCONNECTIONPGSQL_CID,
|
||||
MOZ_SQLCONNECTIONPGSQL_CONTRACTID,
|
||||
mozSqlConnectionPgsqlConstructor
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("sql", components)
|
||||
@@ -1,10 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
DIRS = \
|
||||
public \
|
||||
src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,14 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = sql
|
||||
XPIDL_MODULE = sqlpgsql
|
||||
|
||||
XPIDLSRCS = \
|
||||
mozISqlConnectionPgsql.idl \
|
||||
mozISqlResultPgsql.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(0cf1eefe-611d-48fa-ae27-0a6f40d6a33e)]
|
||||
|
||||
interface mozISqlConnectionPgsql : nsISupports
|
||||
{
|
||||
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(f6573169-286d-4a20-8253-9abb07bdba29)]
|
||||
|
||||
interface mozISqlResultPgsql : nsISupports
|
||||
{
|
||||
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = sql
|
||||
LIBRARY_NAME = sqlpgsql_s
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
locale \
|
||||
rdf \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozSqlConnectionPgsql.cpp \
|
||||
mozSqlResultPgsql.cpp
|
||||
|
||||
EXPORTS = \
|
||||
mozSqlConnectionPgsql.h \
|
||||
mozSqlResultPgsql.h
|
||||
|
||||
FORCE_STATIC_LIB=1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
INCLUDES += -I$(MOZ_PGSQL_INCLUDES)
|
||||
@@ -1,240 +0,0 @@
|
||||
#include "prprf.h"
|
||||
#include "mozSqlConnectionPgsql.h"
|
||||
#include "mozSqlResultPgsql.h"
|
||||
|
||||
mozSqlConnectionPgsql::mozSqlConnectionPgsql()
|
||||
: mConnection(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
mozSqlConnectionPgsql::~mozSqlConnectionPgsql()
|
||||
{
|
||||
if (mConnection)
|
||||
PQfinish(mConnection);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(mozSqlConnectionPgsql, mozSqlConnection)
|
||||
NS_IMPL_RELEASE_INHERITED(mozSqlConnectionPgsql, mozSqlConnection)
|
||||
|
||||
// QueryInterface
|
||||
NS_INTERFACE_MAP_BEGIN(mozSqlConnectionPgsql)
|
||||
NS_INTERFACE_MAP_ENTRY(mozISqlConnectionPgsql)
|
||||
NS_INTERFACE_MAP_END_INHERITING(mozSqlConnection)
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnectionPgsql::Init(const nsAString & aHost, PRInt32 aPort,
|
||||
const nsAString & aDatabase, const nsAString & aUsername,
|
||||
const nsAString & aPassword)
|
||||
{
|
||||
if (mConnection)
|
||||
return NS_OK;
|
||||
|
||||
if (aPort == -1)
|
||||
aPort = 5432;
|
||||
char port[11];
|
||||
char options[] = "";
|
||||
char tty[] = "";
|
||||
PR_snprintf(port, 11, "%d", aPort);
|
||||
|
||||
mConnection = PQsetdbLogin(NS_ConvertUCS2toUTF8(aHost).get(),
|
||||
port, options, tty,
|
||||
NS_ConvertUCS2toUTF8(aDatabase).get(),
|
||||
NS_ConvertUCS2toUTF8(aUsername).get(),
|
||||
NS_ConvertUCS2toUTF8(aPassword).get());
|
||||
|
||||
return Setup();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnectionPgsql::GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval)
|
||||
{
|
||||
nsAutoString select;
|
||||
nsAutoString from;
|
||||
nsAutoString where;
|
||||
if (mVersion >= SERVER_VERSION(7,3,0)) {
|
||||
select = NS_LITERAL_STRING("SELECT n.nspname AS TABLE_SCHEM, ");
|
||||
from = NS_LITERAL_STRING(" FROM pg_catalog.pg_namespace n, pg_catalog.pg_class ct, pg_catalog.pg_class ci, pg_catalog.pg_attribute a, pg_catalog.pg_index i");
|
||||
where = NS_LITERAL_STRING(" AND ct.relnamespace = n.oid ");
|
||||
if (!aSchema.IsEmpty()) {
|
||||
where.Append(NS_LITERAL_STRING(" AND n.nspname = '") + aSchema);
|
||||
where.Append(PRUnichar('\''));
|
||||
}
|
||||
}
|
||||
else {
|
||||
select = NS_LITERAL_STRING("SELECT NULL AS TABLE_SCHEM, ");
|
||||
from = NS_LITERAL_STRING(" FROM pg_class ct, pg_class ci, pg_attribute a, pg_index i ");
|
||||
}
|
||||
|
||||
if (!aTable.IsEmpty()) {
|
||||
where.Append(NS_LITERAL_STRING(" AND ct.relname = '") + aTable);
|
||||
where.Append(PRUnichar('\''));
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(select2, " ct.relname AS TABLE_NAME, a.attname AS COLUMN_NAME, a.attnum AS KEY_SEQ, ci.relname AS PK_NAME ");
|
||||
NS_NAMED_LITERAL_STRING(where2, " WHERE ct.oid=i.indrelid AND ci.oid=i.indexrelid AND a.attrelid=ci.oid AND i.indisprimary ");
|
||||
NS_NAMED_LITERAL_STRING(order2, " ORDER BY table_name, pk_name, key_seq");
|
||||
|
||||
return RealExec(select + select2 + from + where2 + where + order2, _retval, nsnull);
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::Setup()
|
||||
{
|
||||
if (PQstatus(mConnection) == CONNECTION_BAD) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQerrorMessage(mConnection)));
|
||||
mConnection = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PQsetClientEncoding(mConnection, "UNICODE");
|
||||
|
||||
/*
|
||||
PGresult* result = PQexec(mConnection, "SET DATESTYLE TO US");
|
||||
PRInt32 stat = PQresultStatus(result);
|
||||
if (stat != PGRES_COMMAND_OK) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(result)));
|
||||
PQfinish(mConnection);
|
||||
mConnection = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*/
|
||||
|
||||
PGresult* result = PQexec(mConnection, "select version()");
|
||||
PRInt32 stat = PQresultStatus(result);
|
||||
if (stat != PGRES_TUPLES_OK) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(result)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
char* version = PQgetvalue(result, 0, 0);
|
||||
NS_ConvertUTF8toUCS2 buffer(version);
|
||||
nsAString::const_iterator start, end, iter;
|
||||
buffer.BeginReading(iter);
|
||||
buffer.EndReading(end);
|
||||
while (iter != end && !nsCRT::IsAsciiSpace(*iter))
|
||||
++iter;
|
||||
while (iter != end && nsCRT::IsAsciiSpace(*iter))
|
||||
++iter;
|
||||
start = iter;
|
||||
while (iter != end && !nsCRT::IsAsciiSpace(*iter))
|
||||
++iter;
|
||||
mServerVersion = Substring(start,iter);
|
||||
|
||||
PRInt32 numbers[3] = {0,0,0};
|
||||
mServerVersion.BeginReading(iter);
|
||||
mServerVersion.EndReading(end);
|
||||
for (PRInt32 i = 0; i < 3; i++) {
|
||||
start = iter;
|
||||
while (iter != end && *iter != PRUnichar('.'))
|
||||
++iter;
|
||||
nsAutoString v(Substring(start,iter));
|
||||
PRInt32 err;
|
||||
numbers[i] = v.ToInteger(&err);
|
||||
while (iter != end && *iter == PRUnichar('.'))
|
||||
++iter;
|
||||
}
|
||||
mVersion = SERVER_VERSION(numbers[0], numbers[1], numbers[2]);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::RealExec(const nsAString& aQuery,
|
||||
mozISqlResult** aResult, PRInt32* aAffectedRows)
|
||||
{
|
||||
if (! mConnection)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
PGresult* r;
|
||||
r = PQexec(mConnection, NS_ConvertUCS2toUTF8(aQuery).get());
|
||||
PRInt32 stat = PQresultStatus(r);
|
||||
|
||||
if (PQstatus(mConnection) == CONNECTION_BAD) {
|
||||
PQreset(mConnection);
|
||||
nsresult rv = Setup();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
r = PQexec(mConnection, NS_ConvertUCS2toUTF8(aQuery).get());
|
||||
stat = PQresultStatus(r);
|
||||
}
|
||||
|
||||
if (stat == PGRES_TUPLES_OK) {
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
static char select1[] = "select t.oid, case when t.typbasetype = 0 then t.typname else (select t2.typname from pg_type t2 where t2.oid=t.typbasetype) end as typname from pg_type t where t.oid in (";
|
||||
static char select2[] = "select oid, typname from pg_type where oid in (";
|
||||
char* select;
|
||||
if (mVersion >= SERVER_VERSION(7,3,0))
|
||||
select = select1;
|
||||
else
|
||||
select = select2;
|
||||
PRInt32 columnCount = PQnfields(r);
|
||||
char* query = (char*)malloc(strlen(select) + columnCount * 11 + 2);
|
||||
strcpy(query, select);
|
||||
for (PRInt32 i = 0; i < columnCount; i++) {
|
||||
PRInt32 oid = PQftype(r, i);
|
||||
char oidStr[11];
|
||||
if (i)
|
||||
sprintf(oidStr, ",%d", oid);
|
||||
else
|
||||
sprintf(oidStr, "%d", oid);
|
||||
strcat(query, oidStr);
|
||||
}
|
||||
strcat(query, ")");
|
||||
PGresult* types = PQexec(mConnection, query);
|
||||
free(query);
|
||||
stat = PQresultStatus(types);
|
||||
if (stat != PGRES_TUPLES_OK) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(types)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (*aResult) {
|
||||
((mozSqlResultPgsql*)*aResult)->SetResult(r, types);
|
||||
nsresult rv = ((mozSqlResult*)*aResult)->Rebuild();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
NS_ADDREF(*aResult);
|
||||
}
|
||||
else {
|
||||
mozSqlResult* result = new mozSqlResultPgsql(this, aQuery);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
((mozSqlResultPgsql*)result)->SetResult(r, types);
|
||||
nsresult rv = result->Init();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
NS_ADDREF(*aResult = result);
|
||||
}
|
||||
}
|
||||
else if (stat == PGRES_COMMAND_OK) {
|
||||
if (!aAffectedRows)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
PR_sscanf(PQcmdTuples(r), "%d", aAffectedRows);
|
||||
mLastID = PQoidValue(r);
|
||||
}
|
||||
else {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(r)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::CancelExec()
|
||||
{
|
||||
if (!PQrequestCancel(mConnection)) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQerrorMessage(mConnection)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::GetIDName(nsAString& aIDName)
|
||||
{
|
||||
aIDName = NS_LITERAL_STRING("OID");
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef mozSqlConnectionPgsql_h
|
||||
#define mozSqlConnectionPgsql_h
|
||||
|
||||
#include "libpq-fe.h"
|
||||
#include "mozSqlConnection.h"
|
||||
#include "mozISqlConnectionPgsql.h"
|
||||
|
||||
#define MOZ_SQLCONNECTIONPGSQL_CLASSNAME "PosgreSQL SQL Connection"
|
||||
#define MOZ_SQLCONNECTIONPGSQL_CID \
|
||||
{0x0cf1eefe, 0x611d, 0x48fa, {0xae, 0x27, 0x0a, 0x6f, 0x40, 0xd6, 0xa3, 0x3e }}
|
||||
#define MOZ_SQLCONNECTIONPGSQL_CONTRACTID "@mozilla.org/sql/connection;1?type=pgsql"
|
||||
|
||||
#define SERVER_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
|
||||
class mozSqlConnectionPgsql : public mozSqlConnection,
|
||||
public mozISqlConnectionPgsql
|
||||
{
|
||||
public:
|
||||
mozSqlConnectionPgsql();
|
||||
virtual ~mozSqlConnectionPgsql();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(const nsAString& aHost, PRInt32 aPort,
|
||||
const nsAString& aDatabase, const nsAString& aUsername,
|
||||
const nsAString& aPassword);
|
||||
|
||||
NS_IMETHOD GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval);
|
||||
|
||||
NS_DECL_MOZISQLCONNECTIONPGSQL
|
||||
|
||||
protected:
|
||||
nsresult Setup();
|
||||
|
||||
virtual nsresult RealExec(const nsAString& aQuery,
|
||||
mozISqlResult** aResult, PRInt32* aAffectedRows);
|
||||
|
||||
virtual nsresult CancelExec();
|
||||
|
||||
virtual nsresult GetIDName(nsAString& aIDName);
|
||||
|
||||
private:
|
||||
PGconn* mConnection;
|
||||
PRInt32 mVersion;
|
||||
};
|
||||
|
||||
#endif // mozSqlConnectionPgsql_h
|
||||
@@ -1,235 +0,0 @@
|
||||
|
||||
#include "prprf.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "mozSqlResultPgsql.h"
|
||||
|
||||
mozSqlResultPgsql::mozSqlResultPgsql(mozISqlConnection* aConnection,
|
||||
const nsAString& aQuery)
|
||||
: mozSqlResult(aConnection, aQuery),
|
||||
mResult(nsnull),
|
||||
mTypes(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mozSqlResultPgsql::SetResult(PGresult* aResult,
|
||||
PGresult* aTypes)
|
||||
{
|
||||
mResult = aResult;
|
||||
mTypes = aTypes;
|
||||
}
|
||||
|
||||
mozSqlResultPgsql::~mozSqlResultPgsql()
|
||||
{
|
||||
ClearNativeResult();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(mozSqlResultPgsql, mozSqlResult)
|
||||
NS_IMPL_RELEASE_INHERITED(mozSqlResultPgsql, mozSqlResult)
|
||||
|
||||
// QueryInterface
|
||||
NS_INTERFACE_MAP_BEGIN(mozSqlResultPgsql)
|
||||
NS_INTERFACE_MAP_ENTRY(mozISqlResultPgsql)
|
||||
NS_INTERFACE_MAP_END_INHERITING(mozSqlResult)
|
||||
|
||||
PRInt32
|
||||
mozSqlResultPgsql::GetColType(PRInt32 aColumnIndex)
|
||||
{
|
||||
PRInt32 oid = PQftype(mResult, aColumnIndex);
|
||||
|
||||
for (PRInt32 i = 0; i < PQntuples(mTypes); i++) {
|
||||
char* value = PQgetvalue(mTypes, i, 0);
|
||||
PRInt32 o;
|
||||
PR_sscanf(value, "%d", &o);
|
||||
if (o == oid) {
|
||||
char* type = PQgetvalue(mTypes, i, 1);
|
||||
if (! strcmp(type, "int2"))
|
||||
return mozISqlResult::TYPE_INT;
|
||||
else if (! strcmp(type, "int4"))
|
||||
return mozISqlResult::TYPE_INT;
|
||||
else if (! strcmp(type, "float4"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "numeric"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "date"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "time"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "timestamp"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "bool"))
|
||||
return mozISqlResult::TYPE_BOOL;
|
||||
else
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::BuildColumnInfo()
|
||||
{
|
||||
for (PRInt32 i = 0; i < PQnfields(mResult); i++) {
|
||||
char* n = PQfname(mResult, i);
|
||||
PRUnichar* name = ToNewUnicode(NS_ConvertUTF8toUCS2(n));
|
||||
PRInt32 type = GetColType(i);
|
||||
PRInt32 size = PQfsize(mResult, i);
|
||||
PRInt32 mod = PQfmod(mResult, i);
|
||||
|
||||
nsCAutoString uri(NS_LITERAL_CSTRING("http://www.mozilla.org/SQL-rdf#"));
|
||||
uri.Append(n);
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
gRDFService->GetResource(uri, getter_AddRefs(property));
|
||||
|
||||
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, size, mod, property);
|
||||
mColumnInfo.AppendElement(columnInfo);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::BuildRows()
|
||||
{
|
||||
for(PRInt32 i = 0; i < PQntuples(mResult); i++) {
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
nsresult rv = gRDFService->GetAnonymousResource(getter_AddRefs(resource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
Row* row = Row::Create(mAllocator, resource, mColumnInfo);
|
||||
|
||||
for (PRInt32 j = 0; j < mColumnInfo.Count(); j++) {
|
||||
if (! PQgetisnull(mResult, i, j)) {
|
||||
char* value = PQgetvalue(mResult, i, j);
|
||||
Cell* cell = row->mCells[j];
|
||||
cell->SetNull(PR_FALSE);
|
||||
PRInt32 type = cell->GetType();
|
||||
if (type == mozISqlResult::TYPE_STRING)
|
||||
cell->SetString(ToNewUnicode(NS_ConvertUTF8toUCS2(value)));
|
||||
else if (type == mozISqlResult::TYPE_INT)
|
||||
PR_sscanf(value, "%d", &cell->mInt);
|
||||
else if (type == mozISqlResult::TYPE_FLOAT)
|
||||
PR_sscanf(value, "%f", &cell->mFloat);
|
||||
else if (type == mozISqlResult::TYPE_DECIMAL)
|
||||
PR_sscanf(value, "%f", &cell->mFloat);
|
||||
else if (type == mozISqlResult::TYPE_DATE ||
|
||||
type == mozISqlResult::TYPE_TIME ||
|
||||
type == mozISqlResult::TYPE_DATETIME)
|
||||
PR_ParseTimeString(value, PR_FALSE, &cell->mDate);
|
||||
else if (type == mozISqlResult::TYPE_BOOL)
|
||||
cell->mBool = !strcmp(value, "t");
|
||||
}
|
||||
}
|
||||
|
||||
mRows.AppendElement(row);
|
||||
nsVoidKey key(resource);
|
||||
mSources.Put(&key, row);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
mozSqlResultPgsql::ClearNativeResult()
|
||||
{
|
||||
if (mResult) {
|
||||
PQclear(mResult);
|
||||
mResult = nsnull;
|
||||
}
|
||||
if (mTypes) {
|
||||
PQclear(mTypes);
|
||||
mTypes = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::EnsureTablePrivileges()
|
||||
{
|
||||
nsresult rv = EnsureTableName();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_NAMED_LITERAL_STRING(select, "select ");
|
||||
NS_NAMED_LITERAL_STRING(func, "has_table_privilege(SESSION_USER, '");
|
||||
NS_NAMED_LITERAL_STRING(comma, ", ");
|
||||
NS_NAMED_LITERAL_STRING(ins, "', 'INSERT')");
|
||||
NS_NAMED_LITERAL_STRING(upd, "', 'UPDATE')");
|
||||
NS_NAMED_LITERAL_STRING(del, "','DELETE')");
|
||||
|
||||
nsCOMPtr<mozISqlResult> result;
|
||||
rv = mConnection->ExecuteQuery(
|
||||
select + func + mTableName + ins +
|
||||
comma + func + mTableName + upd +
|
||||
comma + func + mTableName + del,
|
||||
getter_AddRefs(result));
|
||||
if (NS_FAILED(rv)) {
|
||||
mConnection->GetErrorMessage(mErrorMessage);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<mozISqlResultEnumerator> enumerator;
|
||||
rv = result->Enumerate(getter_AddRefs(enumerator));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = enumerator->First();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = enumerator->GetBool(0, &mCanInsert);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = enumerator->GetBool(1, &mCanUpdate);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
return enumerator->GetBool(2, &mCanDelete);
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::CanInsert(PRBool* _retval)
|
||||
{
|
||||
if (mCanInsert >= 0) {
|
||||
*_retval = mCanInsert;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureTablePrivileges();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mCanInsert;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::CanUpdate(PRBool* _retval)
|
||||
{
|
||||
if (mCanUpdate >= 0) {
|
||||
*_retval = mCanUpdate;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureTablePrivileges();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mCanUpdate;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::CanDelete(PRBool* _retval)
|
||||
{
|
||||
if (mCanDelete >= 0) {
|
||||
*_retval = mCanDelete;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureTablePrivileges();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mCanDelete;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef mozSqlResultPgsql_h
|
||||
#define mozSqlResultPgsql_h
|
||||
|
||||
#include "libpq-fe.h"
|
||||
#include "mozSqlResult.h"
|
||||
#include "mozISqlResultPgsql.h"
|
||||
|
||||
class mozSqlResultPgsql : public mozSqlResult,
|
||||
public mozISqlResultPgsql
|
||||
{
|
||||
public:
|
||||
mozSqlResultPgsql(mozISqlConnection* aConnection,
|
||||
const nsAString& aQuery);
|
||||
void SetResult(PGresult* aResult,
|
||||
PGresult* aTypes);
|
||||
virtual ~mozSqlResultPgsql();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLRESULTPGSQL
|
||||
|
||||
protected:
|
||||
PRInt32 GetColType(PRInt32 aColumnIndex);
|
||||
|
||||
virtual nsresult BuildColumnInfo();
|
||||
virtual nsresult BuildRows();
|
||||
virtual void ClearNativeResult();
|
||||
|
||||
nsresult EnsureTablePrivileges();
|
||||
virtual nsresult CanInsert(PRBool* _retval);
|
||||
virtual nsresult CanUpdate(PRBool* _retval);
|
||||
virtual nsresult CanDelete(PRBool* _retval);
|
||||
|
||||
private:
|
||||
PGresult* mResult;
|
||||
PGresult* mTypes;
|
||||
};
|
||||
|
||||
#endif // mozSqlResultPgsql_h
|
||||
@@ -1,15 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
XPI_FILE = sqltest-$(shell date +%Y%m%d).xpi
|
||||
|
||||
xpi:
|
||||
zip -j $(DIST)/$(XPI_FILE) $(srcdir)/install.js
|
||||
cd $(DIST); zip -r $(XPI_FILE) \
|
||||
bin/chrome/sqltest.jar
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the packages being supplied by this jar -->
|
||||
<RDF:Seq about="urn:mozilla:package:root">
|
||||
<RDF:li resource="urn:mozilla:package:sqltest"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- package information -->
|
||||
<RDF:Description about="urn:mozilla:package:sqltest"
|
||||
chrome:displayName="SQL test"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:name="sqltest">
|
||||
</RDF:Description>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,57 +0,0 @@
|
||||
// this function verifies disk space in kilobytes
|
||||
function verifyDiskSpace(dirPath, spaceRequired)
|
||||
{
|
||||
var spaceAvailable;
|
||||
|
||||
// Get the available disk space on the given path
|
||||
spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
|
||||
|
||||
// Convert the available disk space into kilobytes
|
||||
spaceAvailable = parseInt(spaceAvailable / 1024);
|
||||
|
||||
// do the verification
|
||||
if(spaceAvailable < spaceRequired)
|
||||
{
|
||||
logComment("Insufficient disk space: " + dirPath);
|
||||
logComment(" required : " + spaceRequired + " K");
|
||||
logComment(" available: " + spaceAvailable + " K");
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
var srDest = 100;
|
||||
|
||||
var err = initInstall("SQL test", "SQLTEST", "0.1");
|
||||
logComment("initInstall: " + err);
|
||||
|
||||
var fProgram = getFolder("Program");
|
||||
logComment("fProgram: " + fProgram);
|
||||
|
||||
if (verifyDiskSpace(fProgram, srDest))
|
||||
{
|
||||
err = addDirectory("Program", "0.1", "bin", fProgram, "", true);
|
||||
|
||||
logComment("addDirectory() returned: " + err);
|
||||
|
||||
var chromeFolder = getFolder("Chrome", "sqltest.jar");
|
||||
registerChrome(CONTENT | DELAYED_CHROME, chromeFolder, "content/sqltest/");
|
||||
|
||||
err = getLastError();
|
||||
if (err == ACCESS_DENIED) {
|
||||
alert("Unable to write to program directory " + fProgram + ".\n You will need to restart the browser with administrator/root privileges to install this software. After installing as root (or administrator), you will need to restart the browser one more time to register the installed software.\n After the second restart, you can go back to running the browser without privileges!");
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else if (err != SUCCESS) {
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else {
|
||||
performInstall();
|
||||
logComment("performInstall() returned: " + err);
|
||||
}
|
||||
}
|
||||
else
|
||||
cancelInstall(INSUFFICIENT_DISK_SPACE);
|
||||
@@ -1,7 +0,0 @@
|
||||
sqltest.jar:
|
||||
content/sqltest/contents.rdf (contents.rdf)
|
||||
content/sqltest/sqltest.xul (sqltest.xul)
|
||||
content/sqltest/sqltest.js (sqltest.js)
|
||||
content/sqltest/sqltest.css (sqltest.css)
|
||||
content/sqltest/sqltestDialog.xul (sqltestDialog.xul)
|
||||
content/sqltest/sqltestDialog.js (sqltestDialog.js)
|
||||
@@ -1,8 +0,0 @@
|
||||
treechildren:-moz-tree-cell {
|
||||
border-right: 1px solid ThreeDFace;
|
||||
border-bottom: 1px solid ThreeDFace;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
height: 10px;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
const alias = "urn:aliases:sqltest";
|
||||
const complete = Components.interfaces.mozISqlRequest.STATUS_COMPLETE;
|
||||
|
||||
var connection;
|
||||
var result;
|
||||
|
||||
var startupObserver = {
|
||||
onStartRequest: function(request, ctxt) {
|
||||
},
|
||||
onStopRequest: function(request, ctxt) {
|
||||
if (request.status == complete) {
|
||||
result = request.result;
|
||||
var ds = result.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
|
||||
var menulist = document.getElementById("statesMenulist");
|
||||
menulist.database.AddDataSource(ds);
|
||||
menulist.builder.rebuild();
|
||||
menulist.selectedIndex = 0;
|
||||
|
||||
var tree = document.getElementById("statesTree");
|
||||
tree.database.AddDataSource(ds);
|
||||
tree.builder.rebuild();
|
||||
}
|
||||
else {
|
||||
alert(request.errorMessage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, ctxt) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, ctxt) {
|
||||
if (request.status == complete) {
|
||||
var element = document.getElementById("asyncStateName");
|
||||
if (request.result.rowCount) {
|
||||
var enumerator = request.result.enumerate();
|
||||
enumerator.first();
|
||||
element.value = enumerator.getVariant(0);
|
||||
}
|
||||
else {
|
||||
element.value = "Not found";
|
||||
}
|
||||
}
|
||||
else {
|
||||
alert(request.errorMessage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
var service = Components.classes["@mozilla.org/sql/service;1"]
|
||||
.getService(Components.interfaces.mozISqlService);
|
||||
|
||||
if (!service.hasAlias(alias)) {
|
||||
alert("The alias for the sqltest was not defined.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connection = service.getConnection(alias);
|
||||
}
|
||||
catch (ex) {
|
||||
alert(service.errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
var query = "select code, name from states";
|
||||
var request = connection.asyncExecuteQuery(query, null, startupObserver);
|
||||
}
|
||||
|
||||
function syncFindState() {
|
||||
var code = document.getElementById("syncStateCode").value
|
||||
var query = "select name from states where code = '" + code + "'";
|
||||
try {
|
||||
var result = connection.executeQuery(query);
|
||||
var element = document.getElementById("syncStateName");
|
||||
if (result.rowCount) {
|
||||
var enumerator = result.enumerate();
|
||||
enumerator.first();
|
||||
element.value = enumerator.getVariant(0);
|
||||
}
|
||||
else {
|
||||
element.value = "Not found";
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
alert(connection.errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
function asyncFindState() {
|
||||
var code = document.getElementById("asyncStateCode").value;
|
||||
var query = "select name from states where code = '" + code + "'";
|
||||
var request = connection.asyncExecuteQuery(query, null, observer);
|
||||
}
|
||||
|
||||
function getSelectedRowIndex() {
|
||||
var tree = document.getElementById("statesTree");
|
||||
var currentIndex = tree.currentIndex;
|
||||
var resource = tree.builderView.getResourceAtIndex(currentIndex);
|
||||
var datasource = result.QueryInterface(Components.interfaces.mozISqlDataSource);
|
||||
return datasource.getIndexOfResource(resource);
|
||||
}
|
||||
|
||||
function doInsert() {
|
||||
window.openDialog("sqltestDialog.xul", "testDialog", "chrome,modal=yes,resizable=no", result);
|
||||
}
|
||||
|
||||
function doUpdate() {
|
||||
var rowIndex = this.getSelectedRowIndex();
|
||||
window.openDialog("sqltestDialog.xul", "testDialog", "chrome,modal=yes,resizable=no", result, rowIndex);
|
||||
}
|
||||
|
||||
function doDelete() {
|
||||
var rowIndex = this.getSelectedRowIndex();
|
||||
var enumerator = result.enumerate();
|
||||
enumerator.absolute(rowIndex);
|
||||
try {
|
||||
enumerator.deleteRow();
|
||||
}
|
||||
catch(ex) {
|
||||
alert(enumerator.errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="sqltest.css" type="text/css"?>
|
||||
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
orient="vertical"
|
||||
width="640" height="480"
|
||||
title="SQL test"
|
||||
onload="init()">
|
||||
|
||||
<script type="application/x-javascript" src="sqltest.js"/>
|
||||
|
||||
<popupset>
|
||||
<popup id="editContextMenu">
|
||||
<menuitem label="Insert" oncommand="doInsert()"/>
|
||||
<menuitem label="Update" oncommand="doUpdate()"/>
|
||||
<menuitem label="Delete" oncommand="doDelete()"/>
|
||||
</popup>
|
||||
</popupset>
|
||||
|
||||
<tabbox flex="1">
|
||||
<tabs>
|
||||
<tab label="Sync test"/>
|
||||
<tab label="Async test"/>
|
||||
<tab label="Widgets"/>
|
||||
</tabs>
|
||||
<tabpanels flex="1">
|
||||
<vbox>
|
||||
<text class="label" value="Type a state code and then hit ENTER. You should get a state name."/>
|
||||
<spacer class="spacer"/>
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="State code:"/>
|
||||
<hbox>
|
||||
<textbox id="syncStateCode" size="2" maxlength="2" onkeyup="if (event.keyCode == 13) syncFindState()"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="State name:"/>
|
||||
<textbox id="syncStateName"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<text class="label" value="Type a state code and then hit ENTER. You should get a state name."/>
|
||||
<spacer class="spacer"/>
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="State code:"/>
|
||||
<hbox>
|
||||
<textbox id="asyncStateCode" size="2" maxlength="2" onkeyup="if (event.keyCode == 13) asyncFindState()"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="State name:"/>
|
||||
<textbox id="asyncStateName"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<text class="label" value="You should see a menulist filled with all the states."/>
|
||||
<spacer class="spacer"/>
|
||||
<hbox>
|
||||
<menulist id="statesMenulist"
|
||||
datasources="rdf:null" ref="SQL:ResultRoot">
|
||||
<template>
|
||||
<menupopup>
|
||||
<menuitem uri="..."
|
||||
value="rdf:http://www.mozilla.org/SQL-rdf#code"
|
||||
label="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
</menupopup>
|
||||
</template>
|
||||
</menulist>
|
||||
</hbox>
|
||||
<spacer class="spacer"/>
|
||||
<text value="You should see codes and names of all states in this tree. You can even edit them using the context menu."/>
|
||||
<spacer class="spacer"/>
|
||||
<tree id="statesTree" flex="1"
|
||||
context="editContextMenu"
|
||||
seltype="single" enableColumnDrag="true"
|
||||
datasources="rdf:null" ref="SQL:ResultRoot" flags="dont-build-content">
|
||||
<treecols>
|
||||
<treecol id="codeCol"
|
||||
label="State code"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#code"
|
||||
sortActive="true" sortDirection="ascending"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol id="nameCol" flex="1"
|
||||
label="State name"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
</treecols>
|
||||
<template>
|
||||
<treechildren>
|
||||
<treeitem uri="rdf:*">
|
||||
<treerow>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#code"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
</template>
|
||||
</tree>
|
||||
</vbox>
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
|
||||
</window>
|
||||
@@ -1,41 +0,0 @@
|
||||
var result;
|
||||
var enumerator;
|
||||
|
||||
function init() {
|
||||
result = window.arguments[0];
|
||||
enumerator = result.enumerate();
|
||||
if (window.arguments.length == 2) {
|
||||
enumerator.absolute(window.arguments[1]);
|
||||
var columnCount = result.columnCount;
|
||||
for(var i = 0; i < columnCount; i++) {
|
||||
if (!enumerator.isNull(i)) {
|
||||
var element = document.getElementById(result.getColumnName(i));
|
||||
element.value = enumerator.getVariant(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onAccept() {
|
||||
var columnCount = result.columnCount;
|
||||
for (var i = 0; i < columnCount; i++) {
|
||||
var element = document.getElementById(result.getColumnName(i));
|
||||
if (element.value)
|
||||
enumerator.setVariant(i, element.value);
|
||||
else
|
||||
enumerator.setNull(i);
|
||||
}
|
||||
|
||||
try {
|
||||
if (window.arguments.length == 2)
|
||||
enumerator.updateRow();
|
||||
else
|
||||
enumerator.insertRow();
|
||||
}
|
||||
catch(ex) {
|
||||
alert(enumerator.errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<dialog id="testDialog"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="Test dialog"
|
||||
buttons="accept,cancel" buttonpack="center"
|
||||
ondialogaccept="return onAccept();"
|
||||
onload="init()">
|
||||
|
||||
<script type="application/x-javascript" src="sqltestDialog.js"/>
|
||||
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="Code:"/>
|
||||
<hbox>
|
||||
<textbox id="code" size="2" maxlength="2" oninput="this.value = this.value.toUpperCase()"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<label value="Name:"/>
|
||||
<textbox id="name" size="30" maxlength="30"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
</dialog>
|
||||
@@ -1,4 +0,0 @@
|
||||
create table states (
|
||||
code varchar(2) primary key,
|
||||
name varchar(30)
|
||||
);
|
||||
@@ -1,51 +0,0 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
DC Washington,D.C.
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
@@ -1,6 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
48
mozilla/mozilla.kdevprj
Normal file
48
mozilla/mozilla.kdevprj
Normal file
@@ -0,0 +1,48 @@
|
||||
# KDE Config File
|
||||
[mozilla.lsm]
|
||||
install_location=
|
||||
dist=true
|
||||
install=false
|
||||
type=DATA
|
||||
[Config for BinMakefileAm]
|
||||
ldflags=
|
||||
cxxflags=-O0 -g3 -Wall
|
||||
bin_program=mozilla
|
||||
[po/Makefile.am]
|
||||
sub_dirs=
|
||||
type=po
|
||||
[LFV Groups]
|
||||
Dialogs=*.kdevdlg,
|
||||
Others=*,
|
||||
Translations=*.po,
|
||||
groups=Headers,Sources,Dialogs,Translations,Others,
|
||||
Sources=*.cpp,*.c,*.cc,*.C,*.cxx,*.ec,*.ecpp,*.lxx,*.l++,*.ll,*.l,
|
||||
Headers=*.h,*.hh,*.hxx,*.hpp,*.H,
|
||||
[mozilla.kdevprj]
|
||||
install_location=
|
||||
dist=true
|
||||
install=false
|
||||
type=DATA
|
||||
[mozilla/docs/en/Makefile.am]
|
||||
sub_dirs=
|
||||
type=normal
|
||||
[mozilla/Makefile.am]
|
||||
sub_dirs=
|
||||
type=prog_main
|
||||
[General]
|
||||
makefiles=Makefile.am,mozilla/Makefile.am,mozilla/docs/Makefile.am,mozilla/docs/en/Makefile.am,po/Makefile.am,
|
||||
version_control=CVS
|
||||
author=Heikki Toivonen
|
||||
project_type=normal_empty
|
||||
sub_dir=mozilla/
|
||||
version=0.1
|
||||
project_name=Mozilla
|
||||
email=heikki@netscape.com
|
||||
kdevprj_version=1.2
|
||||
[Makefile.am]
|
||||
files=mozilla.kdevprj,mozilla.lsm,
|
||||
sub_dirs=mozilla,
|
||||
type=normal
|
||||
[mozilla/docs/Makefile.am]
|
||||
sub_dirs=
|
||||
type=normal
|
||||
14
mozilla/mozilla.lsm
Normal file
14
mozilla/mozilla.lsm
Normal file
@@ -0,0 +1,14 @@
|
||||
Begin3
|
||||
Title: Mozilla
|
||||
Version: 0.1
|
||||
Entered-date:
|
||||
Description:
|
||||
Keywords:
|
||||
Author: Heikki Toivonen <heikki@netscape.com>
|
||||
Maintained-by: Heikki Toivonen <heikki@netscape.com>
|
||||
Primary-site:
|
||||
Home-page: http://
|
||||
Original-site:
|
||||
Platforms: Linux and other Unices
|
||||
Copying-policy: GNU Public License
|
||||
End
|
||||
20
mozilla/mozilla/templates/cpp_template
Normal file
20
mozilla/mozilla/templates/cpp_template
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
20
mozilla/mozilla/templates/header_template
Normal file
20
mozilla/mozilla/templates/header_template
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
Reference in New Issue
Block a user