зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 196576. Add MySQL support.
r=me patch by Neil Deakin <enndeakin@sympatico.ca>
This commit is contained in:
Родитель
de524e2d65
Коммит
a6e4556cd5
|
@ -51,6 +51,10 @@ ifdef MOZ_ENABLE_SQLITE
|
||||||
DIRS += sqlite
|
DIRS += sqlite
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef MOZ_ENABLE_MYSQL
|
||||||
|
DIRS += mysql
|
||||||
|
endif
|
||||||
|
|
||||||
DIRS += build
|
DIRS += build
|
||||||
|
|
||||||
ifdef ENABLE_TESTS
|
ifdef ENABLE_TESTS
|
||||||
|
|
|
@ -1295,22 +1295,28 @@ mozSqlResult::InsertRow(Row* aSrcRow, PRInt32* _retval)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<mozISqlResult> result;
|
nsAutoString IDName;
|
||||||
rv = GetValues(aSrcRow, getter_AddRefs(result), PR_TRUE);
|
((mozSqlConnection*)mConnection.get())->GetIDName(IDName);
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
PRInt32 rowCount;
|
// assume that if the IDName is empty that we don't need to re-get the last row
|
||||||
result->GetRowCount(&rowCount);
|
if (!IDName.IsEmpty()){
|
||||||
if (rowCount == 0) {
|
nsCOMPtr<mozISqlResult> result;
|
||||||
*_retval = 0;
|
rv = GetValues(aSrcRow, getter_AddRefs(result), PR_TRUE);
|
||||||
return NS_OK;
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
PRInt32 rowCount;
|
||||||
|
result->GetRowCount(&rowCount);
|
||||||
|
if (rowCount == 0) {
|
||||||
|
*_retval = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = CopyValues(result, aSrcRow);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = CopyValues(result, aSrcRow);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIRDFResource> resource;
|
nsCOMPtr<nsIRDFResource> resource;
|
||||||
gRDFService->GetAnonymousResource(getter_AddRefs(resource));
|
gRDFService->GetAnonymousResource(getter_AddRefs(resource));
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,10 @@ class ColumnInfo {
|
||||||
PRInt32 aType,
|
PRInt32 aType,
|
||||||
PRInt32 aSize,
|
PRInt32 aSize,
|
||||||
PRInt32 aMod,
|
PRInt32 aMod,
|
||||||
|
PRBool aIsPrimaryKey,
|
||||||
nsIRDFResource* aProperty) {
|
nsIRDFResource* aProperty) {
|
||||||
void* place = aAllocator.Alloc(sizeof(ColumnInfo));
|
void* place = aAllocator.Alloc(sizeof(ColumnInfo));
|
||||||
return place ? ::new(place) ColumnInfo(aName, aType, aSize, aMod, aProperty) : nsnull;
|
return place ? ::new(place) ColumnInfo(aName, aType, aSize, aMod, aIsPrimaryKey, aProperty) : nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -81,11 +82,13 @@ class ColumnInfo {
|
||||||
aAllocator.Free(aColumnInfo, sizeof(ColumnInfo));
|
aAllocator.Free(aColumnInfo, sizeof(ColumnInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnInfo(PRUnichar* aName, PRInt32 aType, PRInt32 aSize, PRInt32 aMod, nsIRDFResource* aProperty)
|
ColumnInfo(PRUnichar* aName, PRInt32 aType, PRInt32 aSize, PRInt32 aMod,
|
||||||
|
PRBool aIsPrimaryKey, nsIRDFResource* aProperty)
|
||||||
: mName(aName),
|
: mName(aName),
|
||||||
mType(aType),
|
mType(aType),
|
||||||
mSize(aSize),
|
mSize(aSize),
|
||||||
mMod(aMod),
|
mMod(aMod),
|
||||||
|
mIsPrimaryKey(aIsPrimaryKey),
|
||||||
mProperty(aProperty) {
|
mProperty(aProperty) {
|
||||||
NS_IF_ADDREF(mProperty);
|
NS_IF_ADDREF(mProperty);
|
||||||
}
|
}
|
||||||
|
@ -100,6 +103,7 @@ class ColumnInfo {
|
||||||
PRInt32 mType;
|
PRInt32 mType;
|
||||||
PRInt32 mSize;
|
PRInt32 mSize;
|
||||||
PRInt32 mMod;
|
PRInt32 mMod;
|
||||||
|
PRBool mIsPrimaryKey;
|
||||||
nsIRDFResource* mProperty;
|
nsIRDFResource* mProperty;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -337,10 +341,10 @@ class mozSqlResult : public mozISqlResult,
|
||||||
void ClearRows();
|
void ClearRows();
|
||||||
|
|
||||||
nsresult EnsureTableName();
|
nsresult EnsureTableName();
|
||||||
nsresult EnsurePrimaryKeys();
|
virtual nsresult EnsurePrimaryKeys();
|
||||||
|
|
||||||
void AppendValue(Cell* aCell, nsAutoString& aValues);
|
void AppendValue(Cell* aCell, nsAutoString& aValues);
|
||||||
nsresult AppendKeys(Row* aRow, nsAutoString& aKeys);
|
virtual nsresult AppendKeys(Row* aRow, nsAutoString& aKeys);
|
||||||
nsresult GetValues(Row* aRow, mozISqlResult** aResult, PRBool aUseID);
|
nsresult GetValues(Row* aRow, mozISqlResult** aResult, PRBool aUseID);
|
||||||
nsresult CopyValues(mozISqlResult* aResult, Row* aRow);
|
nsresult CopyValues(mozISqlResult* aResult, Row* aRow);
|
||||||
|
|
||||||
|
|
|
@ -54,5 +54,6 @@ xpi:
|
||||||
bin/components/sql.xpt \
|
bin/components/sql.xpt \
|
||||||
bin/components/sqlpgsql.xpt \
|
bin/components/sqlpgsql.xpt \
|
||||||
bin/components/sqlsqlite.xpt \
|
bin/components/sqlsqlite.xpt \
|
||||||
|
bin/components/sqlmysql.xpt \
|
||||||
bin/components/$(LIB_PREFIX)sql$(DLL_SUFFIX) \
|
bin/components/$(LIB_PREFIX)sql$(DLL_SUFFIX) \
|
||||||
bin/chrome/sql.jar
|
bin/chrome/sql.jar
|
||||||
|
|
|
@ -75,6 +75,12 @@ SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)sqlsqlite_s.$(LIB_SUFFIX)
|
||||||
EXTRA_DSO_LDOPTS += -L$(MOZ_SQLITE_LIBS) -lsqlite3
|
EXTRA_DSO_LDOPTS += -L$(MOZ_SQLITE_LIBS) -lsqlite3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef MOZ_ENABLE_MYSQL
|
||||||
|
DEFINES += -DMOZ_ENABLE_MYSQL
|
||||||
|
SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)sqlmysql_s.$(LIB_SUFFIX)
|
||||||
|
EXTRA_DSO_LDOPTS += -L$(MOZ_MYSQL_LIBS) -lmysqlclient -lz
|
||||||
|
endif
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
ifdef MOZ_ENABLE_PGSQL
|
ifdef MOZ_ENABLE_PGSQL
|
||||||
|
@ -85,3 +91,6 @@ ifdef MOZ_ENABLE_SQLITE
|
||||||
INCLUDES += -I$(MOZ_SQLITE_INCLUDES)
|
INCLUDES += -I$(MOZ_SQLITE_INCLUDES)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef MOZ_ENABLE_MYSQL
|
||||||
|
INCLUDES += -I$(MOZ_MYSQL_INCLUDES)
|
||||||
|
endif
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
#ifdef MOZ_ENABLE_SQLITE
|
#ifdef MOZ_ENABLE_SQLITE
|
||||||
#include "mozSqlConnectionSqlite.h"
|
#include "mozSqlConnectionSqlite.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MOZ_ENABLE_MYSQL
|
||||||
|
#include "mozSqlConnectionMysql.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozSqlService, Init)
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozSqlService, Init)
|
||||||
#ifdef MOZ_ENABLE_PGSQL
|
#ifdef MOZ_ENABLE_PGSQL
|
||||||
|
@ -50,6 +53,9 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(mozSqlConnectionPgsql)
|
||||||
#ifdef MOZ_ENABLE_SQLITE
|
#ifdef MOZ_ENABLE_SQLITE
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSqlConnectionSqlite)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSqlConnectionSqlite)
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MOZ_ENABLE_MYSQL
|
||||||
|
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSqlConnectionMysql)
|
||||||
|
#endif
|
||||||
|
|
||||||
static nsModuleComponentInfo components[] =
|
static nsModuleComponentInfo components[] =
|
||||||
{
|
{
|
||||||
|
@ -77,6 +83,13 @@ static nsModuleComponentInfo components[] =
|
||||||
mozSqlConnectionSqliteConstructor
|
mozSqlConnectionSqliteConstructor
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MOZ_ENABLE_MYSQL
|
||||||
|
,{ MOZ_SQLCONNECTIONMYSQL_CLASSNAME,
|
||||||
|
MOZ_SQLCONNECTIONMYSQL_CID,
|
||||||
|
MOZ_SQLCONNECTIONMYSQL_CONTRACTID,
|
||||||
|
mozSqlConnectionMysqlConstructor
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_NSGETMODULE("mozSqlModule", components)
|
NS_IMPL_NSGETMODULE("mozSqlModule", components)
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
# ***** 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 Jan Varga
|
||||||
|
# Portions created by the Initial Developer are Copyright (C) 2003
|
||||||
|
# the Initial Developer. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
# 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 ***** */
|
||||||
|
|
||||||
|
DEPTH = ../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
DIRS = \
|
||||||
|
public \
|
||||||
|
src
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,49 @@
|
||||||
|
# ***** 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 Jan Varga
|
||||||
|
# Portions created by the Initial Developer are Copyright (C) 2003
|
||||||
|
# the Initial Developer. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
# 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 ***** */
|
||||||
|
|
||||||
|
DEPTH = ../../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
MODULE = sql
|
||||||
|
XPIDL_MODULE = sqlmysql
|
||||||
|
|
||||||
|
XPIDLSRCS = \
|
||||||
|
mozISqlConnectionMysql.idl \
|
||||||
|
mozISqlResultMysql.idl \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ***** 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 Neil Deakin
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
[scriptable, uuid(47327928-c789-11d8-9fa2-aa29858f77e5)]
|
||||||
|
|
||||||
|
interface mozISqlConnectionMysql : nsISupports
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ***** 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 Neil Deakin
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
[scriptable, uuid(4587d956-c789-11d8-96e2-bb3b01bace14)]
|
||||||
|
|
||||||
|
interface mozISqlResultMysql : nsISupports
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
# ***** 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 Jan Varga
|
||||||
|
# Portions created by the Initial Developer are Copyright (C) 2003
|
||||||
|
# the Initial Developer. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
# 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 ***** */
|
||||||
|
|
||||||
|
DEPTH = ../../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
MODULE = sql
|
||||||
|
LIBRARY_NAME = sqlmysql_s
|
||||||
|
REQUIRES = xpcom \
|
||||||
|
string \
|
||||||
|
locale \
|
||||||
|
rdf \
|
||||||
|
dom \
|
||||||
|
layout \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
CPPSRCS = \
|
||||||
|
mozSqlConnectionMysql.cpp \
|
||||||
|
mozSqlResultMysql.cpp
|
||||||
|
|
||||||
|
EXPORTS = \
|
||||||
|
mozSqlConnectionMysql.h \
|
||||||
|
mozSqlResultMysql.h
|
||||||
|
|
||||||
|
FORCE_STATIC_LIB=1
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
INCLUDES += -I$(MOZ_MYSQL_INCLUDES)
|
|
@ -0,0 +1,188 @@
|
||||||
|
/* ***** 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 Neil Deakin
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 "nsReadableUtils.h"
|
||||||
|
#include "mozSqlConnectionMysql.h"
|
||||||
|
#include "mozSqlResultMysql.h"
|
||||||
|
|
||||||
|
mozSqlConnectionMysql::mozSqlConnectionMysql()
|
||||||
|
: mConnection(nsnull)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
mozSqlConnectionMysql::~mozSqlConnectionMysql()
|
||||||
|
{
|
||||||
|
if (mConnection)
|
||||||
|
mysql_close(mConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF_INHERITED(mozSqlConnectionMysql, mozSqlConnection)
|
||||||
|
NS_IMPL_RELEASE_INHERITED(mozSqlConnectionMysql, mozSqlConnection)
|
||||||
|
|
||||||
|
// QueryInterface
|
||||||
|
NS_INTERFACE_MAP_BEGIN(mozSqlConnectionMysql)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(mozISqlConnectionMysql)
|
||||||
|
NS_INTERFACE_MAP_END_INHERITING(mozSqlConnection)
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
mozSqlConnectionMysql::Init(const nsAString &aHost, PRInt32 aPort,
|
||||||
|
const nsAString &aDatabase, const nsAString &aUsername,
|
||||||
|
const nsAString &aPassword)
|
||||||
|
{
|
||||||
|
if (mConnection)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
if (aPort == -1)
|
||||||
|
aPort = 0;
|
||||||
|
|
||||||
|
mConnection = mysql_init((MYSQL *) nsnull);
|
||||||
|
if (!mConnection){
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mysql_real_connect(mConnection,
|
||||||
|
NS_ConvertUCS2toUTF8(aHost).get(),
|
||||||
|
NS_ConvertUCS2toUTF8(aUsername).get(),
|
||||||
|
NS_ConvertUCS2toUTF8(aPassword).get(),
|
||||||
|
NS_ConvertUCS2toUTF8(aDatabase).get(),
|
||||||
|
aPort, nsnull, 0)){
|
||||||
|
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));
|
||||||
|
mConnection = nsnull;
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
mozSqlConnectionMysql::GetServerVersion(nsAString &aServerVersion)
|
||||||
|
{
|
||||||
|
if (!mConnection)
|
||||||
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
|
if (mServerVersion.IsEmpty()){
|
||||||
|
mServerVersion.Assign(NS_ConvertUTF8toUCS2(mysql_get_server_info(mConnection)));
|
||||||
|
}
|
||||||
|
aServerVersion.Assign(mServerVersion);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
mozSqlConnectionMysql::GetPrimaryKeys(const nsAString& aSchema,
|
||||||
|
const nsAString& aTable,
|
||||||
|
mozISqlResult** aResult)
|
||||||
|
{
|
||||||
|
// XXX this can be done with 'show columns from <table>', but it can't be
|
||||||
|
// filtered just for primary keys, which are listed in column 3
|
||||||
|
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlConnectionMysql::RealExec(const nsAString& aQuery,
|
||||||
|
mozISqlResult** aResult, PRInt32* aAffectedRows)
|
||||||
|
{
|
||||||
|
if (!mConnection)
|
||||||
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
|
if (mysql_query(mConnection, NS_ConvertUCS2toUTF8(aQuery).get())){
|
||||||
|
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aResult){
|
||||||
|
if (!aAffectedRows)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
my_ulonglong numrows = (PRInt32)mysql_affected_rows(mConnection);
|
||||||
|
*aAffectedRows = ((numrows == (my_ulonglong)-1) ? 0 : (PRInt32)numrows);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aResult = nsnull;
|
||||||
|
|
||||||
|
MYSQL_RES *rowresults = mysql_store_result(mConnection);
|
||||||
|
if (!rowresults){
|
||||||
|
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
mozSqlResult *mozresult = new mozSqlResultMysql(this, aQuery);
|
||||||
|
if (!mozresult){
|
||||||
|
mysql_free_result(rowresults);
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
((mozSqlResultMysql*)mozresult)->SetResult(rowresults);
|
||||||
|
nsresult rv = mozresult->Init();
|
||||||
|
if (NS_FAILED(rv)){
|
||||||
|
delete mozresult;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aResult = mozresult;
|
||||||
|
NS_ADDREF(*aResult);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlConnectionMysql::CancelExec()
|
||||||
|
{
|
||||||
|
unsigned long id = mysql_thread_id(mConnection);
|
||||||
|
mysql_kill(mConnection, id);
|
||||||
|
|
||||||
|
if (mysql_errno(mConnection)) {
|
||||||
|
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection)));
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_ping(mConnection);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlConnectionMysql::GetIDName(nsAString& aIDName)
|
||||||
|
{
|
||||||
|
aIDName.Truncate();
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/* ***** 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 Neil Deakin
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef mozSqlConnectionMysql_h
|
||||||
|
#define mozSqlConnectionMysql_h
|
||||||
|
|
||||||
|
#include "mysql.h"
|
||||||
|
|
||||||
|
#include "mozSqlConnection.h"
|
||||||
|
#include "mozISqlConnectionMysql.h"
|
||||||
|
|
||||||
|
#define MOZ_SQLCONNECTIONMYSQL_CLASSNAME "Mysql SQL Connection"
|
||||||
|
|
||||||
|
#define MOZ_SQLCONNECTIONMYSQL_CID \
|
||||||
|
{0x582dcad4, 0xc789, 0x11d8, {0x89, 0xf4, 0xd0, 0x5c, 0x55, 0x80, 0x13, 0xcc }}
|
||||||
|
|
||||||
|
#define MOZ_SQLCONNECTIONMYSQL_CONTRACTID "@mozilla.org/sql/connection;1?type=mysql"
|
||||||
|
|
||||||
|
class mozSqlConnectionMysql : public mozSqlConnection,
|
||||||
|
public mozISqlConnectionMysql
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
mozSqlConnectionMysql();
|
||||||
|
virtual ~mozSqlConnectionMysql();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD Init(const nsAString& aHost, PRInt32 aPort,
|
||||||
|
const nsAString& aDatabase, const nsAString& aUsername,
|
||||||
|
const nsAString& aPassword);
|
||||||
|
|
||||||
|
NS_IMETHODIMP GetServerVersion(nsAString &aServerVersion);
|
||||||
|
|
||||||
|
NS_IMETHOD GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval);
|
||||||
|
|
||||||
|
NS_DECL_MOZISQLCONNECTIONMYSQL
|
||||||
|
|
||||||
|
MYSQL *mConnection;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual nsresult RealExec(const nsAString& aQuery,
|
||||||
|
mozISqlResult** aResult, PRInt32* aAffectedRows);
|
||||||
|
|
||||||
|
virtual nsresult CancelExec();
|
||||||
|
|
||||||
|
virtual nsresult GetIDName(nsAString& aIDName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// MysqlConnection* mConnection;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // mozSqlConnectionMysql_h
|
|
@ -0,0 +1,224 @@
|
||||||
|
/* ***** 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 Neil Deakin
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 "prprf.h"
|
||||||
|
#include "nsReadableUtils.h"
|
||||||
|
#include "mozSqlResultMysql.h"
|
||||||
|
|
||||||
|
mozSqlResultMysql::mozSqlResultMysql(mozISqlConnection* aConnection,
|
||||||
|
const nsAString& aQuery)
|
||||||
|
: mozSqlResult(aConnection, aQuery),
|
||||||
|
mResult(nsnull)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mozSqlResultMysql::SetResult(MYSQL_RES *aResult)
|
||||||
|
{
|
||||||
|
if (mResult){
|
||||||
|
mysql_free_result(mResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
mResult = aResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
mozSqlResultMysql::~mozSqlResultMysql()
|
||||||
|
{
|
||||||
|
ClearNativeResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF_INHERITED(mozSqlResultMysql, mozSqlResult)
|
||||||
|
NS_IMPL_RELEASE_INHERITED(mozSqlResultMysql, mozSqlResult)
|
||||||
|
|
||||||
|
// QueryInterface
|
||||||
|
NS_INTERFACE_MAP_BEGIN(mozSqlResultMysql)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(mozISqlResultMysql)
|
||||||
|
NS_INTERFACE_MAP_END_INHERITING(mozSqlResult)
|
||||||
|
|
||||||
|
PRInt32
|
||||||
|
mozSqlResultMysql::GetColType(MYSQL_FIELD *aField)
|
||||||
|
{
|
||||||
|
switch (aField->type){
|
||||||
|
case FIELD_TYPE_TINY:
|
||||||
|
case FIELD_TYPE_SHORT:
|
||||||
|
case FIELD_TYPE_LONG:
|
||||||
|
case FIELD_TYPE_INT24:
|
||||||
|
case FIELD_TYPE_LONGLONG:
|
||||||
|
return mozISqlResult::TYPE_INT;
|
||||||
|
|
||||||
|
case FIELD_TYPE_DECIMAL:
|
||||||
|
return mozISqlResult::TYPE_DECIMAL;
|
||||||
|
|
||||||
|
case FIELD_TYPE_FLOAT:
|
||||||
|
case FIELD_TYPE_DOUBLE:
|
||||||
|
return mozISqlResult::TYPE_FLOAT;
|
||||||
|
|
||||||
|
case FIELD_TYPE_DATE:
|
||||||
|
return mozISqlResult::TYPE_DATE;
|
||||||
|
|
||||||
|
case FIELD_TYPE_TIME:
|
||||||
|
return mozISqlResult::TYPE_TIME;
|
||||||
|
|
||||||
|
case FIELD_TYPE_DATETIME:
|
||||||
|
return mozISqlResult::TYPE_DATETIME;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// handles these types:
|
||||||
|
// FIELD_TYPE_TIMESTAMP, FIELD_TYPE_YEAR, FIELD_TYPE_STRING,
|
||||||
|
// FIELD_TYPE_VAR_STRING, FIELD_TYPE_BLOB, FIELD_TYPE_SET,
|
||||||
|
// FIELD_TYPE_ENUM, FIELD_TYPE_NULL, FIELD_TYPE_CHAR
|
||||||
|
|
||||||
|
return mozISqlResult::TYPE_STRING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::BuildColumnInfo()
|
||||||
|
{
|
||||||
|
MYSQL_FIELD *field;
|
||||||
|
|
||||||
|
while ((field = mysql_fetch_field(mResult))){
|
||||||
|
PRUnichar* name = UTF8ToNewUnicode(nsDependentCString(field->name));
|
||||||
|
PRInt32 type = GetColType(field);
|
||||||
|
|
||||||
|
nsCAutoString uri(NS_LITERAL_CSTRING("http://www.mozilla.org/SQL-rdf#"));
|
||||||
|
uri.Append(field->name);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIRDFResource> property;
|
||||||
|
gRDFService->GetResource(uri, getter_AddRefs(property));
|
||||||
|
|
||||||
|
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type,
|
||||||
|
(PRInt32)field->length, (PRInt32)field->length,
|
||||||
|
(field->flags & PRI_KEY_FLAG), property);
|
||||||
|
mColumnInfo.AppendElement(columnInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::BuildRows()
|
||||||
|
{
|
||||||
|
MYSQL_ROW resultrow;
|
||||||
|
while ((resultrow = mysql_fetch_row(mResult))){
|
||||||
|
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++) {
|
||||||
|
char* value = resultrow[j];
|
||||||
|
if (value){
|
||||||
|
Cell* cell = row->mCells[j];
|
||||||
|
cell->SetNull(PR_FALSE);
|
||||||
|
PRInt32 type = cell->GetType();
|
||||||
|
if (type == mozISqlResult::TYPE_STRING)
|
||||||
|
cell->SetString(UTF8ToNewUnicode(nsDependentCString(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
|
||||||
|
mozSqlResultMysql::ClearNativeResult()
|
||||||
|
{
|
||||||
|
if (mResult) {
|
||||||
|
mysql_free_result(mResult);
|
||||||
|
mResult = nsnull;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::EnsurePrimaryKeys()
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::AppendKeys(Row* aRow, nsAutoString& aKeys)
|
||||||
|
{
|
||||||
|
PRInt32 i;
|
||||||
|
for (i = 0; i < mColumnInfo.Count(); i++) {
|
||||||
|
if (((ColumnInfo*)mColumnInfo[i])->mIsPrimaryKey){
|
||||||
|
if (i){
|
||||||
|
aKeys.Append(NS_LITERAL_STRING(" AND "));
|
||||||
|
}
|
||||||
|
aKeys.Append(((ColumnInfo*)mColumnInfo[i])->mName);
|
||||||
|
aKeys.Append(PRUnichar('='));
|
||||||
|
|
||||||
|
Cell* cell = aRow->mCells[i];
|
||||||
|
AppendValue(cell, aKeys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::CanInsert(PRBool* _retval)
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::CanUpdate(PRBool* _retval)
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
mozSqlResultMysql::CanDelete(PRBool* _retval)
|
||||||
|
{
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/* ***** 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 Neil Deakin
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef mozSqlResultMysql_h
|
||||||
|
#define mozSqlResultMysql_h
|
||||||
|
|
||||||
|
#include "mysql.h"
|
||||||
|
|
||||||
|
#include "mozSqlResult.h"
|
||||||
|
#include "mozISqlResultMysql.h"
|
||||||
|
|
||||||
|
class mozSqlResultMysql : public mozSqlResult,
|
||||||
|
public mozISqlResultMysql
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
mozSqlResultMysql(mozISqlConnection* aConnection,
|
||||||
|
const nsAString& aQuery);
|
||||||
|
void SetResult(MYSQL_RES *aResult);
|
||||||
|
virtual ~mozSqlResultMysql();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_DECL_MOZISQLRESULTMYSQL
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PRInt32 GetColType(MYSQL_FIELD *aField);
|
||||||
|
|
||||||
|
virtual nsresult BuildColumnInfo();
|
||||||
|
virtual nsresult BuildRows();
|
||||||
|
virtual void ClearNativeResult();
|
||||||
|
|
||||||
|
nsresult EnsurePrimaryKeys();
|
||||||
|
nsresult AppendKeys(Row* aRow, nsAutoString& aKeys);
|
||||||
|
|
||||||
|
virtual nsresult CanInsert(PRBool* _retval);
|
||||||
|
virtual nsresult CanUpdate(PRBool* _retval);
|
||||||
|
virtual nsresult CanDelete(PRBool* _retval);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MYSQL_RES *mResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // mozSqlResultMysql_h
|
|
@ -116,7 +116,7 @@ mozSqlResultPgsql::BuildColumnInfo()
|
||||||
nsCOMPtr<nsIRDFResource> property;
|
nsCOMPtr<nsIRDFResource> property;
|
||||||
gRDFService->GetResource(uri, getter_AddRefs(property));
|
gRDFService->GetResource(uri, getter_AddRefs(property));
|
||||||
|
|
||||||
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, size, mod, property);
|
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, size, mod, PR_FALSE, property);
|
||||||
mColumnInfo.AppendElement(columnInfo);
|
mColumnInfo.AppendElement(columnInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ mozSqlResultSqlite::BuildColumnInfo()
|
||||||
gRDFService->GetResource(uri, getter_AddRefs(property));
|
gRDFService->GetResource(uri, getter_AddRefs(property));
|
||||||
|
|
||||||
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, size,
|
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, size,
|
||||||
mod, property);
|
mod, PR_FALSE, property);
|
||||||
mColumnInfo.AppendElement(columnInfo);
|
mColumnInfo.AppendElement(columnInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче