From VisualWorks®, 7.4 of December 5, 2005 on December 5, 2005 at 2:01:24 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>CTLibTableColumn</name> <environment>Smalltalk</environment> <super>Lens.LensDatabaseTableColumn</super> <private>false</private> none table columnName odbcTypeCode typeName dataPrecision length numericScale numericRadix nullable remarks dataType typeMap <imports></imports> <category>Lens-Private-CTLib</category> <attributes> <package>CTLibLens</package> </attributes> </class> <comment> CTLibTableColumn
This class is private to the implementation of the ObjectLens. Users should not use this class directly and should not subclass it. The instance variables below, with the exception of colid, are filled in by executing the 'sp_columns' catalog procedure. Instance Variables: table <LensDatabaseTable> the table containing the column columnName <String> the column's name odbcTypeCode <Integer> the ODBC type code for the column typeName <String> data-source dependent data type name (assumption: they match those from the SQLServer) dataPrecision <SmallInteger> the column's precision, if the column is numeric. the number of characters in the column otherwise length <SmallInteger> the number of bytes required for storage or transfer across the api numericScale <SmallInteger> the column's scale, if the column is numeric numericRadix <SmallInteger> the column's radix, if the column is numeric (typically 10 or 2) nullable <SmallInteger> 1 if the column may contain nil, 0 if the column may not contain nil, 2 if the sp_columns procedure didn't know (interpreted as 0) remarks <String> a description of the column ssDataType <SmallInteger> the SQL-Server data type code dataType <SmallInteger> the name of the data type of the column (in a database-specific encoding) Class instance variables: typeMap <IdentityDictionary> Maps sybase type codes to type names
</comment> <class> <name>CTLibTransporter</name> <environment>Smalltalk</environment> <super>Lens.LensSQLTransporter</super> <private>false</private> none <imports></imports> <category>Lens-Private-CTLib</category> <attributes> <package>CTLibLens</package> </attributes> </class> <comment> CTLibTransporter
This class is private to the implementation of the ObjectLens. Users should not use this class directly and should not subclass it.
</comment> <class> <name>CTLibPkeys</name> <environment>Smalltalk</environment> <super>Core.Object</super> <private>false</private> none tableQualifier tableOwner tableName columnName keySeq <imports></imports> <category>Lens-Private-CTLib</category> <attributes> <package>CTLibLens</package> </attributes> </class> <comment> CTLibPkeys
This class is private to the implementation of the ObjectLens. Users should not use this class directly and should not subclass it. The instance variables are populated by the 'sp_pkeys' catalog procedure. Instance variables: tableQualifier <String> The table qualifier tableOwner <String> The table's owner tableName <String> The table name columnName <String> The name of the column keySeq <SmallInteger> The sequence number of the column in the key
</comment> <class> <name>CTLibFkeys</name> <environment>Smalltalk</environment> <super>Core.Object</super> <private>false</private> none pktableQualifier pktableOwner pktableName pkcolumnName fktableQualifier fktableOwner fktableName fkcolumnName keySeq <imports></imports> <category>Lens-Private-CTLib</category> <attributes> <package>CTLibLens</package> </attributes> </class> <comment> CTLibFkeys
This class is private to the implementation of the ObjectLens. Users should not use this class directly and should not subclass it. The instance variables are populated via the 'sp_fkeys' catalog procedure. Instance variables: pktableQualifier <String> The primary key table qualifier pktableOwner <String> The primary key table owner pktableName <String> The primary key table name pkcolumnName <String> The primary key column name fktableQualifier <String> The foreign key table qualifier fktableOwner <String> The foreign key table owner fktableName <String> The foreign key table name fkcolumnName <String> The foreign key column name keySeq <SmallInteger> The sequence of the column within the primary key
</comment> <class> <name>CTLibTable</name> <environment>Smalltalk</environment> <super>Lens.LensDatabaseTable</super> <private>false</private> none tableQualifier tableOwner tableName tableType columns <imports></imports> <category>Lens-Private-CTLib</category> <attributes> <package>CTLibLens</package> </attributes> </class> <comment> CTLibTable
This class is private to the implementation of the ObjectLens. Users should not use this class directly and should not subclass it. CTLibTable instances represent a table in a SYBASE database. Instance Variables: tableQualifier <String | nil> The database name of the table. If the table is to be used without qualification, then this field is nil. tableOwner <String | nil> The name of the owner of the table. If the table is to be used without qualification, then this field is nil. tableName <String> the table's name tableType <String> encodes the type of table (database-specific) columns <IdentitySet of: LensDatabaseTableColumn> the set of columns defined on the table
</comment> <class> <name>CTLibContext</name> <environment>Smalltalk</environment> <super>Lens.LensDatabaseContext</super> <private>false</private> none databaseName <imports></imports> <category>Lens-Private-CTLib</category> <attributes> <package>CTLibLens</package> </attributes> </class> <comment> CTLibContext
This class is private to the implementation of the ObjectLens. Users should not use this class directly and should not subclass it. Instance variables: databaseName <String> The name of the database
</comment> <methods> CTLibTableColumn <category>accessing</category>
dataType "Answer the receiver's dataType." ^dataType
dataType: newDataType "Set the receiver's dataType to newDataType. 'bit' variables can not be null in SYBASE" dataType := newDataType. dataType = 'bit' ifTrue: [self isNotNil: true].
isNotNil "Answer whether the column described by the receiver cannot store nulls." ^nullable = 0 or: [ nullable == 2 ]
isNotNil: aBoolean "Set the receiver's isNotNil. 'bit' variables can not be null in SYBASE" nullable := aBoolean ifTrue: [0] ifFalse: [1]. self dataType = 'bit' ifTrue: [ nullable := 0 ].
maxColumnConstraint "Answer the receiver's maxColumnConstraint." ^dataPrecision
maxColumnConstraint: newWidth "Set the receiver's maxColumnConstraint to newWidth." dataPrecision := newWidth
name "Answer the receiver's name." ^columnName
name: newName "Set the receiver's name to newName." columnName := newName
scale "Answer the receiver's scale." ^numericScale
scale: newScale "Set the receiver's scale to newScale." numericScale := newScale
table "Answer the receiver's table." ^table
table: newTable "Set the receiver's table to newTable." table := newTable
</methods> <methods> CTLibTableColumn <category>private</category>
deriveBaseDataType "The typeName field must be a user type and so we need to infer the underlying type name to use." | typeToUse | "Attempt to translate just by looking up the type code. If unrecognized, punt." typeToUse := self class typeMap at: odbcTypeCode ifAbsent: [ ^nil ]. "Check to see which kind of integer we've got." typeToUse = 'int' ifTrue: [ length == 2 ifTrue: [ ^'smallint' ]. length == 1 ifTrue: [ ^'tinyint' ]. ^typeToUse ]. "Check to see which kind of floating point number we've got." typeToUse = 'float' ifTrue: [ length == 4 ifTrue: [ ^'real' ]. ^typeToUse ]. "Check to see which kind of money we've got." typeToUse = 'money' ifTrue: [ length == 4 ifTrue: [ ^'smallmoney' ]. ^typeToUse ]. "Check to see which kind of datetime we've got." typeToUse = 'datetime' ifTrue: [ length == 4 ifTrue: [ ^'smalldatetime' ]. ^typeToUse ]. ^typeToUse
</methods> <methods> CTLibTableColumn <category>initialize-release</category>
postFetchInitialize: ignored "Decode dataType and zero out width if dataType is long." | dtm | "If the dbms gave us a recognizable type name, use it. Otherwise, derive from the odbcTypeCode field." dtm := self class contextClass dataTypeMappings detect: [ :m | m columnType = typeName ] ifNone: [ nil ]. self dataType: (dtm notNil ifTrue: [ dtm columnType ] ifFalse: [ self deriveBaseDataType ]). (#('image' 'text') includes: self dataType) ifTrue: [ self maxColumnConstraint: self defaultBLOBSize ]
</methods> <methods> CTLibTableColumn class <category>class initialization</category>
initialize "Initialize the class" "CTLibTableColumn initialize" self initializeTypeMap
initializeTypeMap "Initialize the map from type code to type name. The codes in this table are those returned for the data_type by the stored procedure sp_columns." typeMap := IdentityDictionary new. typeMap at: 1 put: 'char'; at: 2 put: 'numeric'; at: 3 put: 'money'; at: 4 put: 'int'; at: 5 put: 'smallint'; at: 6 put: 'float'; at: 7 put: 'real'; at: 8 put: 'float'; at: 11 put: 'datetime'; at: 12 put: 'varchar'; at: -1 put: 'text'; at: -2 put: 'binary'; at: -3 put: 'varbinary'; at: -4 put: 'image'; at: -6 put: 'tinyint'; at: -7 put: 'bit'
</methods> <methods> CTLibTableColumn class <category>private</category>
encodedAspects ^#(#name #dataType #maxColumnConstraint #scale #(#pickledIsNotNil #isNotNil:) )
</methods> <methods> CTLibTableColumn class <category>accessing</category>
contextClass "Answer the name of the class which provides database context." ^CTLibContext
typeMap ^typeMap
</methods> <methods> CTLibTransporter <category>clause generation</category>
generateExpressionFor: surrogate "Generate an SQL expression for condition, and put it on commandStream." surrogate IsOperationSurrogate ifTrue: [ | op | op := surrogate Operator. (#(StandardDeviation Variance) includes: op) ifTrue: [ LensContainer invalidAggregateFunctionSignal raiseWith: (Array with: lensContainer with: op)]]. ^super generateExpressionFor: surrogate
generateFromClauseLocking: flag "Generate the FROM clause. If there is more than one referenced table then emit aliases for the tables" | useAlias | useAlias := referencedObjectSurrogates size > 1. commandStream nextPutAll: ' FROM '. referencedObjectSurrogates do: [:surrog | commandStream nextPutAll: surrog Type tableName. useAlias ifTrue: [ commandStream nextPut: $ ; nextPutAll: (self tableNameFor: surrog)]. (session checkLocking: flag) ifTrue: [ commandStream nextPutAll: ' HOLDLOCK']. commandStream nextPut: $,]. commandStream skip: -1.
</methods> <methods> CTLibTransporter <category>registration</category>
nextVariableName "Answer a name to be used for the next variable being created." ^ ':' , (variableIndex := variableIndex + 1) printString
</methods> <methods> CTLibTransporter class <category>class initialization</category>
initialize "CTLibTransporter initialize" super initialize
initializeFunctionsTable "CTLibTransporter initializeFunctionsTable" | dict | super initializeFunctionsTable. dict := functions at: #Number. dict at: #abs put: 'ABS'. dict at: #ceil put: 'CEILING'. dict at: #floor put: 'FLOOR'. dict at: #power: put: 'POWER'. dict at: #round: put: 'ROUND'. dict at: #sign put: 'SIGN'. dict at: #sqrt put: 'SQRT'. dict at: #cos put: 'COS'. dict at: #exp put: 'EXP'. dict at: #ln put: 'LOG'. dict at: #sin put: 'SIN'. dict at: #tan put: 'TAN'. dict := functions at: #Character. dict at: #ascii put: 'ASCII'. dict at: #length put: 'DATALENGTH'. dict at: #lower put: 'LOWER'. dict at: #soundex put: 'SOUNDEX'. dict at: #substringAt:length: put: 'SUBSTRING'. dict at: #upper put: 'UPPER'. dict := functions at: #Date. dict := functions at: #Conversion. dict at: #toChar put: 'STR'. dict at: #toChar: put: 'STR'.
</methods> <methods> CTLibPkeys <category>accessing</category>
columnName "Answer the receiver's columnName." ^columnName
keySeq "Answer the receiver's keySeq." ^keySeq
tableName "Answer the receiver's tableName." ^tableName
tableOwner "Answer the receiver's tableOwner." ^tableOwner
tableQualifier "Answer the receiver's tableQualifier." ^tableQualifier
</methods> <methods> CTLibFkeys <category>accessing</category>
fkcolumnName "Answer the receiver's fkcolumnName." ^fkcolumnName
fktableName "Answer the receiver's fktableName." ^fktableName
fktableOwner "Answer the receiver's fktableOwner." ^fktableOwner
fktableQualifier "Answer the receiver's fktableQualifier." ^fktableQualifier
keySeq "Answer the receiver's keySeq." ^keySeq
pkcolumnName "Answer the receiver's pkcolumnName." ^pkcolumnName
pktableName "Answer the receiver's pktableName." ^pktableName
pktableOwner "Answer the receiver's pktableOwner." ^pktableOwner
pktableQualifier "Answer the receiver's pktableQualifier." ^pktableQualifier
</methods> <methods> CTLibFkeys <category>private</category>
pkTableNameArray "Construct a 1-3 element array with the pktableName, pkownerName, and pkqualifierName." | elems | elems := OrderedCollection new: 3. elems add: self pktableName. (self pktableOwner notNil and: [self pktableOwner isEmpty not]) ifTrue: [ elems add: self pktableOwner ]. (self pktableQualifier notNil and: [self pktableQualifier isEmpty not]) ifTrue: [ elems size < 2 ifTrue: [ elems add: self pktableOwner ]. elems add: self pktableQualifier ]. ^elems
</methods> <methods> CTLibTable <category>qualifications</category>
qualify: ldm self owner: ldm databaseContext username. self qualifier: ldm databaseContext databaseName
unqualify self owner: nil. self qualifier: nil
</methods> <methods> CTLibTable <category>accessing</category>
columns "Answer the receiver's columns." | lens qryTextStream cols colsAccessor ldm | (self privateColumns notNil or: [(lens := self lensSession) isNil]) ifTrue: [ ^self privateColumns ]. "Construct the stored procedure invocation to be used." (qryTextStream := String new writeStream) nextPutAll: 'execute sp_columns @table_name="'; nextPutAll: self name; nextPut: $". (self owner notNil and: [ self owner isEmpty not ]) ifTrue: [ qryTextStream nextPutAll: ', @table_owner="'; nextPutAll: self owner; nextPut: $" ]. (self qualifier notNil and: [ self qualifier isEmpty not ]) ifTrue: [ qryTextStream nextPutAll: ', @table_qualifier="'; nextPutAll: self qualifier; nextPut: $" ]. "Gather the table object we're looking for." CTLibConnection unableToExecuteSQLSignal handle: [ :ex | cols := Array new: 0. ex return ] do: [ colsAccessor := (lens containerOf: (ldm := lens dataModel) databaseContext class tableColumnClass) operationAccessor. colsAccessor operation alternateSQL: qryTextStream contents. cols := colsAccessor values ]. self columns: cols. "nil out widths of all fixed-size columns" self privateColumns do: [ :column | (ldm fieldTypeForColumn: column) isVariableSize ifFalse: [ column maxColumnConstraint: nil ]]. ^cols
columns: newColumns "Set the receiver's columns to newColumns." columns := newColumns
name "Answer the receiver's name." ^tableName
name: newName "Set the receiver's name to newName." tableName := newName
owner "Answer the receiver's owner." ^tableOwner
owner: aString "Set the receiver's owner." tableOwner := aString
qualifier "Answer the second level of name qualification (scoped outside of owner)." ^tableQualifier
qualifier: aString "Set the receiver's qualifier." tableQualifier := aString
tableType "Answer the receiver's tableType." ^tableType
</methods> <methods> CTLibTable <category>key detection</category>
getPrimaryKeyIn: aLensSession "Answer the primary key for this table by looking it up in the database catalogs. Answer an instance of LensTableKey or nil." | qryTextStream keysAccessor keyCols | "Construct the stored procedure invocation to be used." (qryTextStream := String new writeStream) nextPutAll: 'execute sp_pkeys @table_name="'; nextPutAll: self name; nextPut: $". (self owner notNil and: [self owner isEmpty not]) ifTrue: [ qryTextStream nextPutAll: ', @table_owner="'; nextPutAll: self owner; nextPut: $" ]. (self qualifier notNil and: [self qualifier isEmpty not]) ifTrue: [ qryTextStream nextPutAll: ', @table_qualifier="'; nextPutAll: self qualifier; nextPut: $" ]. "Execute the stored procedure and capture the results." CTLibConnection unableToExecuteSQLSignal handle: [ :ex | keyCols := Array new: 0. ex return ] do: [ keysAccessor := (aLensSession containerOf: CTLibPkeys) operationAccessor. keysAccessor operation alternateSQL: qryTextStream contents. keyCols := keysAccessor values ]. keyCols isEmpty ifFalse: [ "We found a valid primary key, make a LensTableKey to hold it." | tabCols | tabCols := keyCols collect: [ :pkey | self columns detect: [ :each | each name = pkey columnName ] ] . ^LensTableKey table: self columns: tabCols keyType: #primary ]. ^nil
inferReferencesIn: aLensSession "We use tables also as non-persistent objects, therefore, aLensSession is passed to this method and the table's own lens is not used (if it even had one). This method returns a collection with arrays representing references from the table to other tables" | qryTextStream fkeysAccessor fkeys res allParts fkeysStream | "Construct the stored procedure invocation to be used." (qryTextStream := String new writeStream) nextPutAll: 'execute sp_fkeys @fktable_name="'; nextPutAll: self name; nextPut: $". (self owner notNil and: [self owner isEmpty not]) ifTrue: [ qryTextStream nextPutAll: ', @fktable_owner="'; nextPutAll: self owner; nextPut: $" ]. (self qualifier notNil and: [self qualifier isEmpty not]) ifTrue: [ qryTextStream nextPutAll: ', @fktable_qualifier="'; nextPutAll: self qualifier; nextPut: $" ]. "Gather all of the column references for any foreign key from this table." CTLibConnection unableToExecuteSQLSignal handle: [ :ex | fkeys := Array new: 0. ex return ] do: [ fkeysAccessor := (aLensSession containerOf: CTLibFkeys) operationAccessor. fkeysAccessor operation alternateSQL: qryTextStream contents. fkeys := fkeysAccessor values ]. res := OrderedCollection new. fkeysStream := fkeys readStream. [fkeysStream atEnd] whileFalse: [ | seq | "The stored procedure gives them back in order so we just need to find the break points." allParts := OrderedCollection new. seq := 0. [fkeysStream atEnd not and: [ seq < fkeysStream peek keySeq ]] whileTrue: [ seq := (allParts add: fkeysStream next) keySeq ]. res add: (Array with: self with: (allParts collect: [ :fkey | fkey fkcolumnName ]) with: (allParts at: 1) pkTableNameArray) ]. ^res
</methods> <methods> CTLibTable <category>private-accessing</category>
privateColumns "Answer the contents of the instance variable which holds the receiver's columns." ^columns
</methods> <methods> CTLibTable <category>printing</category>
printNameOn: aStream | emitOwnerSeparator | emitOwnerSeparator := false. (self qualifier notNil and: [self qualifier isEmpty not]) ifTrue: [ aStream nextPutAll: self qualifier; nextPut: $.. emitOwnerSeparator := true ]. (self owner notNil and: [self owner isEmpty not]) ifTrue: [ aStream nextPutAll: self owner. emitOwnerSeparator := true ]. emitOwnerSeparator ifTrue: [ aStream nextPut: $.. ]. aStream nextPutAll: self name
</methods> <methods> CTLibTable <category>DDL generation</category>
alterColumnCommand: column operation: operation "Answer a command to add a column to a table." | stream | operation == #add ifTrue: [ stream := WriteStream on: String new. stream nextPutAll: 'alter table ', self qualifiedName. stream nextPutAll: ' add '. column putDefinitionOn: stream. ^stream contents] ifFalse: [ LensSession complain: ( (#cannotAlterExistingColumns << #sybaseDB >> 'SYBASE databases do not support altering existing<n>database columns to conform to data model columns.<n>Please use the Data Modeler to make the database<n> and model columns compatible, or drop the table.<n>Then restart installation.' ) expandMacros )]
removeFrom: container "Remove table represented by receiver." container lensSession connection doCommandString: 'drop table ' , self qualifiedName
</methods> <methods> CTLibTable <category>testing</category>
isReferredToBy: tableNameArray "Answer whether tableNameArray contains a viable reference to this table. The tableNameArray is composed of name elements ordered from the RIGHT to left in a qualification order (i.e. the simple name comes first and then any qualification)." | temp1 temp2 | ^(super isReferredToBy: tableNameArray) and: [ tableNameArray size < 3 or: [ (temp1 := self qualifier) isNil or: [ temp1 isEmpty or: [ (temp2 := tableNameArray at: 3) isNil or: [ temp1 = temp2 ] ] ] ] ]
</methods> <methods> CTLibTable class <category>accessing</category>
contextClass "Answer the name of the class which provides database context." ^CTLibContext
</methods> <methods> CTLibTable class <category>private</category>
encodedAspects ^#(#owner)
</methods> <methods> CTLibContext <category>private</category>
isColumn: c1 theSameAs: c2 "Since sybase is case-sensitive we compare using =" ^c1 name = c2 name
</methods> <methods> CTLibContext <category>accessing</category>
copyParametersFrom: dbc2 "Copy only the editable parameters of the context." super copyParametersFrom: dbc2. self databaseName: dbc2 databaseName
databaseName "Answer the receiver's databaseName." ^databaseName
databaseName: newName "Set the receiver's databaseName to newName." databaseName := newName
</methods> <methods> CTLibContext <category>printing</category>
displayString | strm | strm := String new writeStream. strm nextPutAll: 'CTLib: '. username isEmpty not ifTrue: [strm nextPutAll: username]. environment isEmpty not ifTrue: [strm nextPut: Character space; nextPutAll: environment]. databaseName isEmpty not ifTrue: [strm nextPut: Character space; nextPutAll: databaseName]. ^strm contents
printOn: stream | elaborated | elaborated := false. super printOn: stream. (username isNil or: [username isEmpty]) ifFalse: [elaborated := true. stream nextPut: $(; nextPutAll: 'user='; nextPutAll: username; nextPut: Character space]. (databaseName isNil or: [databaseName isEmpty]) ifFalse: [elaborated ifFalse: [stream nextPut: $(]. stream nextPutAll: 'db='; nextPutAll: databaseName; nextPut: Character space]. elaborated ifTrue: [stream skip: -1. stream nextPut: $)]
</methods> <methods> CTLibContext <category>connection</category>
postConnectIn: aLensSession "Give the LensDatabaseContext a chance to get control after the connect but before any database access is performed." | dbName | ((dbName := self databaseName) notNil and: [dbName isEmpty not]) ifTrue: [ aLensSession connection doCommandString: 'use ', self databaseName ]
</methods> <methods> CTLibContext <category>initialize-release</category>
initialize super initialize. databaseName := ''.
</methods> <methods> CTLibContext <category>data dictionary manipulation</category>
definePrimaryKeyFor: type in: aLensSession "Define the primary key for type in aLensSession. It's OK if it already exists." | definition idv | self class == (self class environment at: #CTLib10Context ifAbsent: [nil]) ifTrue: [ "CTLib System 10 does it the standard way." ^super definePrimaryKeyFor: type in: aLensSession ]. "Special handling for CTLib 4.x servers." definition := WriteStream on: String new. definition nextPutAll: 'execute sp_primarykey '; print: type table qualifiedName. idv := type idVariable. idv forLeavesDo: [:v | definition nextPutAll: ', '; print: v column name ]. aLensSession connection doCommandString: definition contents
getTableNamed: tableName in: aLens "Answer the table named tableName from the data dictionary. tableName may contain an owner to qualify the table name." | criteria qryTextStream tables tablesAccessor | "Construct the stored procedure invocation to be used." criteria := self separateNameQualification: tableName. (qryTextStream := String new writeStream) nextPutAll: 'execute sp_tables @table_name="'; nextPutAll: (criteria at: 1); nextPut: $". (criteria size > 1 and: [(criteria at: 2) notNil and: [ (criteria at: 2) isEmpty not ]]) ifTrue: [ qryTextStream nextPutAll: ', @table_owner="'; nextPutAll: (criteria at: 2); nextPut: $" ]. (criteria size > 2 and: [(criteria at: 3) notNil and: [ (criteria at: 3) isEmpty not ]]) ifTrue: [ qryTextStream nextPutAll: ', @table_qualifier="'; nextPutAll: (criteria at: 3); nextPut: $" ]. qryTextStream nextPutAll: ', @table_type = "''TABLE'', ''SYSTEM TABLE'', ''VIEW''"'. "Gather the table object we're looking for." self class connectionClass unableToExecuteSQLSignal handle: [ :ex | tables := Array new: 0. ex return ] do: [ tablesAccessor := (aLens containerOf: self class tableClass) operationAccessor. tablesAccessor operation alternateSQL: qryTextStream contents. tables := tablesAccessor values ]. ^tables isEmpty ifTrue: [ nil ] ifFalse: [ tables at: 1 ]
listTablesLike: aPattern in: aLens "Answer a collection of tables which are accessible using aLens. If aPattern is not nil, limit the search to only those tables with names matching." | criteria qryTextStream tables tablesAccessor | "Construct the stored procedure invocation to be used." criteria := self separateNameQualification: aPattern. (qryTextStream := String new writeStream) nextPutAll: 'execute sp_tables @table_name="'; nextPutAll: ((criteria at: 1) copyReplaceAll: '*' with: '%'); nextPut: $". (criteria size > 1 and: [(criteria at: 2) notNil and: [ (criteria at: 2) isEmpty not ]]) ifTrue: [ qryTextStream nextPutAll: ', @table_owner="'; nextPutAll: ((criteria at: 2) copyReplaceAll: '*' with: '%'); nextPut: $" ]. (criteria size > 2 and: [(criteria at: 3) notNil and: [ (criteria at: 3) isEmpty not ]]) ifTrue: [ qryTextStream nextPutAll: ', @table_qualifier="'; nextPutAll: (criteria at: 3); nextPut: $" ]. qryTextStream nextPutAll: ', @table_type = "''TABLE'', ''SYSTEM TABLE'', ''VIEW''"'. "Gather the table object we're looking for." self class connectionClass unableToExecuteSQLSignal handle: [ :ex | tables := Array new: 0. ex return ] do: [ tablesAccessor := (aLens containerOf: self class tableClass) operationAccessor. tablesAccessor operation alternateSQL: qryTextStream contents. tables := tablesAccessor values ]. ^(tables asSortedCollection: [ :before :after | before owner < after owner or: [ before owner = after owner and: [ before name <= after name ] ] ]) asArray
</methods> <methods> CTLibContext <category>testing</category>
isCTLib "Answer whether receiver is a CTLib context." ^true
</methods> <methods> CTLibContext class <category>accessing</category>
connectionClass "Answer the class of connections opened by instances of self." ^(self environment at: #CTLibConnection ifAbsent: [nil])
kind "Answer user-friendly label for receiver." ^#'SYBASE-CTLib'
tableClass "Answer the class of tables for the receiver." ^CTLibTable
tableColumnClass "Answer the class of table columns in receiver's data dictionary." ^CTLibTableColumn
transporterClass "Answer the class of transporters via which to dynamically access the receiver's associated database." ^CTLibTransporter
</methods> <methods> CTLibContext class <category>class initialization</category>
initialize "Initialize class instance variables." "CTLibContext initialize" shortSize := 255. maxColumnSize := SmallInteger maxVal. maxNameSize := 30. (transactionPolicies := IdentitySet new) add: #PessimisticRR. self initializeBasicTypes. dataTypeMappings := OrderedCollection new. (self mapFieldOf: #String to: 'varchar') maxSize: shortSize. (self mapFieldOf: #String to: 'char') maxSize: shortSize. (self mapFieldOf: #String to: 'text') maxSize: maxColumnSize; makeLong. (self mapFieldOf: #ByteArray to: 'varbinary') maxSize: shortSize. (self mapFieldOf: #ByteArray to: 'binary') maxSize: shortSize. (self mapFieldOf: #ByteArray to: 'image') maxSize: maxColumnSize; makeLong. (self mapFieldOf: #Integer to: 'int'). (self mapFieldOf: #Integer to: 'smallint'). (self mapFieldOf: #Integer to: 'tinyint'). (self mapFieldOf: #Float to: 'real'). (self mapFieldOf: #Double to: 'float'). (self mapFieldOf: #SerialNumber to: 'int'). (self mapFieldOf: #Timestamp to: 'datetime'). (self mapFieldOf: #Timestamp to: 'smalldatetime'). (self mapFieldOf: #Boolean to: 'bit'). (self mapFieldOf: #FixedPoint to: 'money'). (self mapFieldOf: #FixedPoint to: 'smallmoney'). (self mapFieldOf: #FixedPoint to: 'numeric'). (self mapFieldOf: #FixedPoint to: 'decimal'). reservedWords := #('add' 'all' 'alter' 'and' 'any' 'as' 'asc' 'avg' 'begin' 'between' 'break' 'browse' 'bulk' 'by' 'checkpoint' 'clustered' 'commit' 'compute' 'confirm' 'continue' 'controlrow' 'convert' 'count' 'create' 'database' 'dbcc' 'declare' 'default' 'delete' 'desc' 'disk' 'distinct' 'drop' 'dummy' 'dump' 'else' 'end' 'errlvl' 'errexit' 'except' 'exec' 'execute' 'exists' 'exit' 'fillfactor' 'for' 'from' 'goto' 'grant' 'group' 'having' 'holdlock' 'if' 'in' 'index' 'insert' 'intersect' 'into' 'is' 'kill' 'like' 'lineno' 'load' 'max' 'min' 'mirrorexit' 'nonclustered' 'not' 'null' 'off' 'offsets' 'on' 'once' 'or' 'order' 'over' 'perm' 'permanent' 'plan' 'prepare' 'print' 'proc' 'procedure' 'processexit' 'public' 'raiserror' 'readtext' 'reconfigure' 'return' 'revoke' 'rollback' 'rowcount' 'rule' 'save' 'select' 'set' 'setuser' 'shutdown' 'statistics' 'sum' 'syb_terminate' 'table' 'tape' 'temp' 'temporary' 'textsize' 'to' 'tran' 'transaction' 'trigger' 'truncate' 'tsequal' 'union' 'unique' 'update' 'use' 'values' 'view' 'waitfor' 'where' 'while' 'with' 'writetext'). self initializeCatalogDataModel.
initializeBasicTypes "Initialize basicTypes" "CTLibContext initializeBasicTypes" super initializeBasicTypes. self addBasicType: (LensEncodedType new memberClass: Symbol; fieldType: (self typeNamed: #String); encodeSelector: nil; decodeSelector: #asSymbol)
</methods> <methods> CTLibContext class <category>private</category>
bindingsForInstance: aContext "Returns a dictionary whose keys are symbols and values are valueModels. This Dictionary will be used to populate a bindings dictionary when aContext is edited in some ui (probably a dialog)" | bin | bin := super bindingsForInstance: aContext. bin at: #databaseName put: ((AspectAdaptor forAspect: #databaseName) subject: aContext). ^bin
encodedAspects ^#(#databaseName)
markedAsSystemClass "This class not to be shown when browsing user classes."
</methods> <methods> CTLibContext class <category>database specs</category>
catalogDataModelSpec "Answer a literal array encoding of the data model used to access the system catalog." "LensEditor new openOnClass: self andSelector: #catalogDataModelSpec" ^#(#LensDataModel #setDatabaseContext: #(#CTLibContext #username: '' #environment: '' #databaseName: '' ) #structureTypes: #( #(#LensStructureType #memberClass: #CTLibTable #setVariables: #( #(#LensStructureVariable #name: 'tableQualifier' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableQualifier' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'tableOwner' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableOwner' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'tableName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableName' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'tableType' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableType' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'columns' #setValueType: #Object #fieldType: #Object #generatesAccessor: false #generatesMutator: false #privateIsMapped: false ) ) #table: #(#CTLibTable #name: 'sp_tables' ) #defersPostingUpdates: true #idVariable: #('tableQualifier' 'tableOwner' 'tableName' ) #idGeneratorType: #userDefinedId #indexes: #() ) #(#LensStructureType #memberClass: #CTLibTableColumn #setVariables: #( #(#LensStructureVariable #name: 'table' #setValueType: #CTLibTable #fieldType: #(#LensStructureType #memberClass: #Array #setVariables: #( #(#LensStructureVariable #name: 'tableQualifier' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableQualifier' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: false #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'tableOwner' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableOwner' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: false #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'tableName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'tableName' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: false #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) ) #table: #(#CTLibTable #name: 'sp_columns' ) #defersPostingUpdates: true #indexes: #() ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'columnName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'columnName' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'odbcTypeCode' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'odbcTypeCode' #dataType: 'smallint' ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'typeName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'typeName' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'dataPrecision' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'dataPrecision' #dataType: 'smallint' ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'length' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'length' #dataType: 'int' ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'numericScale' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'numericScale' #dataType: 'smallint' ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'numericRadix' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'numericRadix' #dataType: 'smallint' ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'nullable' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'nullable' #dataType: 'smallint' ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'remarks' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'remarks' #dataType: 'varchar' #maxColumnConstraint: 254 ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true ) #(#LensStructureVariable #name: 'dataType' #setValueType: #Object #fieldType: #Object #generatesAccessor: false #generatesMutator: false #privateIsMapped: false ) ) #table: #(#CTLibTable #name: 'sp_columns' ) #defersPostingUpdates: true #idVariable: #('table' 'columnName' ) #idGeneratorType: #userDefinedId #indexes: #() ) #(#LensStructureType #memberClass: #CTLibPkeys #setVariables: #( #(#LensStructureVariable #name: 'tableQualifier' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'table_qualifier' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'tableOwner' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'table_owner' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'tableName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'table_name' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'columnName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'column_name' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'keySeq' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'key_seq' #dataType: 'smallint' #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #privateIsMapped: true #isNotNil: true ) ) #table: #(#CTLibTable #name: 'sp_pkeys' ) #defersPostingUpdates: true #idVariable: #('tableQualifier' 'tableOwner' 'tableName' 'columnName' ) #idGeneratorType: #userDefinedId #indexes: #() ) #(#LensStructureType #memberClass: #CTLibFkeys #setVariables: #( #(#LensStructureVariable #name: 'pktableQualifier' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'pktable_qualifier' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'pktableOwner' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'pktable_owner' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'pktableName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'pktable_name' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'pkcolumnName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'pkcolumn_name' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'fktableQualifier' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'fktable_qualifier' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'fktableOwner' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'fktable_owner' #dataType: 'varchar' #maxColumnConstraint: 32 ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true ) #(#LensStructureVariable #name: 'fktableName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'fktable_name' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'fkcolumnName' #setValueType: #String #fieldType: #String #column: #(#CTLibTableColumn #name: 'fkcolumn_name' #dataType: 'varchar' #maxColumnConstraint: 32 #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) #(#LensStructureVariable #name: 'keySeq' #setValueType: #Integer #fieldType: #Integer #column: #(#CTLibTableColumn #name: 'key_seq' #dataType: 'smallint' #isNotNil: true ) #generatesAccessor: true #generatesMutator: false #isId: true #privateIsMapped: true #isNotNil: true ) ) #table: #(#CTLibTable #name: 'sp_fkeys' ) #defersPostingUpdates: true #idVariable: #('pktableQualifier' 'pktableOwner' 'pktableName' 'pkcolumnName' 'fktableQualifier' 'fktableOwner' 'fktableName' 'fkcolumnName' 'keySeq' ) #idGeneratorType: #userDefinedId #indexes: #() ) ) #lensPolicyName: #Mixed #lensTransactionPolicyName: #PessimisticRR #validity: #installed )
</methods> <methods> CTLibContext class <category>converting</category>
internalNameFor: externalName ^externalName copy
</methods> <methods> CTLibContext class <category>interface specs</category>
propertiesSpec "UIPainter new openOnClass: self andSelector: #propertiesSpec" <resource: #canvas> ^#(#FullSpec #window: #(#WindowSpec #label: '' #min: #(#Point 215 107 ) #bounds: #(#Rectangle 324 648 539 755 ) ) #component: #(#SpecCollection #collection: #( #(#InputFieldSpec #layout: #(#LayoutFrame 140 0 9 0 -6 1 34 0 ) #model: #databaseName ) #(#InputFieldSpec #layout: #(#LayoutFrame 140 0 41 0 -6 1 66 0 ) #model: #username ) #(#InputFieldSpec #layout: #(#LayoutFrame 140 0 73 0 -6 1 98 0 ) #model: #environment ) #(#LabelSpec #layout: #(#AlignmentOrigin 8 0 36 0 0 1 ) #label: #(#{UserMessage} #key: #DatabaseName #catalogID: #sybaseDB #defaultString: 'Database name:' )) #(#LabelSpec #layout: #(#AlignmentOrigin 8 0 68 0 0 1 ) #label: #(#{UserMessage} #key: #UserName #catalogID: #sybaseDB #defaultString: 'User name:') ) #(#LabelSpec #layout: #(#AlignmentOrigin 8 0 100 0 0 1 ) #label: #(#{UserMessage} #key: #Environment #catalogID: #sybaseDB #defaultString: 'Environment:') ) ) ) )
</methods> <initialize> CTLibTableColumn </initialize> <initialize> CTLibTransporter </initialize> <initialize> CTLibContext </initialize> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>Object</name> <environment>Core</environment> <super></super> <private>false</private> none <imports></imports> <category>Kernel-Objects</category> <attributes> <package>Kernel-Objects</package> </attributes> </class> <class> <name>LensDatabaseTable</name> <environment>Lens</environment> <super>Lens.LensMetadata</super> <private>false</private> none <imports></imports> <category>Lens-Private-Database Context</category> <attributes> <package>Lens-Runtime</package> </attributes> </class> <class> <name>LensDatabaseContext</name> <environment>Lens</environment> <super>Lens.LensMetadata</super> <private>false</private> none username environment catalogDataModel dataTypeMappings maxColumnSize maxNameSize reservedWords basicTypes shortSize transactionPolicies <imports></imports> <category>Lens-Private-Database Context</category> <attributes> <package>Lens-Runtime</package> </attributes> </class> <class> <name>LensSQLTransporter</name> <environment>Lens</environment> <super>Lens.LensBasicTransporter</super> <private>false</private> none selectFieldList whereCondition commandStream command objectSurrogateIndices joinLinks variableIndex numberOfIdVariables itemSurrogate variableBindings functions <imports></imports> <category>Lens-Private-Transporter</category> <attributes> <package>Lens-Runtime</package> </attributes> </class> <class> <name>LensDatabaseTableColumn</name> <environment>Lens</environment> <super>Lens.LensMetadata</super> <private>false</private> none <imports></imports> <category>Lens-Private-Database Context</category> <attributes> <package>Lens-Runtime</package> </attributes> </class>