Subject: Marine Geospatial Ecology Tools (MGET) help
Text archives
From: | "Jason Roberts" <> |
---|---|
To: | <> |
Cc: | <> |
Subject: | RE: [mget-help] error using Calculate Species Diversity Index for Polygons |
Date: | Thu, 17 Feb 2011 07:27:40 -0500 |
Hi,
Thanks for your interest in MGET and for contacting us about this. I'm sorry
you're seeing this problem and should be able to help you fix it.
I could not reproduce the error, but I believe I know where it is coming
from. There is some code that checks that the input points
(C:\test\test_indexos\Artesanals.shp, in this case) and species field
(Especie) both exist. I believe that code determined that one or the other
does not exist and tried to report the problem. But there is a bug in the
code that reports the message, so "global name 'table' is not defined” is
reported instead, which is not particularly useful.
So we have two problems to investigate:
1. What is the real error message.
2. Why is that error happening?
To address the first problem, I fixed the bug in the reporting code. You can
patch your MGET installation like this:
1. Shut down all ArcGIS programs.
2. Save the attached file to
C:\Python25\Lib\site-packages\GeoEco\DatabaseAccess\InMemory.py (for Arc
9.3.1) or
C:\Python26\ArcGIS10.0\Lib\site-packages\GeoEco\DatabaseAccess\InMemory.py
(for Arc 10).
3. Restart Arc and try the tool again.
Hopefully you will get a more helpful message. If it says that a table or
field does not exist, please check on that. If that is not the problem, let
me know and we'll investigate further.
Best regards,
Jason
-----Original Message-----
From:
[mailto:]
Sent: Thursday, February 17, 2011 5:58 AM
To:
Subject: [mget-help] error using Calculate Species Diversity Index for
Polygons
Hi,
I'm new to the list. First of all, thanks for this toolset. It´s amazingly
useful.
We are trying to use Calculate Species Diversity Index for Polygons. We
succeeded using it when we didn't use Species Count Field (which is optional).
But when we populates it, it shows up the error bellow.
For + info, we tried it in ArcGis 9.3.1 and arcgis 10. Same error.
Any idea or hint? Thank you
Executing: SpeciesDiversityCalculateDiversityIndexForArcGISPolygons
C:\test\test_indexos\Quadricula_1_1_Poly.shp "Shannon index" SHANNON
C:\test\test_indexos\Artesanals.shp Especie DATO1 # #
Start Time: Thu Feb 17 11:35:23 2011
Running script SpeciesDiversityCalculateDiversityIndexForArcGISPolygons...
The R vegan package is not installed. Downloading and installing the latest
version...
Warning: package 'vegan' was built under R version 2.6.2
Intersecting the points with the polygons.
Summing species counts per polygon.
Reading species counts into memory.
NameError: global name 'table' is not defined
<type 'exceptions.NameError'>: global name 'table' is not defined
Failed to execute (SpeciesDiversityCalculateDiversityIndexForArcGISPolygons).
Failed at Thu Feb 17 11:36:06 2011 (Elapsed Time: 43,00 seconds)
# DatabaseAccess/InMemory.py - Classes that implement the GeoEco database
access
# API for an in memory database based on Python lists.
#
# Copyright (C) 2007 Jason J. Roberts
#
# 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 (available in the file LICENSE.TXT)
# 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.
import datetime
import types
from GeoEco.DatabaseAccess import DatabaseConnection, SelectCursor,
InsertCursor, UpdateCursor
from GeoEco.DynamicDocString import DynamicDocString
from GeoEco.Internationalization import _
from GeoEco.Logging import Logger
# Private classes used only within this module
class _TableDef(object):
def __init__(self, name):
self.Name = name
self.Fields = {}
class _FieldDef(object):
def __init__(self, name, dataType, isNullable):
self.Name = name
self.DataType = dataType
self.IsNullable = isNullable is None or isNullable
# Classes exported by this module
class InMemoryDatabaseConnection(DatabaseConnection):
__doc__ = DynamicDocString()
def __init__(self):
self._TableDefs = {}
self._TableData = {}
def _GetGetRowCountSupported(self):
return True
def _GetCreateTableSupported(self):
return True
def _GetDeleteTableSupported(self):
return True
def _GetTemplatesSupported(self):
return True
def _GetAddFieldSupported(self):
return True
def _GetDeleteFieldSupported(self):
return True
def _GetFieldLengthSupported(self):
return False
def _GetFieldPrecisionSupported(self):
return False
def _GetFieldScaleSupported(self):
return False
def _GetFieldAliasSupported(self):
return False
def _GetFieldIsRequiredSupported(self):
return False
def _GetFieldDomainSupported(self):
return False
def _GetSelectCursorSupported(self):
return True
def _GetInsertCursorSupported(self):
return True
def _GetUpdateCursorSupported(self):
return True
def _GetSelectCursorClass(self):
return InMemorySelectCursor
def _GetInsertCursorClass(self):
return InMemoryInsertCursor
def _GetUpdateCursorClass(self):
return InMemoryUpdateCursor
def _GetFieldsSupported(self):
return False
def _GetWhereSupported(self):
return False
def _GetOrderBySupported(self):
return True
def _GetSpatialReferenceSupported(self):
return False
GetRowCountSupported = property(_GetGetRowCountSupported,
doc=DynamicDocString())
CreateTableSupported = property(_GetCreateTableSupported,
doc=DynamicDocString())
DeleteTableSupported = property(_GetDeleteTableSupported,
doc=DynamicDocString())
TemplatesSupported = property(_GetTemplatesSupported,
doc=DynamicDocString())
AddFieldSupported = property(_GetAddFieldSupported,
doc=DynamicDocString())
DeleteFieldSupported = property(_GetDeleteFieldSupported,
doc=DynamicDocString())
FieldLengthSupported = property(_GetFieldLengthSupported,
doc=DynamicDocString())
FieldPrecisionSupported = property(_GetFieldPrecisionSupported,
doc=DynamicDocString())
FieldScaleSupported = property(_GetFieldScaleSupported,
doc=DynamicDocString())
FieldAliasSupported = property(_GetFieldAliasSupported,
doc=DynamicDocString())
FieldIsRequiredSupported = property(_GetFieldIsRequiredSupported,
doc=DynamicDocString())
FieldDomainSupported = property(_GetFieldDomainSupported,
doc=DynamicDocString())
SelectCursorSupported = property(_GetSelectCursorSupported,
doc=DynamicDocString())
InsertCursorSupported = property(_GetInsertCursorSupported,
doc=DynamicDocString())
UpdateCursorSupported = property(_GetUpdateCursorSupported,
doc=DynamicDocString())
SelectCursorClass = property(_GetSelectCursorClass,
doc=DynamicDocString())
InsertCursorClass = property(_GetInsertCursorClass,
doc=DynamicDocString())
UpdateCursorClass = property(_GetUpdateCursorClass,
doc=DynamicDocString())
FieldsSupported = property(_GetFieldsSupported, doc=DynamicDocString())
WhereSupported = property(_GetWhereSupported, doc=DynamicDocString())
OrderBySupported = property(_GetOrderBySupported, doc=DynamicDocString())
SpatialReferenceSupported = property(_GetSpatialReferenceSupported,
doc=DynamicDocString())
def _TableExists(self, table):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return self._TableDefs.has_key(table)
def _GetRowCount(self, table):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
if len(self._TableDefs[table].Fields) <= 0:
return 0
return len(self._TableData[table][self._TableData[table].keys()[0]])
def _CreateTable(self, table, templates=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._TableDefs[table] = _TableDef(table)
self._TableData[table] = {}
return table
def _DeleteTable(self, table):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
del self._TableDefs[table]
del self._TableData[table]
def _FieldExists(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return self._TableDefs.has_key(table) and
self._TableDefs[table].Fields.has_key(field)
def _FieldIsNullable(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return True
def _FieldDataTypeIsSupported(self, dataType):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return True
def _AddField(self, table, field, dataType, isNullable=None, length=None,
precision=None, scale=None, alias=None, isRequired=False, domain=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
rowCount = self._GetRowCount(table)
if rowCount > 0 and isNullable is not None and not isNullable:
Logger.RaiseException(ValueError(_(u'Cannot add field %(field)s
to table %(table)s because the table is not empty. Fields can only be added
to non-empty tables if isNullable is False.') % {u'field': field, u'table':
table}))
self._TableDefs[table].Fields[field] = _FieldDef(field, dataType,
isNullable)
self._TableData[table][field] = [None] * rowCount
return field
def _DeleteField(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
del self._TableDefs[table].Fields[field]
del self._TableData[table][field]
def _ValidateFieldValue(self, table, field, value):
fieldDef = self._TableDefs[table].Fields[field]
if fieldDef is None:
Logger.RaiseException(ValueError(_(u'Cannot set the value of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': table}))
if value is None:
if not fieldDef.IsNullable:
Logger.RaiseException(ValueError(_(u'Cannot set the value of
field %(field)s of table %(table)s to None because setting this field to None
is not allowed (IsNullable is False).') % {u'field': field, u'table': table}))
return None
return value
def _GetOrderedIndices(self, table, orderBy, directions):
# If the caller did not specify any orderBy fields, just return a list
# of row indices ranging from 0 to the row count - 1.
indices = range(self._GetRowCount(table))
if orderBy is None:
return indices
# Build a temporary comparison function that we can pass to Python's
# built-in sort function.
globalTablePointer = '_Table' + str(id(indices))
globals()[globalTablePointer] = self._TableData[table]
try:
sourceCode = 'def compare(x,y):\n'
sourceCode += ' table = globals()[\'' + globalTablePointer +
'\']\n'
for i in range(len(orderBy)):
dataType =
self._TableDefs[table].Fields[orderBy[i]].DataType.lower()
isString = False
if dataType == u'str' or dataType == u'unicode' or dataType
== u'string' or dataType == u'basestring':
isString = True
sourceCode += ' if table[\'' + str(orderBy[i]) + '\'][y]
is not None and (table[\'' + str(orderBy[i]) + '\'][x] is None or
isinstance(table[\'' + str(orderBy[i]) + '\'][x], basestring) and
isinstance(table[\'' + str(orderBy[i]) + '\'][y], basestring) and table[\'' +
str(orderBy[i]) + '\'][x].lower() < table[\'' + str(orderBy[i]) +
'\'][y].lower() or not (isinstance(table[\'' + str(orderBy[i]) + '\'][x],
basestring) and isinstance(table[\'' + str(orderBy[i]) + '\'][y],
basestring)) and table[\'' + str(orderBy[i]) + '\'][x] < table[\'' +
str(orderBy[i]) + '\'][y]):\n'
if directions[i] == u'Ascending':
sourceCode += ' return -1\n'
else:
sourceCode += ' return 1\n'
sourceCode += ' if table[\'' + str(orderBy[i]) + '\'][x]
is not None and (table[\'' + str(orderBy[i]) + '\'][y] is None or
isinstance(table[\'' + str(orderBy[i]) + '\'][x], basestring) and
isinstance(table[\'' + str(orderBy[i]) + '\'][y], basestring) and table[\'' +
str(orderBy[i]) + '\'][x].lower() > table[\'' + str(orderBy[i]) +
'\'][y].lower() or not (isinstance(table[\'' + str(orderBy[i]) + '\'][x],
basestring) and isinstance(table[\'' + str(orderBy[i]) + '\'][y],
basestring)) and table[\'' + str(orderBy[i]) + '\'][x] > table[\'' +
str(orderBy[i]) + '\'][y]):\n'
if directions[i] == u'Ascending':
sourceCode += ' return 1\n'
else:
sourceCode += ' return -1\n'
sourceCode += ' return 0\n'
exec sourceCode in globals(), locals()
indices.sort(cmp=compare)
finally:
del globals()[globalTablePointer]
# Return the sorted indices.
return indices
def GetFieldValues(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
if not self._TableData.has_key(table):
Logger.RaiseException(ValueError(_(u'Cannot get the values of
field %(field)s of table %(table)s because the table does not exist.') %
{u'field': field, u'table': table}))
if not self._TableData[table].has_key(field):
Logger.RaiseException(ValueError(_(u'Cannot get the values of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': table}))
values = self._TableData[table][field]
from repr import repr
self._LogDebug(_(u'%(conntype)s 0x%(connid)08X: GetFieldValues for
%(field)s of table %(table)s returned %(values)s') % {u'conntype':
self.__class__.__name__, u'connid': id(self), u'field': repr(field),
u'table': repr(table), u'values': repr(values)})
return values
def ImportTable(self, sourceConnection, sourceTable, destTable, fields,
where=None, orderBy=None, directions=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
if not sourceConnection.TableExists(sourceTable):
Logger.RaiseException(ValueError(_(u'Cannot import table
%(table)s into memory because the table does not exist.') % {u'table':
sourceTable}))
for field in fields:
if not sourceConnection.FieldExists(sourceTable, field):
Logger.RaiseException(ValueError(_(u'Cannot import field
%(field)s of table %(table)s into memory because the field does not exist in
the table.') % {u'field': field, u'table': sourceTable}))
if self._TableData.has_key(destTable):
Logger.RaiseException(ValueError(_(u'Cannot import table %(src)s
into in-memory table %(dest)s because that in-memory table already exists.')
% {u'src': sourceTable, u'dest': destTable}))
# Create the destination table and fields. Note that the field
# data type does not matter for in-memory tables.
self.CreateTable(destTable)
for field in fields:
self.AddField(destTable, field, u'object', True)
# Copy the rows from the source table to the destination table.
if sourceConnection.FieldsSupported:
sourceCursor = sourceConnection.OpenSelectCursor(sourceTable,
fields=fields, where=where, orderBy=orderBy, directions=directions)
else:
sourceCursor = sourceConnection.OpenSelectCursor(sourceTable,
where=where, orderBy=orderBy, directions=directions)
try:
destCursor = InMemoryInsertCursor()
from GeoEco.Logging import ProgressReporter
destCursor._ProgressReporter = ProgressReporter(None, None, None,
None, None)
destCursor.Open(self, destTable)
try:
while sourceCursor.NextRow():
for field in fields:
destCursor.SetValue(field,
sourceCursor.GetValue(field))
destCursor.InsertRow()
finally:
del destCursor
finally:
del sourceCursor
class InMemorySelectCursor(SelectCursor):
__doc__ = DynamicDocString()
def __init__(self, connection=None, table=None, fields=None, where=None,
orderBy=None, directions=None, spatialReference=None, rowCount=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = None
super(InMemorySelectCursor, self).__init__(connection, table, fields,
where, orderBy, directions, spatialReference, rowCount)
def _Open(self, connection, table, fields, where, orderBy, directions,
spatialReference):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = connection._GetOrderedIndices(table, orderBy,
directions)
def _Close(self):
pass
def _NextRow(self):
return len(self._RowIndices) > 0 and (self.RowIndex is None or
self.RowIndex + 1 < len(self._RowIndices))
def _GetValue(self, field):
if not self.Connection._TableData[self.Table].has_key(field):
Logger.RaiseException(ValueError(_(u'Cannot get the value of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': self.Table}))
return
self.Connection._TableData[self.Table][field][self._RowIndices[self.RowIndex]]
class InMemoryInsertCursor(InsertCursor):
__doc__ = DynamicDocString()
def __init__(self, connection=None, table=None, spatialReference=None,
rowCount=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._Row = {}
super(InMemoryInsertCursor, self).__init__(connection, table,
spatialReference, rowCount)
def _Open(self, connection, table, spatialReference):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
def _Close(self):
pass
def _SetValue(self, field, value):
self._Row[field] = self.Connection._ValidateFieldValue(self.Table,
field, value)
def _InsertRow(self):
# First set all uninitialized fields to None.
fieldDefs = self.Connection._TableDefs[self.Table].Fields
for (field, d) in fieldDefs.items():
if not self._Row.has_key(field):
if not d.IsNullable:
Logger.RaiseException(ValueError(_(u'Cannot insert this
row into table %(table)s because a value must be provided for field
%(field)s. Setting this field to None is not allowed (IsNullable is False).')
% {u'field': field, u'table': self.Table}))
self._Row[field] = None
# Insert the row.
fieldData = self.Connection._TableData[self.Table]
for (field, value) in self._Row.items():
fieldData[field].append(value)
self._Row = {}
class InMemoryUpdateCursor(UpdateCursor):
__doc__ = DynamicDocString()
def __init__(self, connection=None, table=None, fields=None, where=None,
orderBy=None, directions=None, spatialReference=None, rowCount=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = None
self._Row = {}
self._DeletedRowCount = 0
super(InMemoryUpdateCursor, self).__init__(connection, table, fields,
where, orderBy, directions, spatialReference, rowCount)
def _Open(self, connection, table, fields, where, orderBy, directions,
spatialReference):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = connection._GetOrderedIndices(table, orderBy,
directions)
def _Close(self):
pass
def _NextRow(self):
self._Row = {}
return len(self._RowIndices) > 0 and (self.RowIndex is None or
self.RowIndex + 1 < len(self._RowIndices))
def _GetValue(self, field):
if not self.Connection._TableData[self.Table].has_key(field):
Logger.RaiseException(ValueError(_(u'Cannot get the value of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': self.Table}))
if self._Row.has_key(field):
return self._Row[field]
return
self.Connection._TableData[self.Table][field][self._RowIndices[self.RowIndex]
- self._DeletedRowCount]
def _SetValue(self, field, value):
self._Row[field] = self.Connection._ValidateFieldValue(self.Table,
field, value)
def _UpdateRow(self):
fieldData = self.Connection._TableData[self.Table]
for (field, value) in self._Row.items():
fieldData[field][self._RowIndices[self.RowIndex] -
self._DeletedRowCount] = value
def _DeleteRow(self):
fieldData = self.Connection._TableData[self.Table]
for field in fieldData.keys():
del fieldData[field][self._RowIndices[self.RowIndex] -
self._DeletedRowCount]
self._DeletedRowCount += 1
###############################################################################
# Metadata: module
###############################################################################
from GeoEco.Metadata import *
from GeoEco.Types import *
AddModuleMetadata(shortDescription=_(u'Classes for manipulating data in a
simple in-memory database.'))
###############################################################################
# Metadata: InMemoryDatabaseConnection class
###############################################################################
AddClassMetadata(InMemoryDatabaseConnection,
shortDescription=_(u'Represents a connection to an in-memory database.'),
longDescription=_(
u"""When this class is instantiated, it allocates an empty in-memory
database. The database can hold any number of tables of any size,
limited only by available memory. The memory is freed when all cursors
are closed and all instances to the connection object are released.
The database itself is implemented as a dictionary of dictionaries of
lists. The keys of the top-level dictionary are table names, and the
second-level keys are field names. The lists contain the actual data.
All of the lists for a given table are the same length. Table and
field names are case-insensitive. Internally, this class stores the
names in lowercase.
The database only supports a few of the options of more sophisticated
database systems, notably:
* You must assign each field a data type and decide whether the field
can contain NULL values (represented by None in Python, and null or
empty in other languages). The database enforces these constraints.
* The select and update cursors support the orderBy and direction
parameters so you can walk through the rows in a sorted order.
The database is not thread safe and does not implement locking of any
kind. Multithreaded access is not recommended, and you must be careful
to understand the internal implementation if you ever want to open
multiple cursors against the same table, or modify tables that have
open cursors, etc."""))
# Constructor
AddMethodMetadata(InMemoryDatabaseConnection.__init__,
shortDescription=_(u'Constructs a new %s instance.') %
InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection),
description=_(u'%s instance.') % InMemoryDatabaseConnection.__name__)
AddResultMetadata(InMemoryDatabaseConnection.__init__, u'conn',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection),
description=_(u'New %s instance.') % InMemoryDatabaseConnection.__name__)
# Properties
AddPropertyMetadata(InMemoryDatabaseConnection.GetRowCountSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
getting the row counts of tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.CreateTableSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
creating tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.DeleteTableSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
deleting tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.TemplatesSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the templates parameter for creating tables.'),
longDescription=_(u'CreateTable will fail if you supply a value for the
templates parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.AddFieldSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports adding
fields to tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.DeleteFieldSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
deleting fields from tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldLengthSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the length parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
length parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldPrecisionSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the precision parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
precision parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldScaleSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the scale parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
precision parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldAliasSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the alias parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
alias parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldIsRequiredSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the isRequired parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
isRequired parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldDomainSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the domain parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
domain parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.SelectCursorSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports select
cursors for reading rows from tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.InsertCursorSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports insert
cursors for appending rows to tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.UpdateCursorSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports update
cursors for changing the values of fields of existing table rows.'))
AddPropertyMetadata(InMemoryDatabaseConnection.SelectCursorClass,
typeMetadata=ClassTypeMetadata(cls=InMemorySelectCursor),
shortDescription=_(u'Returns %s.') % InMemorySelectCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.InsertCursorClass,
typeMetadata=ClassTypeMetadata(cls=InMemoryInsertCursor),
shortDescription=_(u'Returns %s.') % InMemoryInsertCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.UpdateCursorClass,
typeMetadata=ClassTypeMetadata(cls=InMemoryUpdateCursor),
shortDescription=_(u'Returns %s.') % InMemoryUpdateCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.FieldsSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the fields parameter for select cursors.'),
longDescription=_(u'%s will fail if you supply a value for the fields
parameter.') % InMemorySelectCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.WhereSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the where parameter for select and update cursors.'),
longDescription=_(u'%s and %s will fail if you supply a value for the
where parameter.') % (InMemorySelectCursor.__name__,
InMemoryUpdateCursor.__name__))
AddPropertyMetadata(InMemoryDatabaseConnection.OrderBySupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports the
orderBy and directions parameters of select and update cursors.'))
AddPropertyMetadata(InMemoryDatabaseConnection.SpatialReferenceSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the spatialReference parameter for cursors.'),
longDescription=_(u'The cursor classes will fail if you supply a value
for the spatialReference parameter.'))
# Private method: _TableExists
AddMethodMetadata(InMemoryDatabaseConnection._TableExists,
shortDescription=_(u'Tests the existence of a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call TableExists instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._TableExists, u'self')
CopyArgumentMetadata(DatabaseConnection.TableExists, u'table',
InMemoryDatabaseConnection._TableExists, u'table')
CopyResultMetadata(DatabaseConnection.TableExists, u'exists',
InMemoryDatabaseConnection._TableExists, u'exists')
# Private method: _GetRowCount
AddMethodMetadata(InMemoryDatabaseConnection._GetRowCount,
shortDescription=_(u'Gets the number of rows in a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call GetRowCount instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._GetRowCount, u'self')
CopyArgumentMetadata(DatabaseConnection.GetRowCount, u'table',
InMemoryDatabaseConnection._GetRowCount, u'table')
CopyResultMetadata(DatabaseConnection.GetRowCount, u'rowCount',
InMemoryDatabaseConnection._GetRowCount, u'rowCount')
# Private method: _CreateTable
AddMethodMetadata(InMemoryDatabaseConnection._CreateTable,
shortDescription=_(u'Creates a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call CreateTable instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._CreateTable, u'self')
CopyArgumentMetadata(DatabaseConnection.CreateTable, u'table',
InMemoryDatabaseConnection._CreateTable, u'table')
CopyArgumentMetadata(DatabaseConnection.CreateTable, u'templates',
InMemoryDatabaseConnection._CreateTable, u'templates')
CopyResultMetadata(DatabaseConnection.CreateTable, u'createdTable',
InMemoryDatabaseConnection._CreateTable, u'createdTable')
# Private method: _DeleteTable
AddMethodMetadata(InMemoryDatabaseConnection._DeleteTable,
shortDescription=_(u'Deletes a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call DeleteTable instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._DeleteTable, u'self')
CopyArgumentMetadata(DatabaseConnection.DeleteTable, u'table',
InMemoryDatabaseConnection._DeleteTable, u'table')
# Private method: _FieldExists
AddMethodMetadata(InMemoryDatabaseConnection._FieldExists,
shortDescription=_(u'Tests the existence of a field.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call FieldExists instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._FieldExists, u'self')
CopyArgumentMetadata(DatabaseConnection.FieldExists, u'table',
InMemoryDatabaseConnection._FieldExists, u'table')
CopyArgumentMetadata(DatabaseConnection.FieldExists, u'field',
InMemoryDatabaseConnection._FieldExists, u'field')
CopyResultMetadata(DatabaseConnection.FieldExists, u'exists',
InMemoryDatabaseConnection._FieldExists, u'exists')
# Private method: _FieldIsNullable
AddMethodMetadata(InMemoryDatabaseConnection._FieldIsNullable,
shortDescription=_(u'Tests the nullability of a field.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call FieldIsNullable instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._FieldIsNullable, u'self')
CopyArgumentMetadata(DatabaseConnection.FieldIsNullable, u'table',
InMemoryDatabaseConnection._FieldIsNullable, u'table')
CopyArgumentMetadata(DatabaseConnection.FieldIsNullable, u'field',
InMemoryDatabaseConnection._FieldIsNullable, u'field')
CopyResultMetadata(DatabaseConnection.FieldIsNullable, u'isNullable',
InMemoryDatabaseConnection._FieldIsNullable, u'isNullable')
# Private method: _FieldDataTypeIsSupported
AddMethodMetadata(InMemoryDatabaseConnection._FieldDataTypeIsSupported,
shortDescription=_(u'Tests whether a data type is supported.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call FieldDataTypeIsSupported instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._FieldDataTypeIsSupported, u'self')
CopyArgumentMetadata(DatabaseConnection.FieldDataTypeIsSupported,
u'dataType', InMemoryDatabaseConnection._FieldDataTypeIsSupported,
u'dataType')
CopyResultMetadata(DatabaseConnection.FieldDataTypeIsSupported,
u'isSupported', InMemoryDatabaseConnection._FieldDataTypeIsSupported,
u'isSupported')
# Private derived class method: _AddField
AddMethodMetadata(InMemoryDatabaseConnection._AddField,
shortDescription=_(u'Adds a field to a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call AddField instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._AddField, u'self')
CopyArgumentMetadata(DatabaseConnection.AddField, u'table',
InMemoryDatabaseConnection._AddField, u'table')
CopyArgumentMetadata(DatabaseConnection.AddField, u'field',
InMemoryDatabaseConnection._AddField, u'field')
CopyArgumentMetadata(DatabaseConnection.AddField, u'dataType',
InMemoryDatabaseConnection._AddField, u'dataType')
CopyArgumentMetadata(DatabaseConnection.AddField, u'isNullable',
InMemoryDatabaseConnection._AddField, u'isNullable')
CopyArgumentMetadata(DatabaseConnection.AddField, u'length',
InMemoryDatabaseConnection._AddField, u'length')
CopyArgumentMetadata(DatabaseConnection.AddField, u'precision',
InMemoryDatabaseConnection._AddField, u'precision')
CopyArgumentMetadata(DatabaseConnection.AddField, u'scale',
InMemoryDatabaseConnection._AddField, u'scale')
CopyArgumentMetadata(DatabaseConnection.AddField, u'alias',
InMemoryDatabaseConnection._AddField, u'alias')
CopyArgumentMetadata(DatabaseConnection.AddField, u'isRequired',
InMemoryDatabaseConnection._AddField, u'isRequired')
CopyArgumentMetadata(DatabaseConnection.AddField, u'domain',
InMemoryDatabaseConnection._AddField, u'domain')
CopyResultMetadata(DatabaseConnection.AddField, u'createdField',
InMemoryDatabaseConnection._AddField, u'createdField')
# Private derived class method: _DeleteField
AddMethodMetadata(InMemoryDatabaseConnection._DeleteField,
shortDescription=_(u'Deletes a field from a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call DeleteField instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._DeleteField, u'self')
CopyArgumentMetadata(DatabaseConnection.DeleteField, u'table',
InMemoryDatabaseConnection._DeleteField, u'table')
CopyArgumentMetadata(DatabaseConnection.DeleteField, u'field',
InMemoryDatabaseConnection._DeleteField, u'field')
# Public derived class method: GetFieldValues
AddMethodMetadata(InMemoryDatabaseConnection.GetFieldValues,
shortDescription=_(u'Gets the values of a field of a table as a Python
list.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection.GetFieldValues, u'self')
AddArgumentMetadata(InMemoryDatabaseConnection.GetFieldValues, u'table',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Table containing the field.'))
AddArgumentMetadata(InMemoryDatabaseConnection.GetFieldValues, u'field',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Field to retrieve.'))
AddResultMetadata(InMemoryDatabaseConnection.GetFieldValues, u'values',
typeMetadata=ListTypeMetadata(elementType=AnyObjectTypeMetadata(canBeNone=True)),
description=_(
u"""Values of the field as a list. The values are guaranteed to be in
the order that the rows were inserted into the table (first in, first
out).
The returned list is a reference to list held internally by the
InMemoryDatabaseConnection. The returned list is intended to be
read-only; modifying it directly modifies the underlying table. If you
add or remove items from it without making the same changes to the
other lists of the table, the underlying table will be corrupt and you
may receive unexpected errors later in your program."""))
# Public derived class method: ImportTable
AddMethodMetadata(InMemoryDatabaseConnection.ImportTable,
shortDescription=_(u'Imports a table from another connection into an
in-memory table of this connection.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection.ImportTable, u'self')
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable,
u'sourceConnection',
typeMetadata=ClassInstanceTypeMetadata(cls=DatabaseConnection),
description=_(u'%s instance containing the table to import.') %
DatabaseConnection.__name__)
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'sourceTable',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Table to import.'))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'destTable',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Name of the destination table to be created in this %s
instance. The table must not already exist.') %
InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'fields',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(),
minLength=1),
description=_(u'List of fields to import. You must specify at least one
field.'))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'where',
typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
description=_(
u"""SQL WHERE clause expression that specifies the subset of rows to
import from the source table. If this parameter is not provided, all
of the rows will be imported. If this parameter is provided but the
source table does not support WHERE clauses, an error will be raised.
The exact syntax of this expression depends on the database containing
the source table and the type of connection used to access it. If you
are using the ArcGIS geoprocessor to access the database, ESRI
recommends you reference fields using the following syntax:
* If you're querying ArcInfo coverages, shapefiles, INFO tables or
dBASE tables (.dbf files), enclose field names in double quotes in
the SQL expression: "MY_FIELD".
* If you're querying Microsoft Access tables or personal
geodatabase tables, enclose field names in square brackets:
[MY_FIELD].
* If you're querying ArcSDE geodatabase tables, an ArcIMS feature
class, or an ArcIMS image service sublayer, don't enclose field
names: MY_FIELD.
"""))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'orderBy',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(),
canBeNone=True),
description=_(
u"""Fields that will be used to sort the rows of the source table
before they are imported into the destination table (i.e., the columns
specified in the ORDER BY clause of a SQL SELECT statement). If no
fields are provided, the rows will be sorted in the default order
determined by the underlying database. If this parameter is provided
but the underlying database does not support ORDER BY clauses, an
error will be raised.
In addition to specifying the ORDER BY fields, you must also specify
the sort direction for each field."""))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'directions',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(allowedValues=[u'Ascending',
u'Descending']), canBeNone=True),
description=_(
u"""List of strings, either 'Ascending' or 'Descending', that specify
the sort directions for the ORDER BY fields. If this parameter is
provided but the underlying database does not support ORDER BY
clauses, an error will be raised."""))
###############################################################################
# Metadata: InMemorySelectCursor class
###############################################################################
AddClassMetadata(InMemorySelectCursor,
shortDescription=_(u'Represents a cursor used to read rows from a table
stored in an in-memory database.'),
longDescription=_(
u"""This class is not intended to be instantiated directly. Call
OpenSelectCursor on the database connection object to obtain an
instance."""))
# Constructor
AddMethodMetadata(InMemorySelectCursor.__init__,
shortDescription=_(u'Constructs a new %s instance and, optionally, opens
it.') % InMemorySelectCursor.__name__,
longDescription=InMemorySelectCursor.__doc__.Obj.LongDescription)
AddArgumentMetadata(InMemorySelectCursor.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemorySelectCursor),
description=_(u'%s instance.') % InMemorySelectCursor.__name__)
AddArgumentMetadata(InMemorySelectCursor.__init__, u'connection',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection,
canBeNone=True),
description=_(u'%s instance.') % InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemorySelectCursor.__init__, u'table',
typeMetadata=UnicodeStringTypeMetadata(minLength=1, canBeNone=True),
description=_(
u"""Database table to access. If this parameter is provided, the
connection parameter must also be provided, and the cursor will be
opened immediately."""))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'fields',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(),
canBeNone=True),
description=_(u'This parameter is not supported. Do not provide a value
for it.'))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'where',
typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
description=_(u'This parameter is not supported. Do not provide a value
for it.'))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'orderBy',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(minLength=1),
canBeNone=True),
description=_(
u"""List of fields that will be used to sort the returned rows (i.e.,
the list of columns specified in the ORDER BY clause of a SQL SELECT
statement). If a list is not provided, or an empty list is provided,
the rows will be returned in the order they were inserted into the
table.
The sort direction for each field is specified by corresponding element of
the list passed for the directions parameter. That list must have the
same number of elements as this one.
The comparisons performed during sorting of string fields are
case-insensitive. For fields of all data types, NULL values (None in
Python, null in other languages) are considered to be less than
non-NULL values."""))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'directions',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(allowedValues=[u'Ascending',
u'Descending']), canBeNone=True),
description=_(
u"""List of strings, either 'Ascending' or 'Descending', that specify
the sort directions for the fields passed in for the orderBy
parameter. This list must have the same number of elements as the one
passed for orderBy."""))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
description=_(u'This parameter is not supported. Do not provide a value
for it.'))
CopyArgumentMetadata(SelectCursor.__init__, u'rowCount',
InMemorySelectCursor.__init__, u'rowCount')
AddResultMetadata(InMemorySelectCursor.__init__, u'cursor',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemorySelectCursor),
description=_(u'New %s instance.') % InMemorySelectCursor.__name__)
# Private method: _Open
AddMethodMetadata(InMemorySelectCursor._Open,
shortDescription=_(u'Opens the cursor.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call Open instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._Open, u'self')
AddArgumentMetadata(InMemorySelectCursor._Open, u'connection',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection),
description=_(u'%s instance.') % InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemorySelectCursor._Open, u'table',
typeMetadata=UnicodeStringTypeMetadata(minLength=1),
description=_(u'Database table to access.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'fields',
InMemorySelectCursor._Open, u'fields')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'where',
InMemorySelectCursor._Open, u'where')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'orderBy',
InMemorySelectCursor._Open, u'orderBy')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'directions',
InMemorySelectCursor._Open, u'directions')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
InMemorySelectCursor._Open, u'spatialReference')
# Private method: _Close
AddMethodMetadata(InMemorySelectCursor._Close,
shortDescription=_(u'Closes the cursor.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Release all references to the cursor instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._Close, u'self')
# Private method: _NextRow
AddMethodMetadata(InMemorySelectCursor._NextRow,
shortDescription=_(u'Moves the cursor to the next row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call NextRow instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._NextRow, u'self')
# Private method: _GetValue
AddMethodMetadata(InMemorySelectCursor._GetValue,
shortDescription=_(u'Gets the value of a field for the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call GetValue instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._GetValue, u'self')
CopyArgumentMetadata(InMemorySelectCursor.GetValue, u'field',
InMemorySelectCursor._GetValue, u'field')
CopyResultMetadata(InMemorySelectCursor.GetValue, u'value',
InMemorySelectCursor._GetValue, u'value')
###############################################################################
# Metadata: InMemoryInsertCursor class
###############################################################################
AddClassMetadata(InMemoryInsertCursor,
shortDescription=_(u'Represents a cursor used to insert rows into a table
stored in an in-memory database.'),
longDescription=_(
u"""This class is not intended to be instantiated directly. Call
OpenInsertCursor on the database connection object to obtain an
instance.
This class always appends new rows to the end of the table."""))
# Constructor
AddMethodMetadata(InMemoryInsertCursor.__init__,
shortDescription=_(u'Constructs a new %s instance and, optionally, opens
it.') % InMemoryInsertCursor.__name__,
longDescription=InMemoryInsertCursor.__doc__.Obj.LongDescription)
AddArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryInsertCursor),
description=_(u'%s instance.') % InMemoryInsertCursor.__name__)
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'connection',
InMemoryInsertCursor.__init__, u'connection')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'table',
InMemoryInsertCursor.__init__, u'table')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
InMemoryInsertCursor.__init__, u'spatialReference')
CopyArgumentMetadata(InsertCursor.__init__, u'rowCount',
InMemoryInsertCursor.__init__, u'rowCount')
AddResultMetadata(InMemoryInsertCursor.__init__, u'cursor',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryInsertCursor),
description=_(u'New %s instance.') % InMemoryInsertCursor.__name__)
# Private method: _Open
AddMethodMetadata(InMemoryInsertCursor._Open,
shortDescription=InMemorySelectCursor._Open.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Open.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._Open, u'self')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'connection',
InMemoryInsertCursor._Open, u'connection')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'table',
InMemoryInsertCursor._Open, u'table')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'spatialReference',
InMemoryInsertCursor._Open, u'spatialReference')
# Private method: _Close
AddMethodMetadata(InMemoryInsertCursor._Close,
shortDescription=InMemorySelectCursor._Close.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Close.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._Close, u'self')
# Private method: _SetValue
AddMethodMetadata(InMemoryInsertCursor._SetValue,
shortDescription=_(u'Sets the value of a field for the row under
construction.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call SetValue instead.'))
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._SetValue, u'self')
CopyArgumentMetadata(InsertCursor.SetValue, u'field',
InMemoryInsertCursor._SetValue, u'field')
CopyArgumentMetadata(InsertCursor.SetValue, u'value',
InMemoryInsertCursor._SetValue, u'value')
# Private method: _InsertRow
AddMethodMetadata(InMemoryInsertCursor._InsertRow,
shortDescription=_(u'Inserts the row under construction into the table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Release all references to the cursor instead.'))
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._InsertRow, u'self')
###############################################################################
# Metadata: InMemoryUpdateCursor class
###############################################################################
AddClassMetadata(InMemoryUpdateCursor,
shortDescription=_(u'Represents a cursor used to read, update, and delete
rows of a table stored in an in-memory database.'),
longDescription=_(
u"""This class is not intended to be instantiated directly. Call
OpenUpdateCursor on the database connection object to obtain an
instance."""))
# Constructor
AddMethodMetadata(InMemoryUpdateCursor.__init__,
shortDescription=_(u'Constructs a new %s instance and, optionally, opens
it.') % InMemoryUpdateCursor.__name__,
longDescription=InMemoryUpdateCursor.__doc__.Obj.LongDescription)
AddArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryUpdateCursor),
description=_(u'%s instance.') % InMemoryUpdateCursor.__name__)
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'connection',
InMemoryUpdateCursor.__init__, u'connection')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'table',
InMemoryUpdateCursor.__init__, u'table')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'fields',
InMemoryUpdateCursor.__init__, u'fields')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'where',
InMemoryUpdateCursor.__init__, u'where')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'orderBy',
InMemoryUpdateCursor.__init__, u'orderBy')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'directions',
InMemoryUpdateCursor.__init__, u'directions')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
InMemoryUpdateCursor.__init__, u'spatialReference')
CopyArgumentMetadata(UpdateCursor.__init__, u'rowCount',
InMemoryUpdateCursor.__init__, u'rowCount')
AddResultMetadata(InMemoryUpdateCursor.__init__, u'cursor',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryUpdateCursor),
description=_(u'New %s instance.') % InMemoryUpdateCursor.__name__)
# Private method: _Open
AddMethodMetadata(InMemoryUpdateCursor._Open,
shortDescription=InMemorySelectCursor._Open.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Open.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._Open, u'self')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'connection',
InMemoryUpdateCursor._Open, u'connection')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'table',
InMemoryUpdateCursor._Open, u'table')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'fields',
InMemoryUpdateCursor._Open, u'fields')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'where',
InMemoryUpdateCursor._Open, u'where')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'orderBy',
InMemoryUpdateCursor._Open, u'orderBy')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'directions',
InMemoryUpdateCursor._Open, u'directions')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'spatialReference',
InMemoryUpdateCursor._Open, u'spatialReference')
# Private method: _Close
AddMethodMetadata(InMemoryUpdateCursor._Close,
shortDescription=InMemorySelectCursor._Close.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Close.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._Close, u'self')
# Private method: _NextRow
AddMethodMetadata(InMemoryUpdateCursor._NextRow,
shortDescription=_(u'Moves the cursor to the next row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call NextRow instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._NextRow, u'self')
# Private method: _GetValue
AddMethodMetadata(InMemoryUpdateCursor._GetValue,
shortDescription=_(u'Gets the value of a field of the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call GetValue instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._GetValue, u'self')
CopyArgumentMetadata(UpdateCursor.GetValue, u'field',
InMemoryUpdateCursor._GetValue, u'field')
CopyResultMetadata(UpdateCursor.GetValue, u'value',
InMemoryUpdateCursor._GetValue, u'value')
# Private method: _SetValue
AddMethodMetadata(InMemoryUpdateCursor._SetValue,
shortDescription=_(u'Sets the value of a field of the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call SetValue instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._SetValue, u'self')
CopyArgumentMetadata(UpdateCursor.SetValue, u'field',
InMemoryUpdateCursor._SetValue, u'field')
CopyArgumentMetadata(UpdateCursor.SetValue, u'value',
InMemoryUpdateCursor._SetValue, u'value')
# Private method: _UpdateRow
AddMethodMetadata(InMemoryUpdateCursor._UpdateRow,
shortDescription=_(u'Updates the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call UpdateRow instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._UpdateRow, u'self')
# Private method: _DeleteRow
AddMethodMetadata(InMemoryUpdateCursor._DeleteRow,
shortDescription=_(u'Deletes the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call DeleteRow instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._DeleteRow, u'self')
###############################################################################
# Names exported by this module
###############################################################################
__all__ = ['InMemoryDatabaseConnection',
'InMemorySelectCursor',
'InMemoryInsertCursor',
'InMemoryUpdateCursor']
Thanks for your interest in MGET and for contacting us about this. I'm sorry
you're seeing this problem and should be able to help you fix it.
I could not reproduce the error, but I believe I know where it is coming
from. There is some code that checks that the input points
(C:\test\test_indexos\Artesanals.shp, in this case) and species field
(Especie) both exist. I believe that code determined that one or the other
does not exist and tried to report the problem. But there is a bug in the
code that reports the message, so "global name 'table' is not defined” is
reported instead, which is not particularly useful.
So we have two problems to investigate:
1. What is the real error message.
2. Why is that error happening?
To address the first problem, I fixed the bug in the reporting code. You can
patch your MGET installation like this:
1. Shut down all ArcGIS programs.
2. Save the attached file to
C:\Python25\Lib\site-packages\GeoEco\DatabaseAccess\InMemory.py (for Arc
9.3.1) or
C:\Python26\ArcGIS10.0\Lib\site-packages\GeoEco\DatabaseAccess\InMemory.py
(for Arc 10).
3. Restart Arc and try the tool again.
Hopefully you will get a more helpful message. If it says that a table or
field does not exist, please check on that. If that is not the problem, let
me know and we'll investigate further.
Best regards,
Jason
-----Original Message-----
From:
[mailto:]
Sent: Thursday, February 17, 2011 5:58 AM
To:
Subject: [mget-help] error using Calculate Species Diversity Index for
Polygons
Hi,
I'm new to the list. First of all, thanks for this toolset. It´s amazingly
useful.
We are trying to use Calculate Species Diversity Index for Polygons. We
succeeded using it when we didn't use Species Count Field (which is optional).
But when we populates it, it shows up the error bellow.
For + info, we tried it in ArcGis 9.3.1 and arcgis 10. Same error.
Any idea or hint? Thank you
Executing: SpeciesDiversityCalculateDiversityIndexForArcGISPolygons
C:\test\test_indexos\Quadricula_1_1_Poly.shp "Shannon index" SHANNON
C:\test\test_indexos\Artesanals.shp Especie DATO1 # #
Start Time: Thu Feb 17 11:35:23 2011
Running script SpeciesDiversityCalculateDiversityIndexForArcGISPolygons...
The R vegan package is not installed. Downloading and installing the latest
version...
Warning: package 'vegan' was built under R version 2.6.2
Intersecting the points with the polygons.
Summing species counts per polygon.
Reading species counts into memory.
NameError: global name 'table' is not defined
<type 'exceptions.NameError'>: global name 'table' is not defined
Failed to execute (SpeciesDiversityCalculateDiversityIndexForArcGISPolygons).
Failed at Thu Feb 17 11:36:06 2011 (Elapsed Time: 43,00 seconds)
# DatabaseAccess/InMemory.py - Classes that implement the GeoEco database
access
# API for an in memory database based on Python lists.
#
# Copyright (C) 2007 Jason J. Roberts
#
# 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 (available in the file LICENSE.TXT)
# 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.
import datetime
import types
from GeoEco.DatabaseAccess import DatabaseConnection, SelectCursor,
InsertCursor, UpdateCursor
from GeoEco.DynamicDocString import DynamicDocString
from GeoEco.Internationalization import _
from GeoEco.Logging import Logger
# Private classes used only within this module
class _TableDef(object):
def __init__(self, name):
self.Name = name
self.Fields = {}
class _FieldDef(object):
def __init__(self, name, dataType, isNullable):
self.Name = name
self.DataType = dataType
self.IsNullable = isNullable is None or isNullable
# Classes exported by this module
class InMemoryDatabaseConnection(DatabaseConnection):
__doc__ = DynamicDocString()
def __init__(self):
self._TableDefs = {}
self._TableData = {}
def _GetGetRowCountSupported(self):
return True
def _GetCreateTableSupported(self):
return True
def _GetDeleteTableSupported(self):
return True
def _GetTemplatesSupported(self):
return True
def _GetAddFieldSupported(self):
return True
def _GetDeleteFieldSupported(self):
return True
def _GetFieldLengthSupported(self):
return False
def _GetFieldPrecisionSupported(self):
return False
def _GetFieldScaleSupported(self):
return False
def _GetFieldAliasSupported(self):
return False
def _GetFieldIsRequiredSupported(self):
return False
def _GetFieldDomainSupported(self):
return False
def _GetSelectCursorSupported(self):
return True
def _GetInsertCursorSupported(self):
return True
def _GetUpdateCursorSupported(self):
return True
def _GetSelectCursorClass(self):
return InMemorySelectCursor
def _GetInsertCursorClass(self):
return InMemoryInsertCursor
def _GetUpdateCursorClass(self):
return InMemoryUpdateCursor
def _GetFieldsSupported(self):
return False
def _GetWhereSupported(self):
return False
def _GetOrderBySupported(self):
return True
def _GetSpatialReferenceSupported(self):
return False
GetRowCountSupported = property(_GetGetRowCountSupported,
doc=DynamicDocString())
CreateTableSupported = property(_GetCreateTableSupported,
doc=DynamicDocString())
DeleteTableSupported = property(_GetDeleteTableSupported,
doc=DynamicDocString())
TemplatesSupported = property(_GetTemplatesSupported,
doc=DynamicDocString())
AddFieldSupported = property(_GetAddFieldSupported,
doc=DynamicDocString())
DeleteFieldSupported = property(_GetDeleteFieldSupported,
doc=DynamicDocString())
FieldLengthSupported = property(_GetFieldLengthSupported,
doc=DynamicDocString())
FieldPrecisionSupported = property(_GetFieldPrecisionSupported,
doc=DynamicDocString())
FieldScaleSupported = property(_GetFieldScaleSupported,
doc=DynamicDocString())
FieldAliasSupported = property(_GetFieldAliasSupported,
doc=DynamicDocString())
FieldIsRequiredSupported = property(_GetFieldIsRequiredSupported,
doc=DynamicDocString())
FieldDomainSupported = property(_GetFieldDomainSupported,
doc=DynamicDocString())
SelectCursorSupported = property(_GetSelectCursorSupported,
doc=DynamicDocString())
InsertCursorSupported = property(_GetInsertCursorSupported,
doc=DynamicDocString())
UpdateCursorSupported = property(_GetUpdateCursorSupported,
doc=DynamicDocString())
SelectCursorClass = property(_GetSelectCursorClass,
doc=DynamicDocString())
InsertCursorClass = property(_GetInsertCursorClass,
doc=DynamicDocString())
UpdateCursorClass = property(_GetUpdateCursorClass,
doc=DynamicDocString())
FieldsSupported = property(_GetFieldsSupported, doc=DynamicDocString())
WhereSupported = property(_GetWhereSupported, doc=DynamicDocString())
OrderBySupported = property(_GetOrderBySupported, doc=DynamicDocString())
SpatialReferenceSupported = property(_GetSpatialReferenceSupported,
doc=DynamicDocString())
def _TableExists(self, table):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return self._TableDefs.has_key(table)
def _GetRowCount(self, table):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
if len(self._TableDefs[table].Fields) <= 0:
return 0
return len(self._TableData[table][self._TableData[table].keys()[0]])
def _CreateTable(self, table, templates=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._TableDefs[table] = _TableDef(table)
self._TableData[table] = {}
return table
def _DeleteTable(self, table):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
del self._TableDefs[table]
del self._TableData[table]
def _FieldExists(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return self._TableDefs.has_key(table) and
self._TableDefs[table].Fields.has_key(field)
def _FieldIsNullable(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return True
def _FieldDataTypeIsSupported(self, dataType):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
return True
def _AddField(self, table, field, dataType, isNullable=None, length=None,
precision=None, scale=None, alias=None, isRequired=False, domain=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
rowCount = self._GetRowCount(table)
if rowCount > 0 and isNullable is not None and not isNullable:
Logger.RaiseException(ValueError(_(u'Cannot add field %(field)s
to table %(table)s because the table is not empty. Fields can only be added
to non-empty tables if isNullable is False.') % {u'field': field, u'table':
table}))
self._TableDefs[table].Fields[field] = _FieldDef(field, dataType,
isNullable)
self._TableData[table][field] = [None] * rowCount
return field
def _DeleteField(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
del self._TableDefs[table].Fields[field]
del self._TableData[table][field]
def _ValidateFieldValue(self, table, field, value):
fieldDef = self._TableDefs[table].Fields[field]
if fieldDef is None:
Logger.RaiseException(ValueError(_(u'Cannot set the value of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': table}))
if value is None:
if not fieldDef.IsNullable:
Logger.RaiseException(ValueError(_(u'Cannot set the value of
field %(field)s of table %(table)s to None because setting this field to None
is not allowed (IsNullable is False).') % {u'field': field, u'table': table}))
return None
return value
def _GetOrderedIndices(self, table, orderBy, directions):
# If the caller did not specify any orderBy fields, just return a list
# of row indices ranging from 0 to the row count - 1.
indices = range(self._GetRowCount(table))
if orderBy is None:
return indices
# Build a temporary comparison function that we can pass to Python's
# built-in sort function.
globalTablePointer = '_Table' + str(id(indices))
globals()[globalTablePointer] = self._TableData[table]
try:
sourceCode = 'def compare(x,y):\n'
sourceCode += ' table = globals()[\'' + globalTablePointer +
'\']\n'
for i in range(len(orderBy)):
dataType =
self._TableDefs[table].Fields[orderBy[i]].DataType.lower()
isString = False
if dataType == u'str' or dataType == u'unicode' or dataType
== u'string' or dataType == u'basestring':
isString = True
sourceCode += ' if table[\'' + str(orderBy[i]) + '\'][y]
is not None and (table[\'' + str(orderBy[i]) + '\'][x] is None or
isinstance(table[\'' + str(orderBy[i]) + '\'][x], basestring) and
isinstance(table[\'' + str(orderBy[i]) + '\'][y], basestring) and table[\'' +
str(orderBy[i]) + '\'][x].lower() < table[\'' + str(orderBy[i]) +
'\'][y].lower() or not (isinstance(table[\'' + str(orderBy[i]) + '\'][x],
basestring) and isinstance(table[\'' + str(orderBy[i]) + '\'][y],
basestring)) and table[\'' + str(orderBy[i]) + '\'][x] < table[\'' +
str(orderBy[i]) + '\'][y]):\n'
if directions[i] == u'Ascending':
sourceCode += ' return -1\n'
else:
sourceCode += ' return 1\n'
sourceCode += ' if table[\'' + str(orderBy[i]) + '\'][x]
is not None and (table[\'' + str(orderBy[i]) + '\'][y] is None or
isinstance(table[\'' + str(orderBy[i]) + '\'][x], basestring) and
isinstance(table[\'' + str(orderBy[i]) + '\'][y], basestring) and table[\'' +
str(orderBy[i]) + '\'][x].lower() > table[\'' + str(orderBy[i]) +
'\'][y].lower() or not (isinstance(table[\'' + str(orderBy[i]) + '\'][x],
basestring) and isinstance(table[\'' + str(orderBy[i]) + '\'][y],
basestring)) and table[\'' + str(orderBy[i]) + '\'][x] > table[\'' +
str(orderBy[i]) + '\'][y]):\n'
if directions[i] == u'Ascending':
sourceCode += ' return 1\n'
else:
sourceCode += ' return -1\n'
sourceCode += ' return 0\n'
exec sourceCode in globals(), locals()
indices.sort(cmp=compare)
finally:
del globals()[globalTablePointer]
# Return the sorted indices.
return indices
def GetFieldValues(self, table, field):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
if not self._TableData.has_key(table):
Logger.RaiseException(ValueError(_(u'Cannot get the values of
field %(field)s of table %(table)s because the table does not exist.') %
{u'field': field, u'table': table}))
if not self._TableData[table].has_key(field):
Logger.RaiseException(ValueError(_(u'Cannot get the values of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': table}))
values = self._TableData[table][field]
from repr import repr
self._LogDebug(_(u'%(conntype)s 0x%(connid)08X: GetFieldValues for
%(field)s of table %(table)s returned %(values)s') % {u'conntype':
self.__class__.__name__, u'connid': id(self), u'field': repr(field),
u'table': repr(table), u'values': repr(values)})
return values
def ImportTable(self, sourceConnection, sourceTable, destTable, fields,
where=None, orderBy=None, directions=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
if not sourceConnection.TableExists(sourceTable):
Logger.RaiseException(ValueError(_(u'Cannot import table
%(table)s into memory because the table does not exist.') % {u'table':
sourceTable}))
for field in fields:
if not sourceConnection.FieldExists(sourceTable, field):
Logger.RaiseException(ValueError(_(u'Cannot import field
%(field)s of table %(table)s into memory because the field does not exist in
the table.') % {u'field': field, u'table': sourceTable}))
if self._TableData.has_key(destTable):
Logger.RaiseException(ValueError(_(u'Cannot import table %(src)s
into in-memory table %(dest)s because that in-memory table already exists.')
% {u'src': sourceTable, u'dest': destTable}))
# Create the destination table and fields. Note that the field
# data type does not matter for in-memory tables.
self.CreateTable(destTable)
for field in fields:
self.AddField(destTable, field, u'object', True)
# Copy the rows from the source table to the destination table.
if sourceConnection.FieldsSupported:
sourceCursor = sourceConnection.OpenSelectCursor(sourceTable,
fields=fields, where=where, orderBy=orderBy, directions=directions)
else:
sourceCursor = sourceConnection.OpenSelectCursor(sourceTable,
where=where, orderBy=orderBy, directions=directions)
try:
destCursor = InMemoryInsertCursor()
from GeoEco.Logging import ProgressReporter
destCursor._ProgressReporter = ProgressReporter(None, None, None,
None, None)
destCursor.Open(self, destTable)
try:
while sourceCursor.NextRow():
for field in fields:
destCursor.SetValue(field,
sourceCursor.GetValue(field))
destCursor.InsertRow()
finally:
del destCursor
finally:
del sourceCursor
class InMemorySelectCursor(SelectCursor):
__doc__ = DynamicDocString()
def __init__(self, connection=None, table=None, fields=None, where=None,
orderBy=None, directions=None, spatialReference=None, rowCount=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = None
super(InMemorySelectCursor, self).__init__(connection, table, fields,
where, orderBy, directions, spatialReference, rowCount)
def _Open(self, connection, table, fields, where, orderBy, directions,
spatialReference):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = connection._GetOrderedIndices(table, orderBy,
directions)
def _Close(self):
pass
def _NextRow(self):
return len(self._RowIndices) > 0 and (self.RowIndex is None or
self.RowIndex + 1 < len(self._RowIndices))
def _GetValue(self, field):
if not self.Connection._TableData[self.Table].has_key(field):
Logger.RaiseException(ValueError(_(u'Cannot get the value of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': self.Table}))
return
self.Connection._TableData[self.Table][field][self._RowIndices[self.RowIndex]]
class InMemoryInsertCursor(InsertCursor):
__doc__ = DynamicDocString()
def __init__(self, connection=None, table=None, spatialReference=None,
rowCount=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._Row = {}
super(InMemoryInsertCursor, self).__init__(connection, table,
spatialReference, rowCount)
def _Open(self, connection, table, spatialReference):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
def _Close(self):
pass
def _SetValue(self, field, value):
self._Row[field] = self.Connection._ValidateFieldValue(self.Table,
field, value)
def _InsertRow(self):
# First set all uninitialized fields to None.
fieldDefs = self.Connection._TableDefs[self.Table].Fields
for (field, d) in fieldDefs.items():
if not self._Row.has_key(field):
if not d.IsNullable:
Logger.RaiseException(ValueError(_(u'Cannot insert this
row into table %(table)s because a value must be provided for field
%(field)s. Setting this field to None is not allowed (IsNullable is False).')
% {u'field': field, u'table': self.Table}))
self._Row[field] = None
# Insert the row.
fieldData = self.Connection._TableData[self.Table]
for (field, value) in self._Row.items():
fieldData[field].append(value)
self._Row = {}
class InMemoryUpdateCursor(UpdateCursor):
__doc__ = DynamicDocString()
def __init__(self, connection=None, table=None, fields=None, where=None,
orderBy=None, directions=None, spatialReference=None, rowCount=None):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = None
self._Row = {}
self._DeletedRowCount = 0
super(InMemoryUpdateCursor, self).__init__(connection, table, fields,
where, orderBy, directions, spatialReference, rowCount)
def _Open(self, connection, table, fields, where, orderBy, directions,
spatialReference):
self.__class__.__doc__.Obj.ValidateMethodInvocation()
self._RowIndices = connection._GetOrderedIndices(table, orderBy,
directions)
def _Close(self):
pass
def _NextRow(self):
self._Row = {}
return len(self._RowIndices) > 0 and (self.RowIndex is None or
self.RowIndex + 1 < len(self._RowIndices))
def _GetValue(self, field):
if not self.Connection._TableData[self.Table].has_key(field):
Logger.RaiseException(ValueError(_(u'Cannot get the value of
field %(field)s of table %(table)s because the field does not exist in the
table.') % {u'field': field, u'table': self.Table}))
if self._Row.has_key(field):
return self._Row[field]
return
self.Connection._TableData[self.Table][field][self._RowIndices[self.RowIndex]
- self._DeletedRowCount]
def _SetValue(self, field, value):
self._Row[field] = self.Connection._ValidateFieldValue(self.Table,
field, value)
def _UpdateRow(self):
fieldData = self.Connection._TableData[self.Table]
for (field, value) in self._Row.items():
fieldData[field][self._RowIndices[self.RowIndex] -
self._DeletedRowCount] = value
def _DeleteRow(self):
fieldData = self.Connection._TableData[self.Table]
for field in fieldData.keys():
del fieldData[field][self._RowIndices[self.RowIndex] -
self._DeletedRowCount]
self._DeletedRowCount += 1
###############################################################################
# Metadata: module
###############################################################################
from GeoEco.Metadata import *
from GeoEco.Types import *
AddModuleMetadata(shortDescription=_(u'Classes for manipulating data in a
simple in-memory database.'))
###############################################################################
# Metadata: InMemoryDatabaseConnection class
###############################################################################
AddClassMetadata(InMemoryDatabaseConnection,
shortDescription=_(u'Represents a connection to an in-memory database.'),
longDescription=_(
u"""When this class is instantiated, it allocates an empty in-memory
database. The database can hold any number of tables of any size,
limited only by available memory. The memory is freed when all cursors
are closed and all instances to the connection object are released.
The database itself is implemented as a dictionary of dictionaries of
lists. The keys of the top-level dictionary are table names, and the
second-level keys are field names. The lists contain the actual data.
All of the lists for a given table are the same length. Table and
field names are case-insensitive. Internally, this class stores the
names in lowercase.
The database only supports a few of the options of more sophisticated
database systems, notably:
* You must assign each field a data type and decide whether the field
can contain NULL values (represented by None in Python, and null or
empty in other languages). The database enforces these constraints.
* The select and update cursors support the orderBy and direction
parameters so you can walk through the rows in a sorted order.
The database is not thread safe and does not implement locking of any
kind. Multithreaded access is not recommended, and you must be careful
to understand the internal implementation if you ever want to open
multiple cursors against the same table, or modify tables that have
open cursors, etc."""))
# Constructor
AddMethodMetadata(InMemoryDatabaseConnection.__init__,
shortDescription=_(u'Constructs a new %s instance.') %
InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection),
description=_(u'%s instance.') % InMemoryDatabaseConnection.__name__)
AddResultMetadata(InMemoryDatabaseConnection.__init__, u'conn',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection),
description=_(u'New %s instance.') % InMemoryDatabaseConnection.__name__)
# Properties
AddPropertyMetadata(InMemoryDatabaseConnection.GetRowCountSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
getting the row counts of tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.CreateTableSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
creating tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.DeleteTableSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
deleting tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.TemplatesSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the templates parameter for creating tables.'),
longDescription=_(u'CreateTable will fail if you supply a value for the
templates parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.AddFieldSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports adding
fields to tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.DeleteFieldSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports
deleting fields from tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldLengthSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the length parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
length parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldPrecisionSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the precision parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
precision parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldScaleSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the scale parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
precision parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldAliasSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the alias parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
alias parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldIsRequiredSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the isRequired parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
isRequired parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.FieldDomainSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the domain parameter when adding fields.'),
longDescription=_(u'AddField will fail if you supply a value for the
domain parameter.'))
AddPropertyMetadata(InMemoryDatabaseConnection.SelectCursorSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports select
cursors for reading rows from tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.InsertCursorSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports insert
cursors for appending rows to tables.'))
AddPropertyMetadata(InMemoryDatabaseConnection.UpdateCursorSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports update
cursors for changing the values of fields of existing table rows.'))
AddPropertyMetadata(InMemoryDatabaseConnection.SelectCursorClass,
typeMetadata=ClassTypeMetadata(cls=InMemorySelectCursor),
shortDescription=_(u'Returns %s.') % InMemorySelectCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.InsertCursorClass,
typeMetadata=ClassTypeMetadata(cls=InMemoryInsertCursor),
shortDescription=_(u'Returns %s.') % InMemoryInsertCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.UpdateCursorClass,
typeMetadata=ClassTypeMetadata(cls=InMemoryUpdateCursor),
shortDescription=_(u'Returns %s.') % InMemoryUpdateCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.FieldsSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the fields parameter for select cursors.'),
longDescription=_(u'%s will fail if you supply a value for the fields
parameter.') % InMemorySelectCursor.__name__)
AddPropertyMetadata(InMemoryDatabaseConnection.WhereSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the where parameter for select and update cursors.'),
longDescription=_(u'%s and %s will fail if you supply a value for the
where parameter.') % (InMemorySelectCursor.__name__,
InMemoryUpdateCursor.__name__))
AddPropertyMetadata(InMemoryDatabaseConnection.OrderBySupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns True. The in-memory database supports the
orderBy and directions parameters of select and update cursors.'))
AddPropertyMetadata(InMemoryDatabaseConnection.SpatialReferenceSupported,
typeMetadata=BooleanTypeMetadata(),
shortDescription=_(u'Returns False. The in-memory database does not
support the spatialReference parameter for cursors.'),
longDescription=_(u'The cursor classes will fail if you supply a value
for the spatialReference parameter.'))
# Private method: _TableExists
AddMethodMetadata(InMemoryDatabaseConnection._TableExists,
shortDescription=_(u'Tests the existence of a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call TableExists instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._TableExists, u'self')
CopyArgumentMetadata(DatabaseConnection.TableExists, u'table',
InMemoryDatabaseConnection._TableExists, u'table')
CopyResultMetadata(DatabaseConnection.TableExists, u'exists',
InMemoryDatabaseConnection._TableExists, u'exists')
# Private method: _GetRowCount
AddMethodMetadata(InMemoryDatabaseConnection._GetRowCount,
shortDescription=_(u'Gets the number of rows in a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call GetRowCount instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._GetRowCount, u'self')
CopyArgumentMetadata(DatabaseConnection.GetRowCount, u'table',
InMemoryDatabaseConnection._GetRowCount, u'table')
CopyResultMetadata(DatabaseConnection.GetRowCount, u'rowCount',
InMemoryDatabaseConnection._GetRowCount, u'rowCount')
# Private method: _CreateTable
AddMethodMetadata(InMemoryDatabaseConnection._CreateTable,
shortDescription=_(u'Creates a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call CreateTable instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._CreateTable, u'self')
CopyArgumentMetadata(DatabaseConnection.CreateTable, u'table',
InMemoryDatabaseConnection._CreateTable, u'table')
CopyArgumentMetadata(DatabaseConnection.CreateTable, u'templates',
InMemoryDatabaseConnection._CreateTable, u'templates')
CopyResultMetadata(DatabaseConnection.CreateTable, u'createdTable',
InMemoryDatabaseConnection._CreateTable, u'createdTable')
# Private method: _DeleteTable
AddMethodMetadata(InMemoryDatabaseConnection._DeleteTable,
shortDescription=_(u'Deletes a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call DeleteTable instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._DeleteTable, u'self')
CopyArgumentMetadata(DatabaseConnection.DeleteTable, u'table',
InMemoryDatabaseConnection._DeleteTable, u'table')
# Private method: _FieldExists
AddMethodMetadata(InMemoryDatabaseConnection._FieldExists,
shortDescription=_(u'Tests the existence of a field.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call FieldExists instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._FieldExists, u'self')
CopyArgumentMetadata(DatabaseConnection.FieldExists, u'table',
InMemoryDatabaseConnection._FieldExists, u'table')
CopyArgumentMetadata(DatabaseConnection.FieldExists, u'field',
InMemoryDatabaseConnection._FieldExists, u'field')
CopyResultMetadata(DatabaseConnection.FieldExists, u'exists',
InMemoryDatabaseConnection._FieldExists, u'exists')
# Private method: _FieldIsNullable
AddMethodMetadata(InMemoryDatabaseConnection._FieldIsNullable,
shortDescription=_(u'Tests the nullability of a field.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call FieldIsNullable instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._FieldIsNullable, u'self')
CopyArgumentMetadata(DatabaseConnection.FieldIsNullable, u'table',
InMemoryDatabaseConnection._FieldIsNullable, u'table')
CopyArgumentMetadata(DatabaseConnection.FieldIsNullable, u'field',
InMemoryDatabaseConnection._FieldIsNullable, u'field')
CopyResultMetadata(DatabaseConnection.FieldIsNullable, u'isNullable',
InMemoryDatabaseConnection._FieldIsNullable, u'isNullable')
# Private method: _FieldDataTypeIsSupported
AddMethodMetadata(InMemoryDatabaseConnection._FieldDataTypeIsSupported,
shortDescription=_(u'Tests whether a data type is supported.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call FieldDataTypeIsSupported instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._FieldDataTypeIsSupported, u'self')
CopyArgumentMetadata(DatabaseConnection.FieldDataTypeIsSupported,
u'dataType', InMemoryDatabaseConnection._FieldDataTypeIsSupported,
u'dataType')
CopyResultMetadata(DatabaseConnection.FieldDataTypeIsSupported,
u'isSupported', InMemoryDatabaseConnection._FieldDataTypeIsSupported,
u'isSupported')
# Private derived class method: _AddField
AddMethodMetadata(InMemoryDatabaseConnection._AddField,
shortDescription=_(u'Adds a field to a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call AddField instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._AddField, u'self')
CopyArgumentMetadata(DatabaseConnection.AddField, u'table',
InMemoryDatabaseConnection._AddField, u'table')
CopyArgumentMetadata(DatabaseConnection.AddField, u'field',
InMemoryDatabaseConnection._AddField, u'field')
CopyArgumentMetadata(DatabaseConnection.AddField, u'dataType',
InMemoryDatabaseConnection._AddField, u'dataType')
CopyArgumentMetadata(DatabaseConnection.AddField, u'isNullable',
InMemoryDatabaseConnection._AddField, u'isNullable')
CopyArgumentMetadata(DatabaseConnection.AddField, u'length',
InMemoryDatabaseConnection._AddField, u'length')
CopyArgumentMetadata(DatabaseConnection.AddField, u'precision',
InMemoryDatabaseConnection._AddField, u'precision')
CopyArgumentMetadata(DatabaseConnection.AddField, u'scale',
InMemoryDatabaseConnection._AddField, u'scale')
CopyArgumentMetadata(DatabaseConnection.AddField, u'alias',
InMemoryDatabaseConnection._AddField, u'alias')
CopyArgumentMetadata(DatabaseConnection.AddField, u'isRequired',
InMemoryDatabaseConnection._AddField, u'isRequired')
CopyArgumentMetadata(DatabaseConnection.AddField, u'domain',
InMemoryDatabaseConnection._AddField, u'domain')
CopyResultMetadata(DatabaseConnection.AddField, u'createdField',
InMemoryDatabaseConnection._AddField, u'createdField')
# Private derived class method: _DeleteField
AddMethodMetadata(InMemoryDatabaseConnection._DeleteField,
shortDescription=_(u'Deletes a field from a table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call DeleteField instead.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection._DeleteField, u'self')
CopyArgumentMetadata(DatabaseConnection.DeleteField, u'table',
InMemoryDatabaseConnection._DeleteField, u'table')
CopyArgumentMetadata(DatabaseConnection.DeleteField, u'field',
InMemoryDatabaseConnection._DeleteField, u'field')
# Public derived class method: GetFieldValues
AddMethodMetadata(InMemoryDatabaseConnection.GetFieldValues,
shortDescription=_(u'Gets the values of a field of a table as a Python
list.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection.GetFieldValues, u'self')
AddArgumentMetadata(InMemoryDatabaseConnection.GetFieldValues, u'table',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Table containing the field.'))
AddArgumentMetadata(InMemoryDatabaseConnection.GetFieldValues, u'field',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Field to retrieve.'))
AddResultMetadata(InMemoryDatabaseConnection.GetFieldValues, u'values',
typeMetadata=ListTypeMetadata(elementType=AnyObjectTypeMetadata(canBeNone=True)),
description=_(
u"""Values of the field as a list. The values are guaranteed to be in
the order that the rows were inserted into the table (first in, first
out).
The returned list is a reference to list held internally by the
InMemoryDatabaseConnection. The returned list is intended to be
read-only; modifying it directly modifies the underlying table. If you
add or remove items from it without making the same changes to the
other lists of the table, the underlying table will be corrupt and you
may receive unexpected errors later in your program."""))
# Public derived class method: ImportTable
AddMethodMetadata(InMemoryDatabaseConnection.ImportTable,
shortDescription=_(u'Imports a table from another connection into an
in-memory table of this connection.'))
CopyArgumentMetadata(InMemoryDatabaseConnection.__init__, u'self',
InMemoryDatabaseConnection.ImportTable, u'self')
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable,
u'sourceConnection',
typeMetadata=ClassInstanceTypeMetadata(cls=DatabaseConnection),
description=_(u'%s instance containing the table to import.') %
DatabaseConnection.__name__)
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'sourceTable',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Table to import.'))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'destTable',
typeMetadata=UnicodeStringTypeMetadata(),
description=_(u'Name of the destination table to be created in this %s
instance. The table must not already exist.') %
InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'fields',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(),
minLength=1),
description=_(u'List of fields to import. You must specify at least one
field.'))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'where',
typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
description=_(
u"""SQL WHERE clause expression that specifies the subset of rows to
import from the source table. If this parameter is not provided, all
of the rows will be imported. If this parameter is provided but the
source table does not support WHERE clauses, an error will be raised.
The exact syntax of this expression depends on the database containing
the source table and the type of connection used to access it. If you
are using the ArcGIS geoprocessor to access the database, ESRI
recommends you reference fields using the following syntax:
* If you're querying ArcInfo coverages, shapefiles, INFO tables or
dBASE tables (.dbf files), enclose field names in double quotes in
the SQL expression: "MY_FIELD".
* If you're querying Microsoft Access tables or personal
geodatabase tables, enclose field names in square brackets:
[MY_FIELD].
* If you're querying ArcSDE geodatabase tables, an ArcIMS feature
class, or an ArcIMS image service sublayer, don't enclose field
names: MY_FIELD.
"""))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'orderBy',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(),
canBeNone=True),
description=_(
u"""Fields that will be used to sort the rows of the source table
before they are imported into the destination table (i.e., the columns
specified in the ORDER BY clause of a SQL SELECT statement). If no
fields are provided, the rows will be sorted in the default order
determined by the underlying database. If this parameter is provided
but the underlying database does not support ORDER BY clauses, an
error will be raised.
In addition to specifying the ORDER BY fields, you must also specify
the sort direction for each field."""))
AddArgumentMetadata(InMemoryDatabaseConnection.ImportTable, u'directions',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(allowedValues=[u'Ascending',
u'Descending']), canBeNone=True),
description=_(
u"""List of strings, either 'Ascending' or 'Descending', that specify
the sort directions for the ORDER BY fields. If this parameter is
provided but the underlying database does not support ORDER BY
clauses, an error will be raised."""))
###############################################################################
# Metadata: InMemorySelectCursor class
###############################################################################
AddClassMetadata(InMemorySelectCursor,
shortDescription=_(u'Represents a cursor used to read rows from a table
stored in an in-memory database.'),
longDescription=_(
u"""This class is not intended to be instantiated directly. Call
OpenSelectCursor on the database connection object to obtain an
instance."""))
# Constructor
AddMethodMetadata(InMemorySelectCursor.__init__,
shortDescription=_(u'Constructs a new %s instance and, optionally, opens
it.') % InMemorySelectCursor.__name__,
longDescription=InMemorySelectCursor.__doc__.Obj.LongDescription)
AddArgumentMetadata(InMemorySelectCursor.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemorySelectCursor),
description=_(u'%s instance.') % InMemorySelectCursor.__name__)
AddArgumentMetadata(InMemorySelectCursor.__init__, u'connection',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection,
canBeNone=True),
description=_(u'%s instance.') % InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemorySelectCursor.__init__, u'table',
typeMetadata=UnicodeStringTypeMetadata(minLength=1, canBeNone=True),
description=_(
u"""Database table to access. If this parameter is provided, the
connection parameter must also be provided, and the cursor will be
opened immediately."""))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'fields',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(),
canBeNone=True),
description=_(u'This parameter is not supported. Do not provide a value
for it.'))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'where',
typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
description=_(u'This parameter is not supported. Do not provide a value
for it.'))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'orderBy',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(minLength=1),
canBeNone=True),
description=_(
u"""List of fields that will be used to sort the returned rows (i.e.,
the list of columns specified in the ORDER BY clause of a SQL SELECT
statement). If a list is not provided, or an empty list is provided,
the rows will be returned in the order they were inserted into the
table.
The sort direction for each field is specified by corresponding element of
the list passed for the directions parameter. That list must have the
same number of elements as this one.
The comparisons performed during sorting of string fields are
case-insensitive. For fields of all data types, NULL values (None in
Python, null in other languages) are considered to be less than
non-NULL values."""))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'directions',
typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(allowedValues=[u'Ascending',
u'Descending']), canBeNone=True),
description=_(
u"""List of strings, either 'Ascending' or 'Descending', that specify
the sort directions for the fields passed in for the orderBy
parameter. This list must have the same number of elements as the one
passed for orderBy."""))
AddArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
description=_(u'This parameter is not supported. Do not provide a value
for it.'))
CopyArgumentMetadata(SelectCursor.__init__, u'rowCount',
InMemorySelectCursor.__init__, u'rowCount')
AddResultMetadata(InMemorySelectCursor.__init__, u'cursor',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemorySelectCursor),
description=_(u'New %s instance.') % InMemorySelectCursor.__name__)
# Private method: _Open
AddMethodMetadata(InMemorySelectCursor._Open,
shortDescription=_(u'Opens the cursor.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call Open instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._Open, u'self')
AddArgumentMetadata(InMemorySelectCursor._Open, u'connection',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryDatabaseConnection),
description=_(u'%s instance.') % InMemoryDatabaseConnection.__name__)
AddArgumentMetadata(InMemorySelectCursor._Open, u'table',
typeMetadata=UnicodeStringTypeMetadata(minLength=1),
description=_(u'Database table to access.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'fields',
InMemorySelectCursor._Open, u'fields')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'where',
InMemorySelectCursor._Open, u'where')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'orderBy',
InMemorySelectCursor._Open, u'orderBy')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'directions',
InMemorySelectCursor._Open, u'directions')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
InMemorySelectCursor._Open, u'spatialReference')
# Private method: _Close
AddMethodMetadata(InMemorySelectCursor._Close,
shortDescription=_(u'Closes the cursor.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Release all references to the cursor instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._Close, u'self')
# Private method: _NextRow
AddMethodMetadata(InMemorySelectCursor._NextRow,
shortDescription=_(u'Moves the cursor to the next row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call NextRow instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._NextRow, u'self')
# Private method: _GetValue
AddMethodMetadata(InMemorySelectCursor._GetValue,
shortDescription=_(u'Gets the value of a field for the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call GetValue instead.'))
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'self',
InMemorySelectCursor._GetValue, u'self')
CopyArgumentMetadata(InMemorySelectCursor.GetValue, u'field',
InMemorySelectCursor._GetValue, u'field')
CopyResultMetadata(InMemorySelectCursor.GetValue, u'value',
InMemorySelectCursor._GetValue, u'value')
###############################################################################
# Metadata: InMemoryInsertCursor class
###############################################################################
AddClassMetadata(InMemoryInsertCursor,
shortDescription=_(u'Represents a cursor used to insert rows into a table
stored in an in-memory database.'),
longDescription=_(
u"""This class is not intended to be instantiated directly. Call
OpenInsertCursor on the database connection object to obtain an
instance.
This class always appends new rows to the end of the table."""))
# Constructor
AddMethodMetadata(InMemoryInsertCursor.__init__,
shortDescription=_(u'Constructs a new %s instance and, optionally, opens
it.') % InMemoryInsertCursor.__name__,
longDescription=InMemoryInsertCursor.__doc__.Obj.LongDescription)
AddArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryInsertCursor),
description=_(u'%s instance.') % InMemoryInsertCursor.__name__)
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'connection',
InMemoryInsertCursor.__init__, u'connection')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'table',
InMemoryInsertCursor.__init__, u'table')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
InMemoryInsertCursor.__init__, u'spatialReference')
CopyArgumentMetadata(InsertCursor.__init__, u'rowCount',
InMemoryInsertCursor.__init__, u'rowCount')
AddResultMetadata(InMemoryInsertCursor.__init__, u'cursor',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryInsertCursor),
description=_(u'New %s instance.') % InMemoryInsertCursor.__name__)
# Private method: _Open
AddMethodMetadata(InMemoryInsertCursor._Open,
shortDescription=InMemorySelectCursor._Open.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Open.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._Open, u'self')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'connection',
InMemoryInsertCursor._Open, u'connection')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'table',
InMemoryInsertCursor._Open, u'table')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'spatialReference',
InMemoryInsertCursor._Open, u'spatialReference')
# Private method: _Close
AddMethodMetadata(InMemoryInsertCursor._Close,
shortDescription=InMemorySelectCursor._Close.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Close.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._Close, u'self')
# Private method: _SetValue
AddMethodMetadata(InMemoryInsertCursor._SetValue,
shortDescription=_(u'Sets the value of a field for the row under
construction.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call SetValue instead.'))
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._SetValue, u'self')
CopyArgumentMetadata(InsertCursor.SetValue, u'field',
InMemoryInsertCursor._SetValue, u'field')
CopyArgumentMetadata(InsertCursor.SetValue, u'value',
InMemoryInsertCursor._SetValue, u'value')
# Private method: _InsertRow
AddMethodMetadata(InMemoryInsertCursor._InsertRow,
shortDescription=_(u'Inserts the row under construction into the table.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Release all references to the cursor instead.'))
CopyArgumentMetadata(InMemoryInsertCursor.__init__, u'self',
InMemoryInsertCursor._InsertRow, u'self')
###############################################################################
# Metadata: InMemoryUpdateCursor class
###############################################################################
AddClassMetadata(InMemoryUpdateCursor,
shortDescription=_(u'Represents a cursor used to read, update, and delete
rows of a table stored in an in-memory database.'),
longDescription=_(
u"""This class is not intended to be instantiated directly. Call
OpenUpdateCursor on the database connection object to obtain an
instance."""))
# Constructor
AddMethodMetadata(InMemoryUpdateCursor.__init__,
shortDescription=_(u'Constructs a new %s instance and, optionally, opens
it.') % InMemoryUpdateCursor.__name__,
longDescription=InMemoryUpdateCursor.__doc__.Obj.LongDescription)
AddArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryUpdateCursor),
description=_(u'%s instance.') % InMemoryUpdateCursor.__name__)
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'connection',
InMemoryUpdateCursor.__init__, u'connection')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'table',
InMemoryUpdateCursor.__init__, u'table')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'fields',
InMemoryUpdateCursor.__init__, u'fields')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'where',
InMemoryUpdateCursor.__init__, u'where')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'orderBy',
InMemoryUpdateCursor.__init__, u'orderBy')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'directions',
InMemoryUpdateCursor.__init__, u'directions')
CopyArgumentMetadata(InMemorySelectCursor.__init__, u'spatialReference',
InMemoryUpdateCursor.__init__, u'spatialReference')
CopyArgumentMetadata(UpdateCursor.__init__, u'rowCount',
InMemoryUpdateCursor.__init__, u'rowCount')
AddResultMetadata(InMemoryUpdateCursor.__init__, u'cursor',
typeMetadata=ClassInstanceTypeMetadata(cls=InMemoryUpdateCursor),
description=_(u'New %s instance.') % InMemoryUpdateCursor.__name__)
# Private method: _Open
AddMethodMetadata(InMemoryUpdateCursor._Open,
shortDescription=InMemorySelectCursor._Open.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Open.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._Open, u'self')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'connection',
InMemoryUpdateCursor._Open, u'connection')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'table',
InMemoryUpdateCursor._Open, u'table')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'fields',
InMemoryUpdateCursor._Open, u'fields')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'where',
InMemoryUpdateCursor._Open, u'where')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'orderBy',
InMemoryUpdateCursor._Open, u'orderBy')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'directions',
InMemoryUpdateCursor._Open, u'directions')
CopyArgumentMetadata(InMemorySelectCursor._Open, u'spatialReference',
InMemoryUpdateCursor._Open, u'spatialReference')
# Private method: _Close
AddMethodMetadata(InMemoryUpdateCursor._Close,
shortDescription=InMemorySelectCursor._Close.__doc__.Obj.ShortDescription,
longDescription=InMemorySelectCursor._Close.__doc__.Obj.LongDescription)
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._Close, u'self')
# Private method: _NextRow
AddMethodMetadata(InMemoryUpdateCursor._NextRow,
shortDescription=_(u'Moves the cursor to the next row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call NextRow instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._NextRow, u'self')
# Private method: _GetValue
AddMethodMetadata(InMemoryUpdateCursor._GetValue,
shortDescription=_(u'Gets the value of a field of the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call GetValue instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._GetValue, u'self')
CopyArgumentMetadata(UpdateCursor.GetValue, u'field',
InMemoryUpdateCursor._GetValue, u'field')
CopyResultMetadata(UpdateCursor.GetValue, u'value',
InMemoryUpdateCursor._GetValue, u'value')
# Private method: _SetValue
AddMethodMetadata(InMemoryUpdateCursor._SetValue,
shortDescription=_(u'Sets the value of a field of the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call SetValue instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._SetValue, u'self')
CopyArgumentMetadata(UpdateCursor.SetValue, u'field',
InMemoryUpdateCursor._SetValue, u'field')
CopyArgumentMetadata(UpdateCursor.SetValue, u'value',
InMemoryUpdateCursor._SetValue, u'value')
# Private method: _UpdateRow
AddMethodMetadata(InMemoryUpdateCursor._UpdateRow,
shortDescription=_(u'Updates the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call UpdateRow instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._UpdateRow, u'self')
# Private method: _DeleteRow
AddMethodMetadata(InMemoryUpdateCursor._DeleteRow,
shortDescription=_(u'Deletes the current row.'),
longDescription=_(u'This is a private method that is not intended to be
called directly. Call DeleteRow instead.'))
CopyArgumentMetadata(InMemoryUpdateCursor.__init__, u'self',
InMemoryUpdateCursor._DeleteRow, u'self')
###############################################################################
# Names exported by this module
###############################################################################
__all__ = ['InMemoryDatabaseConnection',
'InMemorySelectCursor',
'InMemoryInsertCursor',
'InMemoryUpdateCursor']
Archives powered by MHonArc.