Glorp和Oracle:限制查询结果

Can*_*lon 6 oracle smalltalk limit

我在VisualWorks和Oracle数据库中使用Glorp.由于Oracle不知道LIMIT命令,因此以下查询将返回WHERE子句为其计算为true的myTable的所有记录.

q := Glorp.SimpleQuery
       returningManyOf: MyTable
       where: [:each | each name = 'test']
       limit: 10.
q orderBy: [:each | each id descending].
results:= aGlorpSession execute: q.
Run Code Online (Sandbox Code Playgroud)

我如何在这个Glorp查询中加入ROWNUM?

//编辑生成的SQL:

SELECT t1.id, t1.name
 FROM MyTable t1
 WHERE (t1.name= ?) ORDER BY t1.id DESC
Run Code Online (Sandbox Code Playgroud)

Can*_*lon 1

在 Smalltalk.Glorp.DatabasePlatform 上,我添加了两个空方法 #printPreLimitWrapper:on: 和 #printPostLimitWrapper:on: 我在 Smalltalk.Glorp.OraclePlatform 中重写了它们:

printPreLimitWrapper: anInteger on: aCommand
    aCommand nextPutAll: ' SELECT * FROM ( '

printPostLimitWrapper: anInteger on: aCommand

    aCommand nextPutAll: ' ) WHERE ROWNUM <= '.
    anInteger printOn: aCommand.
    aCommand nextPutAll: ' '.
Run Code Online (Sandbox Code Playgroud)

在 Smalltalk.Glorp.SimpleQuery 上我添加了:

printPostLimitWrapperOn: aCommand
    self hasLimit ifFalse: [^self].
    self platform printPostLimitWrapper: self limit on: aCommand.

printPreLimitWrapperOn: aCommand
    self hasLimit ifFalse: [^self].
    self platform printPreLimitWrapper: self limit on: aCommand.
Run Code Online (Sandbox Code Playgroud)

在 Smalltalk.Glorp.QuerySelectCommand 上,我更改了以下方法:

printSQL
    query printPreLimitWrapperOn: self.
    stream nextPutAll: 'SELECT '.
    query printSelectFieldsOn: self.
    self findBoundExpressions.
    query printTablesOn: self.
    query printWhereClauseOn: self.
    query printJoinsOn: self.
    query printOrderingOn: self.
    query printGroupByOn: self.
    query printPostLimitOn: self.
    query printOffsetOn: self.
    query printPostLimitWrapperOn: self.
Run Code Online (Sandbox Code Playgroud)