mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Oracle Spatial support for DBManager
This commit is contained in:
parent
0966dadc79
commit
3768d04d3d
@ -6,7 +6,7 @@ It allows showing the DBs contents and run query on them.
|
||||
In this moment DB Manager supports the following DBMS backends:
|
||||
- PostgreSQL/PostGIS through the psycopg2 pymodule
|
||||
- SQLite/SpatiaLite using the pyspatialite pymodule
|
||||
|
||||
- Oracle Spatial using PyQt QtSql module
|
||||
|
||||
For more info about the project, see at the wiki page:
|
||||
http://qgis.org/wiki/DB_Manager_plugin_GSoC_2011
|
||||
|
@ -0,0 +1,9 @@
|
||||
|
||||
FILE(GLOB PY_FILES *.py)
|
||||
FILE(GLOB ICON_FILES icons/*.png)
|
||||
|
||||
PYQT4_ADD_RESOURCES(PYRC_FILES resources.qrc)
|
||||
|
||||
PLUGIN_INSTALL(db_manager db_plugins/oracle ${PY_FILES} ${PYRC_FILES})
|
||||
PLUGIN_INSTALL(db_manager db_plugins/oracle/icons ${ICON_FILES})
|
||||
|
339
python/plugins/db_manager/db_plugins/oracle/LICENSE
Normal file
339
python/plugins/db_manager/db_plugins/oracle/LICENSE
Normal file
@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
218
python/plugins/db_manager/db_plugins/oracle/QtSqlDB.py
Normal file
218
python/plugins/db_manager/db_plugins/oracle/QtSqlDB.py
Normal file
@ -0,0 +1,218 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
/***************************************************************************
|
||||
Name : QtSqlDB
|
||||
Description : DB API 2.0 interface for QtSql
|
||||
Date : June 6, 2015
|
||||
Copyright : (C) 2015 by Jürgen E. Fischer
|
||||
email : jef at norbit dot de
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import QVariant, QDate, QTime, QDateTime, QByteArray
|
||||
from PyQt4.QtSql import QSqlDatabase, QSqlQuery, QSqlField
|
||||
|
||||
paramstyle = "qmark"
|
||||
threadsafety = 1
|
||||
apilevel = "2.0"
|
||||
|
||||
import time
|
||||
import datetime
|
||||
|
||||
|
||||
def Date(year, month, day):
|
||||
return datetime.date(year, month, day)
|
||||
|
||||
|
||||
def Time(hour, minute, second):
|
||||
return datetime.time(hour, minute, second)
|
||||
|
||||
|
||||
def Timestamp(year, month, day, hour, minute, second):
|
||||
return datetime.datetime(year, month, day, hour, minute, second)
|
||||
|
||||
|
||||
def DateFromTicks(ticks):
|
||||
return Date(*time.localtime(ticks)[:3])
|
||||
|
||||
|
||||
def TimeFromTicks(ticks):
|
||||
return Time(*time.localtime(ticks)[3:6])
|
||||
|
||||
|
||||
def TimestampFromTicks(ticks):
|
||||
return Timestamp(*time.localtime(ticks)[:6])
|
||||
|
||||
|
||||
class ConnectionError(StandardError):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(StandardError, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class ExecError(StandardError):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(StandardError, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class QtSqlDBCursor:
|
||||
|
||||
def __init__(self, conn):
|
||||
self.qry = QSqlQuery(conn)
|
||||
self.description = None
|
||||
self.rowcount = -1
|
||||
self.arraysize = 1
|
||||
|
||||
def close(self):
|
||||
self.qry.finish()
|
||||
|
||||
def execute(self, operation, parameters=[]):
|
||||
if len(parameters) == 0:
|
||||
if not self.qry.exec_(operation):
|
||||
raise ExecError(self.qry.lastError().databaseText())
|
||||
else:
|
||||
if not self.qry.prepare(operation):
|
||||
raise ExecError(self.qry.lastError().databaseText())
|
||||
|
||||
for i in range(len(parameters)):
|
||||
self.qry.bindValue(i, parameters[i])
|
||||
|
||||
if not self.qry.exec_():
|
||||
raise ExecError(self.qry.lastError().databaseText())
|
||||
|
||||
self.rowcount = self.qry.size()
|
||||
self.description = []
|
||||
for c in range(self.qry.record().count()):
|
||||
f = self.qry.record().field(c)
|
||||
|
||||
if f.type() == QVariant.Date:
|
||||
t = Date
|
||||
elif f.type() == QVariant.Time:
|
||||
t = Time
|
||||
elif f.type() == QVariant.DateTime:
|
||||
t = Timestamp
|
||||
elif f.type() == QVariant.Double:
|
||||
t = float
|
||||
elif f.type() == QVariant.Int:
|
||||
t = int
|
||||
elif f.type() == QVariant.String:
|
||||
t = unicode
|
||||
elif f.type() == QVariant.ByteArray:
|
||||
t = unicode
|
||||
else:
|
||||
continue
|
||||
|
||||
self.description.append([
|
||||
f.name(), # name
|
||||
t, # type_code
|
||||
f.length(), # display_size
|
||||
f.length(), # internal_size
|
||||
f.precision(), # precision
|
||||
None, # scale
|
||||
f.requiredStatus() != QSqlField.Required # null_ok
|
||||
])
|
||||
|
||||
def executemany(self, operation, seq_of_parameters):
|
||||
if len(seq_of_parameters) == 0:
|
||||
return
|
||||
|
||||
if not self.qry.prepare(operation):
|
||||
raise ExecError(self.qry.lastError().databaseText())
|
||||
|
||||
for r in seq_of_parameters:
|
||||
for i in range(len(r)):
|
||||
self.qry.bindValue(i, r[i])
|
||||
|
||||
if not self.qry.exec_():
|
||||
raise ExecError(self.qry.lastError().databaseText())
|
||||
|
||||
def scroll(self, row):
|
||||
return self.qry.seek(row)
|
||||
|
||||
def fetchone(self):
|
||||
if not self.qry.next():
|
||||
return None
|
||||
|
||||
row = []
|
||||
for i in range(len(self.description)):
|
||||
value = self.qry.value(i)
|
||||
if (isinstance(value, QDate)
|
||||
or isinstance(value, QTime)
|
||||
or isinstance(value, QDateTime)):
|
||||
value = value.toString()
|
||||
elif isinstance(value, QByteArray):
|
||||
value = u"GEOMETRY"
|
||||
# value = value.toHex()
|
||||
|
||||
row.append(value)
|
||||
|
||||
return row
|
||||
|
||||
def fetchmany(self, size=10):
|
||||
rows = []
|
||||
while len(rows) < size:
|
||||
row = self.fetchone()
|
||||
if row is None:
|
||||
break
|
||||
rows.append(row)
|
||||
|
||||
return rows
|
||||
|
||||
def fetchall(self):
|
||||
rows = []
|
||||
while True:
|
||||
row = self.fetchone()
|
||||
if row is None:
|
||||
break
|
||||
rows.append(row)
|
||||
|
||||
return rows
|
||||
|
||||
def setinputsize(self, sizes):
|
||||
raise ExecError("nyi")
|
||||
|
||||
def setoutputsize(self, size, column=None):
|
||||
raise ExecError("nyi")
|
||||
|
||||
|
||||
class QtSqlDBConnection:
|
||||
connections = 0
|
||||
|
||||
def __init__(self, driver, dbname, user, passwd):
|
||||
self.conn = QSqlDatabase.addDatabase(
|
||||
driver, "qtsql_%d" % QtSqlDBConnection.connections)
|
||||
QtSqlDBConnection.connections += 1
|
||||
self.conn.setDatabaseName(dbname)
|
||||
self.conn.setUserName(user)
|
||||
self.conn.setPassword(passwd)
|
||||
|
||||
if not self.conn.open():
|
||||
raise ConnectionError(self.conn.lastError().databaseText())
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
def commit(self):
|
||||
self.conn.commit()
|
||||
|
||||
def rollback(self):
|
||||
self.conn.rollback()
|
||||
|
||||
def cursor(self):
|
||||
return QtSqlDBCursor(self.conn)
|
||||
|
||||
|
||||
def connect(driver, dbname, user, passwd):
|
||||
return QtSqlDBConnection(driver, dbname, user, passwd)
|
60
python/plugins/db_manager/db_plugins/oracle/README.md
Normal file
60
python/plugins/db_manager/db_plugins/oracle/README.md
Normal file
@ -0,0 +1,60 @@
|
||||
# Oracle implementation of QGis DBManager plugin
|
||||
|
||||
## Introduction
|
||||
|
||||
This Python code try to implement the Oracle part of the QGis DBManager plugin. DBManager plugin is a good tool from QGis with which you can easily manage your databases and create your own queries which can be dynamically added to QGis maps.
|
||||
|
||||
For the moment, DBManager plugin is only able to connect to PostGIS and Spatialite databases. If you want to manage your Oracle Spatial repository, you can (try) to do this with this code implementation.
|
||||
|
||||
The code base of this implementation was the Postgis one. I tried to make every features of the PostGIS work under Oracle but there are some limitations. Read TODO.md to have more details about what is working and what needs to be done.
|
||||
|
||||
Expect bugs !
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
The code does not need [cx_Oracle](http://cx-oracle.sourceforge.net/) anymore ! Thanks to [Jürgen Fischer](https://github.com/jef-n), all Oracle connections uses PyQt QtSql module which is included in QGIS.
|
||||
|
||||
To install DBManager oracle plugin, you just have to clone the git repository in a directory named `oracle` in the `db_plugins` directory of the db_manager installation.
|
||||
|
||||
For MS-Windows users:
|
||||
|
||||
* If you have git for MS-Windows:
|
||||
$ cd "C:\Program Files\QGis Wien\apps\qgis\python\plugins\db_manager\db_plugins"
|
||||
$ git clone https://github.com/medspx/dbmanager-oracle.git oracle
|
||||
|
||||
* Or:
|
||||
* Just create a directory named `oracle` in "C:\Program Files\QGis Wien\apps\qgis\python\plugins\db_manager\db_plugins"
|
||||
* unzip `https://github.com/medspx/dbmanager-oracle/archive/master.zip` into "C:\Program Files\QGis Wien\apps\qgis\python\plugins\db_manager\db_plugins\oracle"
|
||||
|
||||
For GNU/Linux users:
|
||||
|
||||
# cd /usr/share/qgis/python/plugins/db_manager/db_plugins
|
||||
# git clone https://github.com/medspx/dbmanager-oracle.git oracle
|
||||
|
||||
|
||||
## Limitations
|
||||
|
||||
* You have to define Oracle connections directly in QGis for the plugin to work (same thing than PostGIS and Spatialite).
|
||||
* Oracle Spatial Rasters are not supported (as I've don't have a way to test them).
|
||||
* The code try to use the maximum of your Oracle connections parameters. If you have a huge geographic database with a lot of layers, listing tables can take time. So be careful about your connections parameters (try to restrict to user tables to reduce internal queries duration).
|
||||
* Tests have been done with QGis 2.4, 2.6 and 2.8.2. You probably should use the latest version because before 2.4 the Oracle provider of QGis was not able to load dynamic queries.
|
||||
* Some things could not have been well tested, particularly everything that requires administrative rights on DB like schema creation/deletion.
|
||||
* Tests have been done against an Oracle 10g database. I tried to incorporate the official Oracle 12c "dictionary" of commands and the internal queries should also work with 11g and 12c versions of Oracle Database server.
|
||||
* Some tasks cannot been done under Oracle Database like moving a table from a schema to another. There is also no PostgreSQL Rules features under Oracle.
|
||||
* Code has been tested only under MS-Windows (bad) but as it is Python code, I hope it will also works under other OS.
|
||||
|
||||
|
||||
## Bug reports
|
||||
|
||||
For the moment, use the ["issues" tool of GitHub](https://github.com/medspx/dbmanager-oracle/issues) to report bugs.
|
||||
|
||||
|
||||
## Main goal
|
||||
|
||||
My main goal is that this code can be incorporated in the official QGis source code repository. Once this has been done, the code upgrades will take place there.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
This code is released under the GNU GPLv2 license. Read headers code for more information.
|
165
python/plugins/db_manager/db_plugins/oracle/TODO.md
Normal file
165
python/plugins/db_manager/db_plugins/oracle/TODO.md
Normal file
@ -0,0 +1,165 @@
|
||||
# Won't fix
|
||||
|
||||
* SQL Window - "Retrieve columns" don't work => problem in
|
||||
dlg_sql_window.py (not enough abstraction for connectors).
|
||||
|
||||
* SQL Window - Can't retrieve column: dlg_sql_window.py launch an
|
||||
invalid request for Oracle (no LIMIT operator in Oracle). Should
|
||||
patch dlg_sql_window.py to use a connector method to grab columns.
|
||||
|
||||
* Query-builder - Add date functions menu (needs to change the main
|
||||
code of query builder).
|
||||
|
||||
* Table Menu - remove GEOMETRY COLLECTION from the list of geometry
|
||||
types (Oracle can't handle this form of geometries). Needs to modify
|
||||
dlg_create_table.py
|
||||
|
||||
* Refresh - Refresh Action should transmit an argument to the
|
||||
db_plugin object specifying that this a refresh and not a primary
|
||||
dbtree population. I've build (quite) an ugly hack to use SQLite
|
||||
list of tables cache for primary population and once it is done,
|
||||
each other call to connector.tables doesn't not use cache anymore.
|
||||
|
||||
* There is a bug in the create table dialog: there should be a
|
||||
checkbox for Null column but it is not showned. The setData method
|
||||
don't fix the value for notNull attributes and whatever value of
|
||||
this attribute for the field, it is always shown as nullable in the
|
||||
modify field dialog. #13089
|
||||
|
||||
* Import Table does not work because of a problem in
|
||||
QgsVectorLayerImport. After the creation of the table, QGIS tries to
|
||||
open the layer but, as there is no geometries in it, QGIS can't
|
||||
determinate the geometry type of the layer and refuses to open
|
||||
it. Then, no data importation can occur. Must dig into
|
||||
src/core/qgsvectorlayerimport.cpp and into the provider code.
|
||||
See #13096 .
|
||||
|
||||
# Future work
|
||||
|
||||
* Implement SRID modification (with reprojection of data) ?
|
||||
* Modify/force wkbType to be able to open an empty layer in the canvas.
|
||||
|
||||
# TODO
|
||||
|
||||
* Nothing for the moment.
|
||||
|
||||
# DONE
|
||||
|
||||
* Code review
|
||||
* Try to factorise connector.py.
|
||||
* Connector method to handle metadata operations (update/delete/insert).
|
||||
* work on updateExtentMetadata.
|
||||
* 2.10: try to find the differences between postGIS connector 2.8 and 2.10. (Answer: nothing else than pep-8 reformatting).
|
||||
|
||||
* Plugin
|
||||
* Can't open spatial view (no pkcol determined).
|
||||
|
||||
* Info model
|
||||
* Still some problems with extent comparison: do not try to calculate extent when there is no row.
|
||||
* Add precision for float values (NUMBER(10,5)).
|
||||
* View: show the estimated metadata extent for spatial views that have metadata.
|
||||
* Can't rename a spatial View.
|
||||
* Can't rename a column.
|
||||
|
||||
* Table Tab
|
||||
* Problem on one layer casting for number without max_length_char.
|
||||
* When exploring some tables in table view: there is a sort of crash with fetchmoreData.
|
||||
|
||||
* Query Builder
|
||||
* Should not present the geometric columns in column values.
|
||||
|
||||
* SQL Window
|
||||
* Grab the row count.
|
||||
* Create view button.
|
||||
* Spatial Index tab (find if can be activated: no because Oracle use spatial index internally).
|
||||
* Can't open query builder.
|
||||
* Modify dictionnary to add math/string/aggregates functions/operators.
|
||||
* Can't open column values from query builder.
|
||||
* GEOM columns are not retrieved. (Done: don't grab them, just use GEOMETRY string instead to speed columns population)
|
||||
* Can't open a query in QGis.
|
||||
* Find the srid of a query and add it as a layer parameter.
|
||||
* Open non geometric queries.
|
||||
* Show better statistic about query duration.
|
||||
* handle DatabaseError in the dialog.
|
||||
* Make the SQL query window works !
|
||||
* Handle geometry type detection.
|
||||
|
||||
* Table Menu
|
||||
* Error when update/create/delete field in deleteCursor (was problem on QtSql Exceptions).
|
||||
* Can't modify the name of a geographic column: modify also the spatial index.
|
||||
* Create table: problem with index and geocol name is not in upper case.
|
||||
* Create Table: handle 3rd and 4th dimension for metadata creation.
|
||||
* Can't modify a field length.
|
||||
* Can't delete a geographic column.
|
||||
* Add an action to update metadata layer extent to the content of the geocolumn.
|
||||
* Disable move Table to another schema (impossible in Oracle, you have to import/export).
|
||||
* Find how to load Unknown WKBGeometryType layers.
|
||||
* Spatial index creation.
|
||||
* Edit dialog fully functionnal.
|
||||
* Edit Table opens.
|
||||
* Remove Vacuum operation in Table menu.
|
||||
* Fix: Add SRID when creating table.
|
||||
* Rename Geographic Table.
|
||||
* Can create non geographic tables.
|
||||
* Can delete non geographic tables.
|
||||
* Can Create geographic tables.
|
||||
* Can Delete geographic tables.
|
||||
* DO Empty table.
|
||||
|
||||
* Connector
|
||||
* getVectorTablesCache should present only one line per table (don't show tables more than once).
|
||||
* correspondance between Oracle SDO_GTYPE and QGis.WkbType in a class dict.
|
||||
* Show only one table/layer in the table tree even if entry is duplicated in cache.
|
||||
* Reuse the pre-calculated extent metadata when updating.
|
||||
* Create a better privilege function using ALL_PRIVS_RECD
|
||||
|
||||
* Main Tree
|
||||
* Bug on refreshing a whole connection.
|
||||
|
||||
* Information Tab (main tab)
|
||||
* If extent is not in QGIS format (dimensions named X and Y): show it and offer to correct the name of the dimension.
|
||||
* Syntax coloration for View and MView definitions (done with pygments which is included in QGIS).
|
||||
* Add date of last creation/modification for objects.
|
||||
* Modify "Oracle" in table information by "Oracle Spatial".
|
||||
* For rows estimation: use a query to scan nb_rows in object !
|
||||
* Refresh on the fly data that are not stored in cache (comments/table type/row counts).
|
||||
* Bad comparison between metadata extent and calculated extent (was format syntax).
|
||||
* If user can't udpate metadata, dont pull the link for update action.
|
||||
* Can't update metadata extent: find if table is in USER_SDO_GEOM_METADATA.
|
||||
* Print QGis Geometry Type in string instead of int.
|
||||
|
||||
* Constraints:
|
||||
* Handle foreign keys information.
|
||||
* Add search_condition, status, delete_rule, validated, generated
|
||||
|
||||
* Indexes:
|
||||
* Add rebuild index action for indexes.
|
||||
* Add more informations: Compression/Valid/Last analyzed/ityp_name.
|
||||
|
||||
* Refresh:
|
||||
* Make getTables and getVectorTables functions retrieve less informations and manage them on the fly.
|
||||
* Refreshing a schema refresh only the schema, not the whole connection.
|
||||
* Still problems with refreshing (QPyNullVariant for detectedSrid).
|
||||
* Mark views as views.
|
||||
* Grab also geographic views.
|
||||
* Refresh should launch a refresh of the cached list of tables (SQLite).
|
||||
* Implement add_sys_tables (mask MDRT index tables for example).
|
||||
* List of unknown geometry tables when refreshing depending upon onlyExistingTypes.
|
||||
* Grab the geomtypes of the layer during list refreshing.
|
||||
* Grab the srids of the layer during list refreshing.
|
||||
* Grab the pkcols for the views.
|
||||
* Bug with cache srids interpreted as float (convert detected srid to int).
|
||||
* Find if a layer is a view or a table with cache and non cache list of tables.
|
||||
|
||||
* Materialized views:
|
||||
* function to determine if MV or simple Table.
|
||||
* retrieve definition.
|
||||
* unitary comments retrieving.
|
||||
* Primary key mask.
|
||||
* Refreshing informations.
|
||||
* Action to refresh the mview.
|
||||
* View/MView definition is not interpreted as Html anymore.
|
||||
|
||||
* QtSqlDB:
|
||||
* bug with timing functions (no Time module/global name)
|
||||
* better handling of dates (returned as QDateTime) in query dialog.
|
1760
python/plugins/db_manager/db_plugins/oracle/connector.py
Normal file
1760
python/plugins/db_manager/db_plugins/oracle/connector.py
Normal file
File diff suppressed because it is too large
Load Diff
151
python/plugins/db_manager/db_plugins/oracle/data_model.py
Normal file
151
python/plugins/db_manager/db_plugins/oracle/data_model.py
Normal file
@ -0,0 +1,151 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
/***************************************************************************
|
||||
Name : DB Manager
|
||||
Description : Database manager plugin for QGIS (Oracle)
|
||||
Date : Aug 27, 2014
|
||||
copyright : (C) 2014 by Médéric RIBREUX
|
||||
email : mederic.ribreux@gmail.com
|
||||
|
||||
The content of this file is based on
|
||||
- PG_Manager by Martin Dobias <wonder.sk@gmail.com> (GPLv2 license)
|
||||
- DB Manager by Giuseppe Sucameli <brush.tyler@gmail.com> (GPLv2 license)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
from ..data_model import TableDataModel, SqlResultModel, \
|
||||
BaseTableModel, TableFieldsModel, SimpleTableModel
|
||||
from ..plugin import DbError
|
||||
from qgis.core import *
|
||||
|
||||
|
||||
class ORTableDataModel(TableDataModel):
|
||||
|
||||
def __init__(self, table, parent=None):
|
||||
self.cursor = None
|
||||
TableDataModel.__init__(self, table, parent)
|
||||
|
||||
if not self.table.rowCount:
|
||||
self.table.refreshRowCount()
|
||||
|
||||
self.connect(self.table, SIGNAL("aboutToChange"),
|
||||
self._deleteCursor)
|
||||
self._createCursor()
|
||||
|
||||
def _createCursor(self):
|
||||
fields_txt = u", ".join(self.fields)
|
||||
table_txt = self.db.quoteId(
|
||||
(self.table.schemaName(), self.table.name))
|
||||
|
||||
self.cursor = self.db._get_cursor()
|
||||
sql = u"SELECT {0} FROM {1}".format(fields_txt, table_txt)
|
||||
|
||||
self.db._execute(self.cursor, sql)
|
||||
|
||||
def _sanitizeTableField(self, field):
|
||||
# get fields, ignore geometry columns
|
||||
if field.dataType.upper() == u"SDO_GEOMETRY":
|
||||
return (u"CASE WHEN {0} IS NULL THEN NULL ELSE 'GEOMETRY'"
|
||||
u"END AS {0}".format(
|
||||
self.db.quoteId(field.name)))
|
||||
if field.dataType.upper() == u"DATE":
|
||||
return u"CAST({} AS VARCHAR2(8))".format(
|
||||
self.db.quoteId(field.name))
|
||||
if field.dataType.upper() == u"NUMBER":
|
||||
if not field.charMaxLen:
|
||||
return u"CAST({} AS VARCHAR2(135))".format(
|
||||
self.db.quoteId(field.name))
|
||||
elif field.modifier:
|
||||
nbChars = 2 + int(field.charMaxLen) + \
|
||||
int(field.modifier)
|
||||
return u"CAST({} AS VARCHAR2({}))".format(
|
||||
self.db.quoteId(field.name),
|
||||
unicode(nbChars))
|
||||
|
||||
return u"CAST({0} As VARCHAR2({1}))".format(
|
||||
self.db.quoteId(field.name), field.charMaxLen)
|
||||
|
||||
def _deleteCursor(self):
|
||||
self.db._close_cursor(self.cursor)
|
||||
self.cursor = None
|
||||
|
||||
def __del__(self):
|
||||
self.disconnect(
|
||||
self.table, SIGNAL("aboutToChange"), self._deleteCursor)
|
||||
self._deleteCursor()
|
||||
|
||||
def getData(self, row, col):
|
||||
if (row < self.fetchedFrom
|
||||
or row >= self.fetchedFrom + self.fetchedCount):
|
||||
margin = self.fetchedCount / 2
|
||||
if row + margin >= self.rowCount():
|
||||
start = self.rowCount() - margin
|
||||
else:
|
||||
start = row - margin
|
||||
if start < 0:
|
||||
start = 0
|
||||
self.fetchMoreData(start)
|
||||
|
||||
# For some improbable cases
|
||||
if row - self.fetchedFrom >= len(self.resdata):
|
||||
return None
|
||||
|
||||
return self.resdata[row - self.fetchedFrom][col]
|
||||
|
||||
def fetchMoreData(self, row_start):
|
||||
if not self.cursor:
|
||||
self._createCursor()
|
||||
|
||||
self.cursor.scroll(row_start - 1)
|
||||
|
||||
self.resdata = self.cursor.fetchmany(self.fetchedCount)
|
||||
self.fetchedFrom = row_start
|
||||
|
||||
|
||||
class ORSqlResultModel(SqlResultModel):
|
||||
|
||||
def __init__(self, db, sql, parent=None):
|
||||
self.db = db.connector
|
||||
|
||||
t = QTime()
|
||||
t.start()
|
||||
c = self.db._execute(None, unicode(sql))
|
||||
|
||||
self._affectedRows = 0
|
||||
data = []
|
||||
header = self.db._get_cursor_columns(c)
|
||||
if not header:
|
||||
header = []
|
||||
|
||||
try:
|
||||
if len(header) > 0:
|
||||
data = self.db._fetchall(c)
|
||||
self._affectedRows = len(data)
|
||||
except DbError:
|
||||
# nothing to fetch!
|
||||
data = []
|
||||
header = []
|
||||
|
||||
self._secs = t.elapsed() / 1000.0
|
||||
del t
|
||||
|
||||
BaseTableModel.__init__(self, header, data, parent)
|
||||
|
||||
# commit before closing the cursor to make sure that the
|
||||
# changes are stored
|
||||
self.db._commit()
|
||||
c.close()
|
||||
del c
|
BIN
python/plugins/db_manager/db_plugins/oracle/icons/oracle.png
Executable file
BIN
python/plugins/db_manager/db_plugins/oracle/icons/oracle.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 577 B |
674
python/plugins/db_manager/db_plugins/oracle/info_model.py
Normal file
674
python/plugins/db_manager/db_plugins/oracle/info_model.py
Normal file
@ -0,0 +1,674 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
/***************************************************************************
|
||||
Name : DB Manager
|
||||
Description : Database manager plugin for QGIS (Oracle)
|
||||
Date : Aug 27, 2014
|
||||
copyright : (C) 2014 by Médéric RIBREUX
|
||||
email : mederic.ribreux@gmail.com
|
||||
|
||||
The content of this file is based on
|
||||
- PG_Manager by Martin Dobias <wonder.sk@gmail.com> (GPLv2 license)
|
||||
- DB Manager by Giuseppe Sucameli <brush.tyler@gmail.com> (GPLv2 license)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from qgis.core import QGis
|
||||
|
||||
from ..info_model import TableInfo, VectorTableInfo, DatabaseInfo, \
|
||||
SchemaInfo
|
||||
from ..html_elems import HtmlContent, HtmlSection, HtmlParagraph, \
|
||||
HtmlList, HtmlTable, HtmlTableHeader, HtmlTableCol
|
||||
|
||||
# Syntax Highlight for VIEWS/MVIEWS
|
||||
from pygments import highlight
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
|
||||
class ORDatabaseInfo(DatabaseInfo):
|
||||
|
||||
def __init__(self, db):
|
||||
self.db = db
|
||||
|
||||
def connectionDetails(self):
|
||||
tbl = []
|
||||
|
||||
if self.db.connector.host != u"":
|
||||
tbl.append((QApplication.translate("DBManagerPlugin", "Host:"),
|
||||
self.db.connector.host))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin", "Database:"),
|
||||
self.db.connector.dbname))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin", "User:"),
|
||||
self.db.connector.user))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"SQLite list tables cache:"),
|
||||
"Enabled" if self.db.connector.hasCache else
|
||||
"Unavailable"))
|
||||
|
||||
return HtmlTable(tbl)
|
||||
|
||||
def spatialInfo(self):
|
||||
ret = []
|
||||
|
||||
info = self.db.connector.getSpatialInfo()
|
||||
if not info:
|
||||
return
|
||||
|
||||
tbl = [
|
||||
(QApplication.translate("DBManagerPlugin", "Oracle\
|
||||
Spatial:"),
|
||||
info[0])
|
||||
]
|
||||
ret.append(HtmlTable(tbl))
|
||||
|
||||
if not self.db.connector.has_geometry_columns:
|
||||
ret.append(
|
||||
HtmlParagraph(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u"<warning> ALL_SDO_GEOM_METADATA"
|
||||
u" view doesn't exist!\n"
|
||||
u"This view is essential for many"
|
||||
u"GIS applications for enumeration of tables."))))
|
||||
|
||||
return ret
|
||||
|
||||
def privilegesDetails(self):
|
||||
""" find if user can create schemas (CREATE ANY TABLE or something)"""
|
||||
# TODO
|
||||
return None
|
||||
|
||||
|
||||
class ORTableInfo(TableInfo):
|
||||
|
||||
def __init__(self, table):
|
||||
self.table = table
|
||||
if not self.table.objectType:
|
||||
self.table.getType()
|
||||
if not self.table.comment:
|
||||
self.table.getComment()
|
||||
if not self.table.estimatedRowCount and not self.table.isView:
|
||||
self.table.refreshRowEstimation()
|
||||
if not self.table.creationDate:
|
||||
self.table.getDates()
|
||||
|
||||
def generalInfo(self):
|
||||
ret = []
|
||||
|
||||
# if the estimation is less than 100 rows, try to count them - it
|
||||
# shouldn't take long time
|
||||
if (not self.table.isView
|
||||
and not self.table.rowCount
|
||||
and self.table.estimatedRowCount < 100):
|
||||
# row count information is not displayed yet, so just block
|
||||
# table signals to avoid double refreshing
|
||||
# (infoViewer->refreshRowCount->tableChanged->infoViewer)
|
||||
self.table.blockSignals(True)
|
||||
self.table.refreshRowCount()
|
||||
self.table.blockSignals(False)
|
||||
|
||||
relation_type = QApplication.translate(
|
||||
"DBManagerPlugin", self.table.objectType)
|
||||
|
||||
tbl = [
|
||||
(QApplication.translate("DBManagerPlugin", "Object type:"),
|
||||
relation_type),
|
||||
(QApplication.translate("DBManagerPlugin", "Owner:"),
|
||||
self.table.owner)
|
||||
]
|
||||
|
||||
if self.table.comment:
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
"Comment:"),
|
||||
self.table.comment))
|
||||
|
||||
# Estimated rows
|
||||
if not self.table.isView:
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Rows (estimation):"),
|
||||
self.table.estimatedRowCount)
|
||||
)
|
||||
if self.table.rowCount or self.table.rowCount >= 0:
|
||||
# Add a real count of rows
|
||||
tbl.append(
|
||||
(QApplication.translate("DBManagerPlugin", "Rows (counted):"),
|
||||
self.table.rowCount)
|
||||
)
|
||||
else:
|
||||
tbl.append(
|
||||
(QApplication.translate("DBManagerPlugin", "Rows (counted):"),
|
||||
'Unknown (<a href="action:rows/recount">find out</a>)')
|
||||
)
|
||||
|
||||
# Add creation and modification dates
|
||||
if self.table.creationDate:
|
||||
tbl.append(
|
||||
(QApplication.translate("DBManagerPlugin", "Creation Date:"),
|
||||
self.table.creationDate))
|
||||
|
||||
if self.table.modificationDate:
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Last Modification Date:"),
|
||||
self.table.modificationDate))
|
||||
|
||||
# privileges
|
||||
# has the user access to this schema?
|
||||
schema_priv = self.table.database().connector.getSchemaPrivileges(
|
||||
self.table.schemaName()) if self.table.schema() else None
|
||||
if not schema_priv:
|
||||
pass
|
||||
elif schema_priv[1] is False: # no usage privileges on the schema
|
||||
tbl.append((QApplication.translate(
|
||||
"DBManagerPlugin", "Privileges:"),
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u"<warning> This user doesn't have usage privileges"
|
||||
u"for this schema!"))))
|
||||
else:
|
||||
table_priv = self.table.database().connector.getTablePrivileges(
|
||||
(self.table.schemaName(), self.table.name))
|
||||
privileges = []
|
||||
if table_priv[0]:
|
||||
privileges.append("select")
|
||||
if table_priv[1]:
|
||||
privileges.append("insert")
|
||||
if table_priv[2]:
|
||||
privileges.append("update")
|
||||
if table_priv[3]:
|
||||
privileges.append("delete")
|
||||
|
||||
if len(privileges) > 0:
|
||||
priv_string = u", ".join(privileges)
|
||||
else:
|
||||
priv_string = QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'<warning> This user has no privileges!')
|
||||
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Privileges:"),
|
||||
priv_string))
|
||||
|
||||
ret.append(HtmlTable(tbl))
|
||||
|
||||
if schema_priv and schema_priv[1]:
|
||||
if (table_priv[0]
|
||||
and not table_priv[1]
|
||||
and not table_priv[2]
|
||||
and not table_priv[3]):
|
||||
ret.append(
|
||||
HtmlParagraph(QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
"<warning> This user has read-only privileges.")))
|
||||
|
||||
# primary key defined?
|
||||
if (not self.table.isView
|
||||
and self.table.objectType != u"MATERIALIZED VIEW"):
|
||||
pk = filter(lambda fld: fld.primaryKey, self.table.fields())
|
||||
if len(pk) <= 0:
|
||||
ret.append(
|
||||
HtmlParagraph(QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
"<warning> No primary key defined for this table!")))
|
||||
|
||||
return ret
|
||||
|
||||
def getSpatialInfo(self):
|
||||
ret = []
|
||||
|
||||
info = self.db.connector.getSpatialInfo()
|
||||
if not info:
|
||||
return
|
||||
|
||||
tbl = [
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Library:"), info[0]) # ,
|
||||
]
|
||||
ret.append(HtmlTable(tbl))
|
||||
|
||||
if not self.db.connector.has_geometry_columns:
|
||||
ret.append(HtmlParagraph(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u"<warning> ALL_SDO_GEOM_METADATA table doesn't exist!\n"
|
||||
u"This table is essential for many GIS"
|
||||
u"applications for enumeration of tables."))))
|
||||
|
||||
return ret
|
||||
|
||||
def fieldsDetails(self):
|
||||
tbl = []
|
||||
|
||||
# define the table header
|
||||
header = (
|
||||
"#",
|
||||
QApplication.translate("DBManagerPlugin", "Name"),
|
||||
QApplication.translate("DBManagerPlugin", "Type"),
|
||||
QApplication.translate("DBManagerPlugin", "Length"),
|
||||
QApplication.translate("DBManagerPlugin", "Null"),
|
||||
QApplication.translate("DBManagerPlugin", "Default"),
|
||||
QApplication.translate("DBManagerPlugin", "Comment"))
|
||||
tbl.append(HtmlTableHeader(header))
|
||||
|
||||
# add table contents
|
||||
for fld in self.table.fields():
|
||||
char_max_len = fld.charMaxLen if fld.charMaxLen else ""
|
||||
if fld.modifier:
|
||||
char_max_len = u"{},{}".format(char_max_len, fld.modifier)
|
||||
is_null_txt = "N" if fld.notNull else "Y"
|
||||
|
||||
# make primary key field underlined
|
||||
attrs = {"class": "underline"} if fld.primaryKey else None
|
||||
name = HtmlTableCol(fld.name, attrs)
|
||||
|
||||
tbl.append(
|
||||
(fld.num, name, fld.type2String(), char_max_len,
|
||||
is_null_txt, fld.default2String(), fld.comment))
|
||||
|
||||
return HtmlTable(tbl, {"class": "header"})
|
||||
|
||||
def constraintsDetails(self):
|
||||
if not self.table.constraints():
|
||||
return None
|
||||
|
||||
tbl = []
|
||||
|
||||
# define the table header
|
||||
header = (QApplication.translate("DBManagerPlugin", "Name"),
|
||||
QApplication.translate("DBManagerPlugin", "Type"),
|
||||
QApplication.translate("DBManagerPlugin", "Column"),
|
||||
QApplication.translate("DBManagerPlugin", "Status"),
|
||||
QApplication.translate("DBManagerPlugin", "Validated"),
|
||||
QApplication.translate("DBManagerPlugin", "Generated"),
|
||||
QApplication.translate("DBManagerPlugin", "Check condition"),
|
||||
QApplication.translate("DBManagerPlugin", "Foreign Table"),
|
||||
QApplication.translate("DBManagerPlugin", "Foreign column"),
|
||||
QApplication.translate("DBManagerPlugin", "On Delete"))
|
||||
tbl.append(HtmlTableHeader(header))
|
||||
|
||||
# add table contents
|
||||
for con in self.table.constraints():
|
||||
tbl.append((con.name, con.type2String(), con.column,
|
||||
con.status, con.validated, con.generated,
|
||||
con.checkSource, con.foreignTable,
|
||||
con.foreignKey, con.foreignOnDelete))
|
||||
|
||||
return HtmlTable(tbl, {"class": "header"})
|
||||
|
||||
def indexesDetails(self):
|
||||
if not self.table.indexes():
|
||||
return None
|
||||
|
||||
tbl = []
|
||||
|
||||
# define the table header
|
||||
header = (QApplication.translate("DBManagerPlugin", "Name"),
|
||||
QApplication.translate("DBManagerPlugin", "Column(s)"),
|
||||
QApplication.translate("DBManagerPlugin", "Index Type"),
|
||||
QApplication.translate("DBManagerPlugin", "Status"),
|
||||
QApplication.translate("DBManagerPlugin", "Last analyzed"),
|
||||
QApplication.translate("DBManagerPlugin", "Compression"),
|
||||
QApplication.translate("DBManagerPlugin", "Uniqueness"),
|
||||
QApplication.translate("DBManagerPlugin", "Action"))
|
||||
tbl.append(HtmlTableHeader(header))
|
||||
|
||||
# add table contents
|
||||
for idx in self.table.indexes():
|
||||
# get the fields the index is defined on
|
||||
tbl.append((idx.name, idx.column, idx.indexType,
|
||||
idx.status, idx.analyzed, idx.compression,
|
||||
idx.isUnique,
|
||||
(u'<a href="action:index/{}/rebuild">Rebuild'
|
||||
u"""</a>""".format(idx.name))))
|
||||
|
||||
return HtmlTable(tbl, {"class": "header"})
|
||||
|
||||
def triggersDetails(self):
|
||||
if not self.table.triggers():
|
||||
return None
|
||||
|
||||
ret = []
|
||||
|
||||
tbl = []
|
||||
# define the table header
|
||||
header = (
|
||||
QApplication.translate("DBManagerPlugin", "Name"),
|
||||
QApplication.translate("DBManagerPlugin", "Event"),
|
||||
QApplication.translate("DBManagerPlugin", "Type"),
|
||||
QApplication.translate("DBManagerPlugin", "Enabled"))
|
||||
tbl.append(HtmlTableHeader(header))
|
||||
|
||||
# add table contents
|
||||
for trig in self.table.triggers():
|
||||
name = (u"""{0} (<a href="action:trigger/"""
|
||||
u"""{0}/{1}">{1}</a>)""".format(trig.name, "delete"))
|
||||
|
||||
if trig.enabled == u"ENABLED":
|
||||
enabled, action = (
|
||||
QApplication.translate("DBManagerPlugin", "Yes"),
|
||||
u"disable")
|
||||
else:
|
||||
enabled, action = (
|
||||
QApplication.translate("DBManagerPlugin", "No"),
|
||||
"enable")
|
||||
|
||||
txt_enabled = (u"""{0} (<a href="action:trigger/"""
|
||||
u"""{1}/{2}">{2}</a>)""".format(
|
||||
enabled, trig.name, action))
|
||||
|
||||
tbl.append((name, trig.event, trig.type, txt_enabled))
|
||||
|
||||
ret.append(HtmlTable(tbl, {"class": "header"}))
|
||||
|
||||
ret.append(
|
||||
HtmlParagraph(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u'<a href="action:triggers/enable">'
|
||||
u'Enable all triggers</a> / '
|
||||
u'<a href="action:triggers/disable">'
|
||||
u'Disable all triggers</a>'))))
|
||||
|
||||
return ret
|
||||
|
||||
def getTableInfo(self):
|
||||
ret = []
|
||||
|
||||
general_info = self.generalInfo()
|
||||
if not general_info:
|
||||
pass
|
||||
else:
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin", 'General info'),
|
||||
general_info))
|
||||
|
||||
# spatial info
|
||||
spatial_info = self.spatialInfo()
|
||||
if not spatial_info:
|
||||
pass
|
||||
else:
|
||||
spatial_info = HtmlContent(spatial_info)
|
||||
if not spatial_info.hasContents():
|
||||
spatial_info = QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'<warning> This is not a spatial table.')
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
self.table.database().connection().typeNameString(),
|
||||
spatial_info))
|
||||
|
||||
# fields
|
||||
fields_details = self.fieldsDetails()
|
||||
if not fields_details:
|
||||
pass
|
||||
else:
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'Fields'),
|
||||
fields_details))
|
||||
|
||||
# constraints
|
||||
constraints_details = self.constraintsDetails()
|
||||
if not constraints_details:
|
||||
pass
|
||||
else:
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'Constraints'),
|
||||
constraints_details))
|
||||
|
||||
# indexes
|
||||
indexes_details = self.indexesDetails()
|
||||
if not indexes_details:
|
||||
pass
|
||||
else:
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'Indexes'),
|
||||
indexes_details))
|
||||
|
||||
# triggers
|
||||
triggers_details = self.triggersDetails()
|
||||
if not triggers_details:
|
||||
pass
|
||||
else:
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'Triggers'),
|
||||
triggers_details))
|
||||
|
||||
if self.table.objectType == u"MATERIALIZED VIEW":
|
||||
mview_info = self.getMViewInfo()
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'Materialized View informations'),
|
||||
mview_info))
|
||||
|
||||
return ret
|
||||
|
||||
def getMViewInfo(self):
|
||||
"""If the table is a materialized view, grab more
|
||||
informations...
|
||||
"""
|
||||
ret = []
|
||||
tbl = []
|
||||
values = self.table.getMViewInfo()
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Refresh Mode:"),
|
||||
values[0]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Refresh Method:"),
|
||||
values[1]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Build Mode:"),
|
||||
values[2]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Last Refresh Date:"),
|
||||
values[5]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Last Refresh Type:"),
|
||||
values[4]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Fast Refreshable:"),
|
||||
values[3]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Staleness:"),
|
||||
values[6]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Stale since:"),
|
||||
values[7]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Compile State:"),
|
||||
values[8]))
|
||||
tbl.append((QApplication.translate("DBManagerPlugin",
|
||||
"Use no index:"),
|
||||
values[9]))
|
||||
tbl.append((QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u'<a href="action:mview/refresh">Refresh the materializ'
|
||||
u'ed view</a>')),
|
||||
u""))
|
||||
ret.append(HtmlTable(tbl))
|
||||
|
||||
return ret
|
||||
|
||||
def getViewInfo(self):
|
||||
"""If the table is a view or a materialized view, add the
|
||||
definition of the view.
|
||||
"""
|
||||
|
||||
if self.table.objectType not in [u"VIEW", u"MATERIALIZED VIEW"]:
|
||||
return []
|
||||
|
||||
ret = self.getTableInfo()
|
||||
|
||||
# view definition
|
||||
view_def = self.table.getDefinition()
|
||||
|
||||
# Syntax highlight
|
||||
lexer = get_lexer_by_name("sql")
|
||||
formatter = HtmlFormatter(
|
||||
linenos=True, cssclass="source", noclasses=True)
|
||||
result = highlight(view_def, lexer, formatter)
|
||||
|
||||
if view_def:
|
||||
if self.table.objectType == u"VIEW":
|
||||
title = u"View Definition"
|
||||
else:
|
||||
title = u"Materialized View Definition"
|
||||
ret.append(
|
||||
HtmlSection(
|
||||
QApplication.translate("DBManagerPlugin", title),
|
||||
result))
|
||||
|
||||
return ret
|
||||
|
||||
def toHtml(self):
|
||||
if self.table.objectType in [u"VIEW", u"MATERIALIZED VIEW"]:
|
||||
ret = self.getViewInfo()
|
||||
else:
|
||||
ret = self.getTableInfo()
|
||||
return HtmlContent(ret).toHtml()
|
||||
|
||||
|
||||
class ORVectorTableInfo(ORTableInfo, VectorTableInfo):
|
||||
|
||||
def __init__(self, table):
|
||||
VectorTableInfo.__init__(self, table)
|
||||
ORTableInfo.__init__(self, table)
|
||||
|
||||
def spatialInfo(self):
|
||||
ret = []
|
||||
if not self.table.geomType:
|
||||
return ret
|
||||
|
||||
tbl = [
|
||||
(QApplication.translate("DBManagerPlugin", "Column:"),
|
||||
self.table.geomColumn),
|
||||
(QApplication.translate("DBManagerPlugin", "Geometry:"),
|
||||
self.table.geomType),
|
||||
(QApplication.translate("DBManagerPlugin",
|
||||
"QGis Geometry type:"),
|
||||
QGis.featureType(self.table.wkbType))
|
||||
]
|
||||
|
||||
# only if we have info from geometry_columns
|
||||
if self.table.geomDim:
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
"Dimension:"),
|
||||
self.table.geomDim))
|
||||
|
||||
srid = self.table.srid if self.table.srid else -1
|
||||
if srid != -1:
|
||||
sr_info = (
|
||||
self.table.database().connector.getSpatialRefInfo(srid))
|
||||
else:
|
||||
sr_info = QApplication.translate("DBManagerPlugin",
|
||||
"Undefined")
|
||||
if sr_info:
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Spatial ref:"),
|
||||
u"{0} ({1})".format(sr_info, srid)))
|
||||
|
||||
# estimated extent
|
||||
if not self.table.estimatedExtent:
|
||||
# estimated extent information is not displayed yet, so just block
|
||||
# table signals to avoid double refreshing
|
||||
# (infoViewer->refreshEstimatedExtent->tableChanged->infoViewer)
|
||||
self.table.blockSignals(True)
|
||||
self.table.refreshTableEstimatedExtent()
|
||||
self.table.blockSignals(False)
|
||||
|
||||
if self.table.estimatedExtent:
|
||||
estimated_extent_str = (u"{:.9f}, {:.9f} - {:.9f}, "
|
||||
u"{:.9f}".format(
|
||||
*self.table.estimatedExtent))
|
||||
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Estimated extent:"),
|
||||
estimated_extent_str))
|
||||
|
||||
# extent
|
||||
extent_str = None
|
||||
if self.table.extent and len(self.table.extent) == 4:
|
||||
extent_str = (u"{:.9f}, {:.9f} - {:.9f}, "
|
||||
u"{:.9f}".format(*self.table.extent))
|
||||
elif self.table.rowCount > 0 or self.table.estimatedRowCount > 0:
|
||||
# Can't calculate an extent on empty layer
|
||||
extent_str = QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
'(unknown) (<a href="action:extent/get">find out</a>)')
|
||||
|
||||
if extent_str:
|
||||
tbl.append(
|
||||
(QApplication.translate(
|
||||
"DBManagerPlugin", "Extent:"),
|
||||
extent_str))
|
||||
|
||||
ret.append(HtmlTable(tbl))
|
||||
|
||||
# Handle extent update metadata
|
||||
if (self.table.extent
|
||||
and self.table.extent != self.table.estimatedExtent
|
||||
and self.table.canUpdateMetadata()):
|
||||
ret.append(
|
||||
HtmlParagraph(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u'<warning> Metadata extent is different from'
|
||||
u'real extent. You should <a href="action:extent'
|
||||
u'/update">update it</a> !'))))
|
||||
|
||||
# is there an entry in geometry_columns?
|
||||
if self.table.geomType.lower() == 'geometry':
|
||||
ret.append(
|
||||
HtmlParagraph(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
"<warning> There isn't entry in geometry_columns!")))
|
||||
|
||||
# find out whether the geometry column has spatial index on it
|
||||
if not self.table.isView:
|
||||
if not self.table.hasSpatialIndex():
|
||||
ret.append(
|
||||
HtmlParagraph(
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
(u'<warning> No spatial index defined (<a href='
|
||||
u'"action:spatialindex/create">'
|
||||
u'create it</a>).'))))
|
||||
|
||||
return ret
|
653
python/plugins/db_manager/db_plugins/oracle/plugin.py
Normal file
653
python/plugins/db_manager/db_plugins/oracle/plugin.py
Normal file
@ -0,0 +1,653 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
/***************************************************************************
|
||||
Name : DB Manager
|
||||
Description : Database manager plugin for QGIS (Oracle)
|
||||
Date : Aug 27, 2014
|
||||
copyright : (C) 2014 by Médéric RIBREUX
|
||||
email : mederic.ribreux@gmail.com
|
||||
|
||||
The content of this file is based on
|
||||
- PG_Manager by Martin Dobias <wonder.sk@gmail.com> (GPLv2 license)
|
||||
- DB Manager by Giuseppe Sucameli <brush.tyler@gmail.com> (GPLv2 license)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
"""
|
||||
|
||||
# this will disable the dbplugin if the connector raise an ImportError
|
||||
from .connector import OracleDBConnector
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
from ..plugin import ConnectionError, InvalidDataException, DBPlugin, \
|
||||
Database, Schema, Table, VectorTable, TableField, TableConstraint, \
|
||||
TableIndex, TableTrigger, TableRule
|
||||
|
||||
try:
|
||||
from . import resources_rc
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from ..html_elems import HtmlParagraph, HtmlList, HtmlTable
|
||||
|
||||
from qgis.core import QgsCredentials
|
||||
|
||||
|
||||
def classFactory():
|
||||
return OracleDBPlugin
|
||||
|
||||
|
||||
class OracleDBPlugin(DBPlugin):
|
||||
|
||||
@classmethod
|
||||
def icon(self):
|
||||
return QIcon(":/db_manager/oracle/icon")
|
||||
|
||||
@classmethod
|
||||
def typeName(self):
|
||||
return 'oracle'
|
||||
|
||||
@classmethod
|
||||
def typeNameString(self):
|
||||
return 'Oracle Spatial'
|
||||
|
||||
@classmethod
|
||||
def providerName(self):
|
||||
return 'oracle'
|
||||
|
||||
@classmethod
|
||||
def connectionSettingsKey(self):
|
||||
return '/Oracle/connections'
|
||||
|
||||
def connectToUri(self, uri):
|
||||
self.db = self.databasesFactory(self, uri)
|
||||
if self.db:
|
||||
return True
|
||||
return False
|
||||
|
||||
def databasesFactory(self, connection, uri):
|
||||
return ORDatabase(connection, uri)
|
||||
|
||||
def connect(self, parent=None):
|
||||
conn_name = self.connectionName()
|
||||
settings = QSettings()
|
||||
settings.beginGroup(u"/{0}/{1}".format(
|
||||
self.connectionSettingsKey(), conn_name))
|
||||
|
||||
if not settings.contains("database"): # non-existent entry?
|
||||
raise InvalidDataException(
|
||||
self.tr('There is no defined database connection "{}".'.format(
|
||||
conn_name)))
|
||||
|
||||
from qgis.core import QgsDataSourceURI
|
||||
uri = QgsDataSourceURI()
|
||||
|
||||
settingsList = ["host", "port", "database", "username", "password"]
|
||||
host, port, database, username, password = map(
|
||||
lambda x: settings.value(x, "", type=str), settingsList)
|
||||
|
||||
# qgis1.5 use 'savePassword' instead of 'save' setting
|
||||
savedPassword = settings.value("save", False, type=bool) or \
|
||||
settings.value("savePassword", False, type=bool)
|
||||
|
||||
# get all of the connexion options
|
||||
|
||||
useEstimatedMetadata = settings.value(
|
||||
"estimatedMetadata", False, type=bool)
|
||||
uri.setParam('userTablesOnly', str(
|
||||
settings.value("userTablesOnly", False, type=bool)))
|
||||
uri.setParam('geometryColumnsOnly', str(
|
||||
settings.value("geometryColumnsOnly", False, type=bool)))
|
||||
uri.setParam('allowGeometrylessTables', str(
|
||||
settings.value("allowGeometrylessTables", False, type=bool)))
|
||||
uri.setParam('onlyExistingTypes', str(
|
||||
settings.value("onlyExistingTypes", False, type=bool)))
|
||||
|
||||
settings.endGroup()
|
||||
|
||||
uri.setConnection(host, port, database, username, password)
|
||||
|
||||
uri.setUseEstimatedMetadata(useEstimatedMetadata)
|
||||
|
||||
err = u""
|
||||
try:
|
||||
return self.connectToUri(uri)
|
||||
except ConnectionError, e:
|
||||
err = str(e)
|
||||
|
||||
# ask for valid credentials
|
||||
max_attempts = 3
|
||||
for i in range(max_attempts):
|
||||
(ok, username, password) = QgsCredentials.instance().get(
|
||||
uri.connectionInfo(), username, password, err)
|
||||
|
||||
if not ok:
|
||||
return False
|
||||
|
||||
uri.setConnection(host, port, database, username, password)
|
||||
|
||||
try:
|
||||
self.connectToUri(uri)
|
||||
except ConnectionError, e:
|
||||
if i == max_attempts - 1: # failed the last attempt
|
||||
raise e
|
||||
err = str(e)
|
||||
continue
|
||||
|
||||
QgsCredentials.instance().put(
|
||||
uri.connectionInfo(), username, password)
|
||||
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class ORDatabase(Database):
|
||||
|
||||
def __init__(self, connection, uri):
|
||||
self.connName = connection.connectionName()
|
||||
Database.__init__(self, connection, uri)
|
||||
|
||||
def connectorsFactory(self, uri):
|
||||
return OracleDBConnector(uri, self.connName)
|
||||
|
||||
def dataTablesFactory(self, row, db, schema=None):
|
||||
return ORTable(row, db, schema)
|
||||
|
||||
def vectorTablesFactory(self, row, db, schema=None):
|
||||
return ORVectorTable(row, db, schema)
|
||||
|
||||
def info(self):
|
||||
from .info_model import ORDatabaseInfo
|
||||
return ORDatabaseInfo(self)
|
||||
|
||||
def schemasFactory(self, row, db):
|
||||
return ORSchema(row, db)
|
||||
|
||||
def columnUniqueValuesModel(self, col, table, limit=10):
|
||||
l = u""
|
||||
if limit:
|
||||
l = u"WHERE ROWNUM < {:d}".format(limit)
|
||||
con = self.database().connector
|
||||
# Prevent geometry column show
|
||||
tableName = table.replace(u'"', u"").split(u".")
|
||||
if len(tableName) == 0:
|
||||
tableName = [None, tableName[0]]
|
||||
colName = col.replace(u'"', u"").split(u".")[-1]
|
||||
|
||||
if con.isGeometryColumn(tableName, colName):
|
||||
return None
|
||||
|
||||
query = u"SELECT DISTINCT {} FROM {} {}".format(col, table, l)
|
||||
return self.sqlResultModel(query, self)
|
||||
|
||||
def sqlResultModel(self, sql, parent):
|
||||
from .data_model import ORSqlResultModel
|
||||
return ORSqlResultModel(self, sql, parent)
|
||||
|
||||
def toSqlLayer(self, sql, geomCol, uniqueCol,
|
||||
layerName=u"QueryLayer", layerType=None,
|
||||
avoidSelectById=False):
|
||||
from qgis.core import QgsMapLayer, QgsVectorLayer
|
||||
|
||||
uri = self.uri()
|
||||
con = self.database().connector
|
||||
|
||||
uri.setDataSource(u"", u"({})".format(sql), geomCol, u"", uniqueCol)
|
||||
if avoidSelectById:
|
||||
uri.disableSelectAtId(True)
|
||||
provider = self.dbplugin().providerName()
|
||||
vlayer = QgsVectorLayer(uri.uri(), layerName, provider)
|
||||
|
||||
# handling undetermined geometry type
|
||||
if not vlayer.isValid():
|
||||
|
||||
wkbType, srid = con.getTableMainGeomType(
|
||||
u"({})".format(sql), geomCol)
|
||||
uri.setWkbType(wkbType)
|
||||
if srid:
|
||||
uri.setSrid(unicode(srid))
|
||||
vlayer = QgsVectorLayer(uri.uri(), layerName, provider)
|
||||
|
||||
return vlayer
|
||||
|
||||
def registerDatabaseActions(self, mainWindow):
|
||||
action = QAction(QApplication.translate(
|
||||
"DBManagerPlugin", "&Re-connect"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Database"), self.reconnectActionSlot)
|
||||
|
||||
if self.schemas():
|
||||
action = QAction(QApplication.translate(
|
||||
"DBManagerPlugin", "&Create schema"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Schema"), self.createSchemaActionSlot)
|
||||
action = QAction(QApplication.translate(
|
||||
"DBManagerPlugin", "&Delete (empty) schema"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Schema"), self.deleteSchemaActionSlot)
|
||||
|
||||
action = QAction(QApplication.translate(
|
||||
"DBManagerPlugin", "Delete selected item"), self)
|
||||
mainWindow.registerAction(action, None, self.deleteActionSlot)
|
||||
action.setShortcuts(QKeySequence.Delete)
|
||||
|
||||
action = QAction(QIcon(":/db_manager/actions/create_table"),
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin", "&Create table"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Table"), self.createTableActionSlot)
|
||||
action = QAction(QIcon(":/db_manager/actions/edit_table"),
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin", "&Edit table"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Table"), self.editTableActionSlot)
|
||||
action = QAction(QIcon(":/db_manager/actions/del_table"),
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin", "&Delete table/view"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Table"), self.deleteTableActionSlot)
|
||||
action = QAction(QApplication.translate(
|
||||
"DBManagerPlugin", "&Empty table"), self)
|
||||
mainWindow.registerAction(action, QApplication.translate(
|
||||
"DBManagerPlugin", "&Table"), self.emptyTableActionSlot)
|
||||
|
||||
|
||||
class ORSchema(Schema):
|
||||
|
||||
def __init__(self, row, db):
|
||||
Schema.__init__(self, db)
|
||||
# self.oid, self.name, self.owner, self.perms, self.comment = row
|
||||
self.name = row[0]
|
||||
|
||||
|
||||
class ORTable(Table):
|
||||
|
||||
def __init__(self, row, db, schema=None):
|
||||
Table.__init__(self, db, schema)
|
||||
self.name, self.owner, isView = row
|
||||
|
||||
self.estimatedRowCount = None
|
||||
self.objectType = None
|
||||
self.isView = False
|
||||
self.isMaterializedView = False
|
||||
if isView == 1:
|
||||
self.isView = True
|
||||
self.creationDate = None
|
||||
self.modificationDate = None
|
||||
|
||||
def getDates(self):
|
||||
"""Grab the creation/modification dates of the table"""
|
||||
self.creationDate, self.modificationDate = (
|
||||
self.database().connector.getTableDates((self.schemaName(),
|
||||
self.name)))
|
||||
|
||||
def refreshRowEstimation(self):
|
||||
"""Use ALL_ALL_TABLE to get an estimation of rows"""
|
||||
if self.isView:
|
||||
self.estimatedRowCount = 0
|
||||
|
||||
self.estimatedRowCount = (
|
||||
self.database().connector.getTableRowEstimation(
|
||||
(self.schemaName(), self.name)))
|
||||
|
||||
def getType(self):
|
||||
"""Grab the type of object for the table"""
|
||||
self.objectType = self.database().connector.getTableType(
|
||||
(self.schemaName(), self.name))
|
||||
|
||||
def getComment(self):
|
||||
"""Grab the general comment of the table/view"""
|
||||
self.comment = self.database().connector.getTableComment(
|
||||
(self.schemaName(), self.name), self.objectType)
|
||||
|
||||
def getDefinition(self):
|
||||
return self.database().connector.getDefinition(
|
||||
(self.schemaName(), self.name), self.objectType)
|
||||
|
||||
def getMViewInfo(self):
|
||||
if self.objectType == u"MATERIALIZED VIEW":
|
||||
return self.database().connector.getMViewInfo(
|
||||
(self.schemaName(), self.name))
|
||||
else:
|
||||
return None
|
||||
|
||||
def runAction(self, action):
|
||||
action = unicode(action)
|
||||
|
||||
if action.startswith("rows/"):
|
||||
if action == "rows/recount":
|
||||
self.refreshRowCount()
|
||||
return True
|
||||
elif action.startswith("index/"):
|
||||
parts = action.split('/')
|
||||
index_name = parts[1]
|
||||
index_action = parts[2]
|
||||
|
||||
msg = QApplication.translate(
|
||||
"DBManagerPlugin",
|
||||
"Do you want to {} index {} ?".format(
|
||||
index_action, index_name))
|
||||
QApplication.restoreOverrideCursor()
|
||||
try:
|
||||
if QMessageBox.question(
|
||||
None,
|
||||
QApplication.translate(
|
||||
"DBManagerPlugin", "Table Index"),
|
||||
msg,
|
||||
QMessageBox.Yes | QMessageBox.No) == QMessageBox.No:
|
||||
return False
|
||||
finally:
|
||||
QApplication.setOverrideCursor(Qt.WaitCursor)
|
||||
|
||||
if index_action == "rebuild":
|
||||
self.aboutToChange()
|
||||
self.database().connector.rebuildTableIndex(
|
||||
(self.schemaName(), self.name), index_name)
|
||||
self.refreshIndexes()
|
||||
return True
|
||||
elif action.startswith(u"mview/"):
|
||||
if action == "mview/refresh":
|
||||
self.aboutToChange()
|
||||
self.database().connector.refreshMView(
|
||||
(self.schemaName(), self.name))
|
||||
return True
|
||||
|
||||
return Table.runAction(self, action)
|
||||
|
||||
def tableFieldsFactory(self, row, table):
|
||||
return ORTableField(row, table)
|
||||
|
||||
def tableConstraintsFactory(self, row, table):
|
||||
return ORTableConstraint(row, table)
|
||||
|
||||
def tableIndexesFactory(self, row, table):
|
||||
return ORTableIndex(row, table)
|
||||
|
||||
def tableTriggersFactory(self, row, table):
|
||||
return ORTableTrigger(row, table)
|
||||
|
||||
def info(self):
|
||||
from .info_model import ORTableInfo
|
||||
return ORTableInfo(self)
|
||||
|
||||
def tableDataModel(self, parent):
|
||||
from .data_model import ORTableDataModel
|
||||
return ORTableDataModel(self, parent)
|
||||
|
||||
def getValidQGisUniqueFields(self, onlyOne=False):
|
||||
""" list of fields valid to load the table as layer in QGis canvas.
|
||||
QGis automatically search for a valid unique field, so it's
|
||||
needed only for queries and views.
|
||||
"""
|
||||
|
||||
ret = []
|
||||
|
||||
# add the pk
|
||||
pkcols = filter(lambda x: x.primaryKey, self.fields())
|
||||
if len(pkcols) == 1:
|
||||
ret.append(pkcols[0])
|
||||
|
||||
# then add integer fields with an unique index
|
||||
indexes = self.indexes()
|
||||
if indexes is not None:
|
||||
for idx in indexes:
|
||||
if idx.isUnique and len(idx.columns) == 1:
|
||||
fld = idx.fields()[idx.columns[0]]
|
||||
if (fld.dataType == u"NUMBER"
|
||||
and not fld.modifier
|
||||
and fld.notNull
|
||||
and fld not in ret):
|
||||
ret.append(fld)
|
||||
|
||||
# and finally append the other suitable fields
|
||||
for fld in self.fields():
|
||||
if (fld.dataType == u"NUMBER"
|
||||
and not fld.modifier
|
||||
and fld.notNull
|
||||
and fld not in ret):
|
||||
ret.append(fld)
|
||||
|
||||
if onlyOne:
|
||||
return ret[0] if len(ret) > 0 else None
|
||||
return ret
|
||||
|
||||
def uri(self):
|
||||
uri = self.database().uri()
|
||||
schema = self.schemaName() if self.schemaName() else ''
|
||||
geomCol = self.geomColumn if self.type in [
|
||||
Table.VectorType, Table.RasterType] else ""
|
||||
uniqueCol = self.getValidQGisUniqueFields(
|
||||
True) if self.isView else None
|
||||
uri.setDataSource(schema, self.name, geomCol if geomCol else None,
|
||||
None, uniqueCol.name if uniqueCol else "")
|
||||
|
||||
# Handle geographic table
|
||||
if geomCol:
|
||||
uri.setWkbType(self.wkbType)
|
||||
uri.setSrid(unicode(self.srid))
|
||||
|
||||
return uri
|
||||
|
||||
|
||||
class ORVectorTable(ORTable, VectorTable):
|
||||
|
||||
def __init__(self, row, db, schema=None):
|
||||
ORTable.__init__(self, row[0:3], db, schema)
|
||||
VectorTable.__init__(self, db, schema)
|
||||
self.geomColumn, self.geomType, self.wkbType, self.geomDim, \
|
||||
self.srid = row[-7:-2]
|
||||
|
||||
def info(self):
|
||||
from .info_model import ORVectorTableInfo
|
||||
return ORVectorTableInfo(self)
|
||||
|
||||
def runAction(self, action):
|
||||
if action.startswith("extent/"):
|
||||
if action == "extent/update":
|
||||
self.aboutToChange()
|
||||
self.updateExtent()
|
||||
return True
|
||||
|
||||
if ORTable.runAction(self, action):
|
||||
return True
|
||||
|
||||
return VectorTable.runAction(self, action)
|
||||
|
||||
def canUpdateMetadata(self):
|
||||
return self.database().connector.canUpdateMetadata((self.schemaName(),
|
||||
self.name))
|
||||
|
||||
def updateExtent(self):
|
||||
self.database().connector.updateMetadata(
|
||||
(self.schemaName(), self.name),
|
||||
self.geomColumn, extent=self.extent)
|
||||
self.refreshTableEstimatedExtent()
|
||||
self.refresh()
|
||||
|
||||
def hasSpatialIndex(self, geom_column=None):
|
||||
geom_column = geom_column if geom_column else self.geomColumn
|
||||
|
||||
for idx in self.indexes():
|
||||
if geom_column == idx.column:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class ORTableField(TableField):
|
||||
|
||||
def __init__(self, row, table):
|
||||
""" build fields information from query and find primary key """
|
||||
TableField.__init__(self, table)
|
||||
self.num, self.name, self.dataType, self.charMaxLen, \
|
||||
self.modifier, self.notNull, self.hasDefault, \
|
||||
self.default, typeStr, self.comment = row
|
||||
|
||||
self.primaryKey = False
|
||||
self.num = int(self.num)
|
||||
if isinstance(self.charMaxLen, QPyNullVariant):
|
||||
self.charMaxLen = None
|
||||
else:
|
||||
self.charMaxLen = int(self.charMaxLen)
|
||||
|
||||
if isinstance(self.modifier, QPyNullVariant):
|
||||
self.modifier = None
|
||||
else:
|
||||
self.modifier = int(self.modifier)
|
||||
|
||||
if self.notNull.upper() == u"Y":
|
||||
self.notNull = False
|
||||
else:
|
||||
self.notNull = True
|
||||
|
||||
if isinstance(self.comment, QPyNullVariant):
|
||||
self.comment = u""
|
||||
|
||||
# find out whether fields are part of primary key
|
||||
for con in self.table().constraints():
|
||||
if (con.type == ORTableConstraint.TypePrimaryKey
|
||||
and self.name == con.column):
|
||||
self.primaryKey = True
|
||||
break
|
||||
|
||||
def type2String(self):
|
||||
if (u"TIMESTAMP" in self.dataType
|
||||
or self.dataType in [u"DATE", u"SDO_GEOMETRY",
|
||||
u"BINARY_FLOAT", u"BINARY_DOUBLE"]):
|
||||
return u"{}".format(self.dataType)
|
||||
if self.charMaxLen in [None, -1]:
|
||||
return u"{}".format(self.dataType)
|
||||
elif self.modifier in [None, -1, 0]:
|
||||
return u"{}({})".format(self.dataType, self.charMaxLen)
|
||||
|
||||
return u"{}({},{})".format(self.dataType, self.charMaxLen,
|
||||
self.modifier)
|
||||
|
||||
def update(self, new_name, new_type_str=None, new_not_null=None,
|
||||
new_default_str=None):
|
||||
self.table().aboutToChange()
|
||||
if self.name == new_name:
|
||||
new_name = None
|
||||
if self.type2String() == new_type_str:
|
||||
new_type_str = None
|
||||
if self.notNull == new_not_null:
|
||||
new_not_null = None
|
||||
if self.default2String() == new_default_str:
|
||||
new_default_str = None
|
||||
|
||||
ret = self.table().database().connector.updateTableColumn(
|
||||
(self.table().schemaName(), self.table().name),
|
||||
self.name, new_name, new_type_str,
|
||||
new_not_null, new_default_str)
|
||||
|
||||
# When changing a field, refresh also constraints and
|
||||
# indexes.
|
||||
if ret is not False:
|
||||
self.table().refreshFields()
|
||||
self.table().refreshConstraints()
|
||||
self.table().refreshIndexes()
|
||||
return ret
|
||||
|
||||
|
||||
class ORTableConstraint(TableConstraint):
|
||||
|
||||
TypeCheck, TypeForeignKey, TypePrimaryKey, \
|
||||
TypeUnique, TypeUnknown = range(5)
|
||||
|
||||
types = {"c": TypeCheck, "r": TypeForeignKey,
|
||||
"p": TypePrimaryKey, "u": TypeUnique}
|
||||
|
||||
def __init__(self, row, table):
|
||||
""" build constraints info from query """
|
||||
TableConstraint.__init__(self, table)
|
||||
self.name, constr_type_str, self.column, self.validated, \
|
||||
self.generated, self.status = row[0:6]
|
||||
constr_type_str = constr_type_str.lower()
|
||||
|
||||
if constr_type_str in ORTableConstraint.types:
|
||||
self.type = ORTableConstraint.types[constr_type_str]
|
||||
else:
|
||||
self.type = ORTableConstraint.TypeUnknown
|
||||
|
||||
if isinstance(row[6], QPyNullVariant):
|
||||
self.checkSource = u""
|
||||
else:
|
||||
self.checkSource = row[6]
|
||||
|
||||
if isinstance(row[8], QPyNullVariant):
|
||||
self.foreignTable = u""
|
||||
else:
|
||||
self.foreignTable = row[8]
|
||||
|
||||
if isinstance(row[7], QPyNullVariant):
|
||||
self.foreignOnDelete = u""
|
||||
else:
|
||||
self.foreignOnDelete = row[7]
|
||||
|
||||
if isinstance(row[9], QPyNullVariant):
|
||||
self.foreignKey = u""
|
||||
else:
|
||||
self.foreignKey = row[9]
|
||||
|
||||
def type2String(self):
|
||||
if self.type == ORTableConstraint.TypeCheck:
|
||||
return QApplication.translate("DBManagerPlugin", "Check")
|
||||
if self.type == ORTableConstraint.TypePrimaryKey:
|
||||
return QApplication.translate("DBManagerPlugin", "Primary key")
|
||||
if self.type == ORTableConstraint.TypeForeignKey:
|
||||
return QApplication.translate("DBManagerPlugin", "Foreign key")
|
||||
if self.type == ORTableConstraint.TypeUnique:
|
||||
return QApplication.translate("DBManagerPlugin", "Unique")
|
||||
|
||||
return QApplication.translate("DBManagerPlugin", 'Unknown')
|
||||
|
||||
def fields(self):
|
||||
""" Hack to make edit dialog box work """
|
||||
fields = self.table().fields()
|
||||
field = None
|
||||
for fld in fields:
|
||||
if fld.name == self.column:
|
||||
field = fld
|
||||
cols = {}
|
||||
cols[0] = field
|
||||
|
||||
return cols
|
||||
|
||||
|
||||
class ORTableIndex(TableIndex):
|
||||
|
||||
def __init__(self, row, table):
|
||||
TableIndex.__init__(self, table)
|
||||
self.name, self.column, self.indexType, self.status, \
|
||||
self.analyzed, self.compression, self.isUnique = row
|
||||
|
||||
def fields(self):
|
||||
""" Hack to make edit dialog box work """
|
||||
self.table().refreshFields()
|
||||
fields = self.table().fields()
|
||||
|
||||
field = None
|
||||
for fld in fields:
|
||||
if fld.name == self.column:
|
||||
field = fld
|
||||
cols = {}
|
||||
cols[0] = field
|
||||
|
||||
return cols
|
||||
|
||||
|
||||
class ORTableTrigger(TableTrigger):
|
||||
|
||||
def __init__(self, row, table):
|
||||
TableTrigger.__init__(self, table)
|
||||
self.name, self.event, self.type, self.enabled = row
|
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/db_manager/oracle">
|
||||
<file alias="icon">icons/oracle.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
308
python/plugins/db_manager/db_plugins/oracle/sql_dictionary.py
Normal file
308
python/plugins/db_manager/db_plugins/oracle/sql_dictionary.py
Normal file
@ -0,0 +1,308 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
/***************************************************************************
|
||||
Name : DB Manager
|
||||
Description : Database manager plugin for QGIS (Oracle)
|
||||
Date : Aug 27, 2014
|
||||
copyright : (C) 2014 by Médéric RIBREUX
|
||||
email : mederic.ribreux@gmail.com
|
||||
|
||||
The content of this file is based on
|
||||
- PG_Manager by Martin Dobias <wonder.sk@gmail.com> (GPLv2 license)
|
||||
- DB Manager by Giuseppe Sucameli <brush.tyler@gmail.com> (GPLv2 license)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
"""
|
||||
|
||||
__author__ = 'Médéric RIBREUX'
|
||||
__date__ = 'August 2014'
|
||||
__copyright__ = '(C) 2014, Médéric RIBREUX'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
# keywords
|
||||
keywords = [
|
||||
# From:
|
||||
# http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm
|
||||
"ACCESS", "ADD", "ALL", "ALTER", "AND", "ANY", "AS", "ASC",
|
||||
"AUDIT", "BETWEEN", "BY", "CHAR", "CHECK", "CLUSTER", "COLUMN",
|
||||
"COMMENT", "COMPRESS", "CONNECT", "CREATE", "CURRENT", "DATE",
|
||||
"DECIMAL", "DEFAULT", "DELETE", "DESC", "DISTINCT", "DROP",
|
||||
"ELSE", "EXCLUSIVE", "EXISTS", "FILE", "FLOAT", "FOR", "FROM",
|
||||
"GRANT", "GROUP", "HAVING", "IDENTIFIED", "IMMEDIATE", "IN",
|
||||
"INCREMENT", "INDEX", "INITIAL", "INSERT", "INTEGER", "INTERSECT",
|
||||
"INTO", "IS", "LEVEL", "LIKE", "LOCK", "LONG", "MAXEXTENTS",
|
||||
"MINUS", "MLSLABEL", "MODE", "MODIFY", "NOAUDIT", "NOCOMPRESS",
|
||||
"NOT", "NOWAIT", "NULL", "NUMBER", "OF", "OFFLINE", "ON",
|
||||
"ONLINE", "OPTION", "OR", "ORDER", "PCTFREE", "PRIOR",
|
||||
"PRIVILEGES", "PUBLIC", "RAW", "RENAME", "RESOURCE", "REVOKE",
|
||||
"ROW", "ROWID", "ROWNUM", "ROWS", "SELECT", "SESSION", "SET",
|
||||
"SHARE", "SIZE", "SMALLINT", "START", "SUCCESSFUL", "SYNONYM",
|
||||
"SYSDATE", "TABLE", "THEN", "TO", "TRIGGER", "UID", "UNION",
|
||||
"UNIQUE", "UPDATE", "USER", "VALIDATE", "VALUES", "VARCHAR",
|
||||
"VARCHAR2", "VIEW", "WHENEVER", "WHERE", "WITH",
|
||||
# From http://docs.oracle.com/cd/B13789_01/appdev.101/a42525/apb.htm
|
||||
"ADMIN", "CURSOR", "FOUND", "MOUNT", "AFTER", "CYCLE", "FUNCTION",
|
||||
"NEXT", "ALLOCATE", "DATABASE", "GO", "NEW", "ANALYZE",
|
||||
"DATAFILE", "GOTO", "NOARCHIVELOG", "ARCHIVE", "DBA", "GROUPS",
|
||||
"NOCACHE", "ARCHIVELOG", "DEC", "INCLUDING", "NOCYCLE",
|
||||
"AUTHORIZATION", "DECLARE", "INDICATOR", "NOMAXVALUE", "AVG",
|
||||
"DISABLE", "INITRANS", "NOMINVALUE", "BACKUP", "DISMOUNT",
|
||||
"INSTANCE", "NONE", "BEGIN", "DOUBLE", "INT", "NOORDER", "BECOME",
|
||||
"DUMP", "KEY", "NORESETLOGS", "BEFORE", "EACH", "LANGUAGE",
|
||||
"NORMAL", "BLOCK", "ENABLE", "LAYER", "NOSORT", "BODY", "END",
|
||||
"LINK", "NUMERIC", "CACHE", "ESCAPE", "LISTS", "OFF", "CANCEL",
|
||||
"EVENTS", "LOGFILE", "OLD", "CASCADE", "EXCEPT", "MANAGE", "ONLY",
|
||||
"CHANGE", "EXCEPTIONS", "MANUAL", "OPEN", "CHARACTER", "EXEC",
|
||||
"MAX", "OPTIMAL", "CHECKPOINT", "EXPLAIN", "MAXDATAFILES", "OWN",
|
||||
"CLOSE", "EXECUTE", "MAXINSTANCES", "PACKAGE", "COBOL", "EXTENT",
|
||||
"MAXLOGFILES", "PARALLEL", "COMMIT", "EXTERNALLY",
|
||||
"MAXLOGHISTORY", "PCTINCREASE", "COMPILE", "FETCH",
|
||||
"MAXLOGMEMBERS", "PCTUSED", "CONSTRAINT", "FLUSH", "MAXTRANS",
|
||||
"PLAN", "CONSTRAINTS", "FREELIST", "MAXVALUE", "PLI", "CONTENTS",
|
||||
"FREELISTS", "MIN", "PRECISION", "CONTINUE", "FORCE",
|
||||
"MINEXTENTS", "PRIMARY", "CONTROLFILE", "FOREIGN", "MINVALUE",
|
||||
"PRIVATE", "COUNT", "FORTRAN", "MODULE", "PROCEDURE", "PROFILE",
|
||||
"SAVEPOINT", "SQLSTATE", "TRACING", "QUOTA", "SCHEMA",
|
||||
"STATEMENT_ID", "TRANSACTION", "READ", "SCN", "STATISTICS",
|
||||
"TRIGGERS", "REAL", "SECTION", "STOP", "TRUNCATE", "RECOVER",
|
||||
"SEGMENT", "STORAGE", "UNDER", "REFERENCES", "SEQUENCE", "SUM",
|
||||
"UNLIMITED", "REFERENCING", "SHARED", "SWITCH", "UNTIL",
|
||||
"RESETLOGS", "SNAPSHOT", "SYSTEM", "USE", "RESTRICTED", "SOME",
|
||||
"TABLES", "USING", "REUSE", "SORT", "TABLESPACE", "WHEN", "ROLE",
|
||||
"SQL", "TEMPORARY", "WRITE", "ROLES", "SQLCODE", "THREAD", "WORK",
|
||||
"ROLLBACK", "SQLERROR", "TIME", "ABORT", "BETWEEN", "CRASH",
|
||||
"DIGITS", "ACCEPT", "BINARY_INTEGER", "CREATE", "DISPOSE",
|
||||
"ACCESS", "BODY", "CURRENT", "DISTINCT", "ADD", "BOOLEAN",
|
||||
"CURRVAL", "DO", "ALL", "BY", "CURSOR", "DROP", "ALTER", "CASE",
|
||||
"DATABASE", "ELSE", "AND", "CHAR", "DATA_BASE", "ELSIF", "ANY",
|
||||
"CHAR_BASE", "DATE", "END", "ARRAY", "CHECK", "DBA", "ENTRY",
|
||||
"ARRAYLEN", "CLOSE", "DEBUGOFF", "EXCEPTION", "AS", "CLUSTER",
|
||||
"DEBUGON", "EXCEPTION_INIT", "ASC", "CLUSTERS", "DECLARE",
|
||||
"EXISTS", "ASSERT", "COLAUTH", "DECIMAL", "EXIT", "ASSIGN",
|
||||
"COLUMNS", "DEFAULT", "FALSE", "AT", "COMMIT", "DEFINITION",
|
||||
"FETCH", "AUTHORIZATION", "COMPRESS", "DELAY", "FLOAT", "AVG",
|
||||
"CONNECT", "DELETE", "FOR", "BASE_TABLE", "CONSTANT", "DELTA",
|
||||
"FORM", "BEGIN", "COUNT", "DESC", "FROM", "FUNCTION", "NEW",
|
||||
"RELEASE", "SUM", "GENERIC", "NEXTVAL", "REMR", "TABAUTH", "GOTO",
|
||||
"NOCOMPRESS", "RENAME", "TABLE", "GRANT", "NOT", "RESOURCE",
|
||||
"TABLES", "GROUP", "NULL", "RETURN", "TASK", "HAVING", "NUMBER",
|
||||
"REVERSE", "TERMINATE", "IDENTIFIED", "NUMBER_BASE", "REVOKE",
|
||||
"THEN", "IF", "OF", "ROLLBACK", "TO", "IN", "ON", "ROWID", "TRUE",
|
||||
"INDEX", "OPEN", "ROWLABEL", "TYPE", "INDEXES", "OPTION",
|
||||
"ROWNUM", "UNION", "INDICATOR", "OR", "ROWTYPE", "UNIQUE",
|
||||
"INSERT", "ORDER", "RUN", "UPDATE", "INTEGER", "OTHERS",
|
||||
"SAVEPOINT", "USE", "INTERSECT", "OUT", "SCHEMA", "VALUES",
|
||||
"INTO", "PACKAGE", "SELECT", "VARCHAR", "IS", "PARTITION",
|
||||
"SEPARATE", "VARCHAR2", "LEVEL", "PCTFREE", "SET", "VARIANCE",
|
||||
"LIKE", "POSITIVE", "SIZE", "VIEW", "LIMITED", "PRAGMA",
|
||||
"SMALLINT", "VIEWS", "LOOP", "PRIOR", "SPACE", "WHEN", "MAX",
|
||||
"PRIVATE", "SQL", "WHERE", "MIN", "PROCEDURE", "SQLCODE", "WHILE",
|
||||
"MINUS", "PUBLIC", "SQLERRM", "WITH", "MLSLABEL", "RAISE",
|
||||
"START", "WORK", "MOD", "RANGE", "STATEMENT", "XOR", "MODE",
|
||||
"REAL", "STDDEV", "NATURAL", "RECORD", "SUBTYPE"
|
||||
]
|
||||
|
||||
oracle_spatial_keywords = []
|
||||
|
||||
# SQL functions
|
||||
# other than math/string/aggregate/date/conversion/xml/data mining
|
||||
functions = [
|
||||
# FROM
|
||||
# https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
|
||||
"CAST", "COALESCE", "DECODE", "GREATEST", "LEAST", "LNNVL",
|
||||
"NULLIF", "NVL", "NVL2", "SET", "UID", "USER", "USERENV"
|
||||
]
|
||||
|
||||
# SQL math functions
|
||||
math_functions = [
|
||||
'ABS', 'ACOS', 'ASIN', 'ATAN', 'ATAN2', 'BITAND', 'CEIL', 'COS',
|
||||
'COSH', 'EXP', 'FLOOR', 'LN', 'LOG', 'MOD', 'NANVL', 'POWER',
|
||||
'REMAINDER', 'ROUND', 'SIGN', 'SIN', 'SINH', 'SQRT', 'TAN',
|
||||
'TANH', 'TRUNC', 'WIDTH_BUCKET'
|
||||
]
|
||||
|
||||
# Strings functions
|
||||
string_functions = [
|
||||
'CHR', 'CONCAT', 'INITCAP', 'LOWER', 'LPAD', 'LTRIM', 'NLS_INITCAP',
|
||||
'NLS_LOWER', 'NLSSORT', 'NLS_UPPER', 'REGEXP_REPLACE', 'REGEXP_SUBSTR',
|
||||
'REPLACE', 'RPAD', 'RTRIM', 'SOUNDEX', 'SUBSTR', 'TRANSLATE', 'TREAT',
|
||||
'TRIM', 'UPPER', 'ASCII', 'INSTR', 'LENGTH', 'REGEXP_INSTR'
|
||||
]
|
||||
|
||||
# Aggregate functions
|
||||
aggregate_functions = [
|
||||
'AVG', 'COLLECT', 'CORR', 'COUNT', 'COVAR_POP', 'COVAR_SAMP', 'CUME_DIST',
|
||||
'DENSE_RANK', 'FIRST', 'GROUP_ID', 'GROUPING', 'GROUPING_ID',
|
||||
'LAST', 'MAX', 'MEDIAN', 'MIN', 'PERCENTILE_CONT',
|
||||
'PERCENTILE_DISC', 'PERCENT_RANK', 'RANK',
|
||||
'STATS_BINOMIAL_TEST', 'STATS_CROSSTAB', 'STATS_F_TEST',
|
||||
'STATS_KS_TEST', 'STATS_MODE', 'STATS_MW_TEST',
|
||||
'STATS_ONE_WAY_ANOVA', 'STATS_WSR_TEST', 'STDDEV',
|
||||
'STDDEV_POP', 'STDDEV_SAMP', 'SUM', 'SYS_XMLAGG', 'VAR_POP',
|
||||
'VAR_SAMP', 'VARIANCE', 'XMLAGG'
|
||||
]
|
||||
|
||||
oracle_spatial_functions = [
|
||||
# From http://docs.oracle.com/cd/B19306_01/appdev.102/b14255/toc.htm
|
||||
# Spatial operators
|
||||
"SDO_ANYINTERACT", "SDO_CONTAINS", "SDO_COVEREDBY", "SDO_COVERS",
|
||||
"SDO_EQUAL", "SDO_FILTER", "SDO_INSIDE", "SDO_JOIN", "SDO_NN",
|
||||
"SDO_NN_DISTANCE", "SDO_ON", "SDO_OVERLAPBDYDISJOINT",
|
||||
"SDO_OVERLAPBDYINTERSECT", "SDO_OVERLAPS", "SDO_RELATE",
|
||||
"SDO_TOUCH", "SDO_WITHIN_DISTANCE",
|
||||
# SPATIAL AGGREGATE FUNCTIONS
|
||||
"SDO_AGGR_CENTROID", "SDO_AGGR_CONCAT_LINES",
|
||||
"SDO_AGGR_CONVEXHULL", "SDO_AGGR_LRS_CONCAT", "SDO_AGGR_MBR",
|
||||
"SDO_AGGR_UNION",
|
||||
# COORDINATE SYSTEM TRANSFORMATION (SDO_CS)
|
||||
"SDO_CS.ADD_PREFERENCE_FOR_OP", "SDO_CS.CONVERT_NADCON_TO_XML",
|
||||
"SDO_CS.CONVERT_NTV2_TO_XML", "SDO_CS.CONVERT_XML_TO_NADCON",
|
||||
"SDO_CS.CONVERT_XML_TO_NTV2", "SDO_CS.CREATE_CONCATENATED_OP",
|
||||
"SDO_CS.CREATE_OBVIOUS_EPSG_RULES",
|
||||
"SDO_CS.CREATE_PREF_CONCATENATED_OP",
|
||||
"SDO_CS.DELETE_ALL_EPSG_RULES", "SDO_CS.DELETE_OP",
|
||||
"SDO_CS.DETERMINE_CHAIN", "SDO_CS.DETERMINE_DEFAULT_CHAIN",
|
||||
"SDO_CS.FIND_GEOG_CRS", "SDO_CS.FIND_PROJ_CRS",
|
||||
"SDO_CS.FROM_OGC_SIMPLEFEATURE_SRS", "SDO_CS.FROM_USNG",
|
||||
"SDO_CS.MAP_EPSG_SRID_TO_ORACLE",
|
||||
"SDO_CS.MAP_ORACLE_SRID_TO_EPSG",
|
||||
"SDO_CS.REVOKE_PREFERENCE_FOR_OP",
|
||||
"SDO_CS.TO_OGC_SIMPLEFEATURE_SRS", "SDO_CS.TO_USNG",
|
||||
"SDO_CS.TRANSFORM", "SDO_CS.TRANSFORM_LAYER",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_ALL_EPSG_CRS",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_EPSG_CRS",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_EPSG_DATUM",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_EPSG_ELLIPS",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_EPSG_OP",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_EPSG_PARAM",
|
||||
"SDO_CS.UPDATE_WKTS_FOR_EPSG_PM", "SDO_CS.VALIDATE_WKT",
|
||||
"SDO_CS.VIEWPORT_TRANSFORM",
|
||||
# GEOCODING (SDO_GCDR)
|
||||
"SDO_GCDR.GEOCODE", "SDO_GCDR.GEOCODE_ADDR",
|
||||
"SDO_GCDR.GEOCODE_ADDR_ALL", "SDO_GCDR.GEOCODE_ALL",
|
||||
"SDO_GCDR.GEOCODE_AS_GEOMETRY", "SDO_GCDR.REVERSE_GEOCODE",
|
||||
# GEOMETRY (SDO_GEOM)
|
||||
"SDO_GEOM.RELATE", "SDO_GEOM.SDO_ARC_DENSIFY",
|
||||
"SDO_GEOM.SDO_AREA", "SDO_GEOM.SDO_BUFFER",
|
||||
"SDO_GEOM.SDO_CENTROID", "SDO_GEOM.SDO_CONVEXHULL",
|
||||
"SDO_GEOM.SDO_DIFFERENCE", "SDO_GEOM.SDO_DISTANCE",
|
||||
"SDO_GEOM.SDO_INTERSECTION", "SDO_GEOM.SDO_LENGTH",
|
||||
"SDO_GEOM.SDO_MAX_MBR_ORDINATE", "SDO_GEOM.SDO_MBR",
|
||||
"SDO_GEOM.SDO_MIN_MBR_ORDINATE", "SDO_GEOM.SDO_POINTONSURFACE",
|
||||
"SDO_GEOM.SDO_UNION", "SDO_GEOM.SDO_XOR",
|
||||
"SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT",
|
||||
"SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT",
|
||||
"SDO_GEOM.WITHIN_DISTANCE",
|
||||
# LINEAR REFERENCING SYSTEM (SDO_LRS)
|
||||
"SDO_LRS.CLIP_GEOM_SEGMENT", "SDO_LRS.CONCATENATE_GEOM_SEGMENTS",
|
||||
"SDO_LRS.CONNECTED_GEOM_SEGMENTS",
|
||||
"SDO_LRS.CONVERT_TO_LRS_DIM_ARRAY", "SDO_LRS.CONVERT_TO_LRS_GEOM",
|
||||
"SDO_LRS.CONVERT_TO_LRS_LAYER",
|
||||
"SDO_LRS.CONVERT_TO_STD_DIM_ARRAY", "SDO_LRS.CONVERT_TO_STD_GEOM",
|
||||
"SDO_LRS.CONVERT_TO_STD_LAYER", "SDO_LRS.DEFINE_GEOM_SEGMENT",
|
||||
"SDO_LRS.DYNAMIC_SEGMENT", "SDO_LRS.FIND_LRS_DIM_POS",
|
||||
"SDO_LRS.FIND_MEASURE", "SDO_LRS.FIND_OFFSET",
|
||||
"SDO_LRS.GEOM_SEGMENT_END_MEASURE", "SDO_LRS.GEOM_SEGMENT_END_PT",
|
||||
"SDO_LRS.GEOM_SEGMENT_LENGTH",
|
||||
"SDO_LRS.GEOM_SEGMENT_START_MEASURE",
|
||||
"SDO_LRS.GEOM_SEGMENT_START_PT", "SDO_LRS.GET_MEASURE",
|
||||
"SDO_LRS.GET_NEXT_SHAPE_PT", "SDO_LRS.GET_NEXT_SHAPE_PT_MEASURE",
|
||||
"SDO_LRS.GET_PREV_SHAPE_PT", "SDO_LRS.GET_PREV_SHAPE_PT_MEASURE",
|
||||
"SDO_LRS.IS_GEOM_SEGMENT_DEFINED",
|
||||
"SDO_LRS.IS_MEASURE_DECREASING", "SDO_LRS.IS_MEASURE_INCREASING",
|
||||
"SDO_LRS.IS_SHAPE_PT_MEASURE", "SDO_LRS.LOCATE_PT",
|
||||
"SDO_LRS.LRS_INTERSECTION", "SDO_LRS.MEASURE_RANGE",
|
||||
"SDO_LRS.MEASURE_TO_PERCENTAGE", "SDO_LRS.OFFSET_GEOM_SEGMENT",
|
||||
"SDO_LRS.PERCENTAGE_TO_MEASURE", "SDO_LRS.PROJECT_PT",
|
||||
"SDO_LRS.REDEFINE_GEOM_SEGMENT", "SDO_LRS.RESET_MEASURE",
|
||||
"SDO_LRS.REVERSE_GEOMETRY", "SDO_LRS.REVERSE_MEASURE",
|
||||
"SDO_LRS.SET_PT_MEASURE", "SDO_LRS.SPLIT_GEOM_SEGMENT",
|
||||
"SDO_LRS.TRANSLATE_MEASURE", "SDO_LRS.VALID_GEOM_SEGMENT",
|
||||
"SDO_LRS.VALID_LRS_PT", "SDO_LRS.VALID_MEASURE",
|
||||
"SDO_LRS.VALIDATE_LRS_GEOMETRY",
|
||||
# SDO_MIGRATE
|
||||
"SDO_MIGRATE.TO_CURRENT",
|
||||
# SPATIAL ANALYSIS AND MINING (SDO_SAM)
|
||||
"SDO_SAM.AGGREGATES_FOR_GEOMETRY", "SDO_SAM.AGGREGATES_FOR_LAYER",
|
||||
"SDO_SAM.BIN_GEOMETRY", "SDO_SAM.BIN_LAYER",
|
||||
"SDO_SAM.COLOCATED_REFERENCE_FEATURES",
|
||||
"SDO_SAM.SIMPLIFY_GEOMETRY", "SDO_SAM.SIMPLIFY_LAYER",
|
||||
"SDO_SAM.SPATIAL_CLUSTERS", "SDO_SAM.TILED_AGGREGATES",
|
||||
"SDO_SAM.TILED_BINS",
|
||||
# TUNING (SDO_TUNE)
|
||||
"SDO_TUNE.AVERAGE_MBR", "SDO_TUNE.ESTIMATE_RTREE_INDEX_SIZE",
|
||||
"SDO_TUNE.EXTENT_OF", "SDO_TUNE.MIX_INFO",
|
||||
"SDO_TUNE.QUALITY_DEGRADATION",
|
||||
# UTILITY (SDO_UTIL)
|
||||
"SDO_UTIL.APPEND", "SDO_UTIL.CIRCLE_POLYGON",
|
||||
"SDO_UTIL.CONCAT_LINES", "SDO_UTIL.CONVERT_UNIT",
|
||||
"SDO_UTIL.ELLIPSE_POLYGON", "SDO_UTIL.EXTRACT",
|
||||
"SDO_UTIL.FROM_WKBGEOMETRY", "SDO_UTIL.FROM_WKTGEOMETRY",
|
||||
"SDO_UTIL.GETNUMELEM", "SDO_UTIL.GETNUMVERTICES",
|
||||
"SDO_UTIL.GETVERTICES", "SDO_UTIL.INITIALIZE_INDEXES_FOR_TTS",
|
||||
"SDO_UTIL.POINT_AT_BEARING", "SDO_UTIL.POLYGONTOLINE",
|
||||
"SDO_UTIL.PREPARE_FOR_TTS", "SDO_UTIL.RECTIFY_GEOMETRY",
|
||||
"SDO_UTIL.REMOVE_DUPLICATE_VERTICES",
|
||||
"SDO_UTIL.REVERSE_LINESTRING", "SDO_UTIL.SIMPLIFY",
|
||||
"SDO_UTIL.TO_GMLGEOMETRY", "SDO_UTIL.TO_WKBGEOMETRY",
|
||||
"SDO_UTIL.TO_WKTGEOMETRY", "SDO_UTIL.VALIDATE_WKBGEOMETRY",
|
||||
"SDO_UTIL.VALIDATE_WKTGEOMETRY"
|
||||
]
|
||||
|
||||
# Oracle Operators
|
||||
operators = [
|
||||
' AND ', ' OR ', '||', ' < ', ' <= ', ' > ', ' >= ', ' = ',
|
||||
' <> ', '!=', '^=', ' IS ', ' IS NOT ', ' IN ', ' ANY ', ' SOME ',
|
||||
' NOT IN ', ' LIKE ', ' GLOB ', ' MATCH ', ' REGEXP ',
|
||||
' BETWEEN x AND y ', ' NOT BETWEEN x AND y ', ' EXISTS ',
|
||||
' IS NULL ', ' IS NOT NULL', ' ALL ', ' NOT ',
|
||||
' CASE {column} WHEN {value} THEN {value} '
|
||||
]
|
||||
|
||||
|
||||
# constants
|
||||
constants = ["null", "false", "true"]
|
||||
oracle_spatial_constants = []
|
||||
|
||||
|
||||
def getSqlDictionary(spatial=True):
|
||||
k, c, f = list(keywords), list(constants), list(functions)
|
||||
|
||||
if spatial:
|
||||
k += oracle_spatial_keywords
|
||||
f += oracle_spatial_functions
|
||||
c += oracle_spatial_constants
|
||||
|
||||
return {'keyword': k, 'constant': c, 'function': f}
|
||||
|
||||
|
||||
def getQueryBuilderDictionary():
|
||||
# concat functions
|
||||
def ff(l):
|
||||
return filter(lambda s: s[0] != '*', l)
|
||||
|
||||
def add_paren(l):
|
||||
return map(lambda s: s + "(", l)
|
||||
|
||||
foo = sorted(
|
||||
add_paren(
|
||||
ff(
|
||||
list(
|
||||
set.union(set(functions),
|
||||
set(oracle_spatial_functions))))))
|
||||
m = sorted(add_paren(ff(math_functions)))
|
||||
agg = sorted(add_paren(ff(aggregate_functions)))
|
||||
op = ff(operators)
|
||||
s = sorted(add_paren(ff(string_functions)))
|
||||
return {'function': foo, 'math': m, 'aggregate': agg,
|
||||
'operator': op, 'string': s}
|
Loading…
x
Reference in New Issue
Block a user