0

我正在尝试在 smartgwt 中使用 SQL 模板将数据从我的数据库加载到 listgrid 中,但我无法获得所需的结果。这是我试图在 SmartGWT 中采用的原始 SQL 查询以获得结果

SELECT
dbo.province.provincename as province,
dbo.province.capital,
dbo.province.code,
dbo.province.telcode,
dbo.province.taxcode,
dbo.county.countyname as county,
dbo.district.districtname as district,
dbo.zone.alternateName as zone,
dbo.neighbourhood.alternateName as neigbhour,
dbo.city.cityname as city,
dbo.city.taxcode,
dbo.city.fdocode,
count(dbo.customer.customeraltname) as countCustomer
FROM
dbo.county
INNER JOIN
dbo.province
ON
(
    dbo.county.provinceID = dbo.province.id)
INNER JOIN
dbo.district
ON
(
    dbo.county.id = dbo.district.countyID)
INNER JOIN
dbo.city
ON
(
    dbo.district.id = dbo.city.districtID)
INNER JOIN
dbo.zone
ON
(
    dbo.city.id = dbo.zone.cityId)
INNER JOIN
dbo.neighbourhood
ON
(
    dbo.zone.id = dbo.neighbourhood.zoneId)
INNER JOIN
dbo.customer
ON
(
    dbo.neighbourhood.id = dbo.customer.neighbourhoodId)
    Group By dbo.province.provincename,
dbo.province.capital,
dbo.province.code,
dbo.province.telcode,
dbo.province.taxcode,
dbo.county.countyname,
dbo.district.districtname,
dbo.zone.alternateName,
dbo.neighbourhood.alternateName,
dbo.city.cityname,
dbo.city.taxcode,
dbo.city.fdocode

下面是我的 ds.xml

<DataSource ID="CusNeiGroupDS" serverType="sql">
<fields>
    <field name="id" type="integer" />
    <field name="provincename" title="province" type="text"/>
    <field name="capital" title="capital" type="text"/>
    <field name="code" title="code" type="text"/>
    <field name="telcode" title="telcode" type="text"/>
    <field name="taxcode" title="taxcode" type="text" />
    <field name="provinceId" type="integer" tableName="county"/>
    <field name="countyname" title="county" type="text" tableName="county"/>
    <field name="district" title="district" type="text" />
    <field name="city" title="city" type="text"  />
    <field name="zone" title="zone" type="text"  />
    <field name="neighbour" title="neighbour" type="text"  />
    <field name="taxcodecity" title="taxcodecity" type="text"
        />
    <field name="fdocode" title="fdocode" type="text" />
    <!-- <field name="countCustomer" title="countCustomer" type="int" /> -->
</fields>


<operationBindings>
    <operationBinding operationId="summary"
        operationType="fetch">
        <selectClause>
            districtname as
            district,
            alternateName as zone,
            alternateName as neigbhour,
            cityname
            as city,
            fdocode
        </selectClause>
        <tableClause>province, county, district, zone, neighbourhood, city
        </tableClause>
        <whereClause>
            province.Id = county.provinceId
        AND district.countyId = county.Id
        AND city.districtId = district.Id
        AND neighbourhood.zoneId = zone.Id
        </whereClause>
    </operationBinding>
</operationBindings>

我得到的错误是

执行选择:SELECT COUNT(*) FROM CusNeiGroupDS WHERE ('1'='1') on db:SQLServer 抛出异常:java.sql.SQLException:无效的对象名称 'CusNeiGroupDS'。- 假设连接过时并重试查询。

但是当我像这样将表名放在数据源中时,我会得到输出,但只能从我提到的那个表中得到输出,而不是从与 FK 连接的其他表中得到输出。

<DataSource ID="CusNeiGroupDS" serverType="sql" tableName="province">
4

1 回答 1

0

我能够通过在数据源中使用 includeFrom 和 foreignKey 标签来实现这一点。然后创建另一个数据源,我用它来包含我需要的来自不同表的所有数据。就像这样

<DataSource ID="neighbourDS_1" serverType="sql" tableName="neighbourhood"     inheritsFrom="neighbourDS">
<fields>
    <field name="provincename" includeFrom="provinceDS.provincename" />
    <field name="capital" includeFrom="provinceDS.capital" />
    <field name="code" includeFrom="provinceDS.code" />
    <field name="telcode" includeFrom="provinceDS.telcode" />
    <field name="countyname" includeFrom="countyDS.countyname" />
    <field name="district" includeFrom="districtDS.districtname" />
    <field name="city" includeFrom="cityDS.cityname" />
    <field name="taxcodecity" includeFrom="cityDS.taxcodecity" />
    <field name="fdocode" includeFrom="cityDS.fdocode" />
    <field name="zone" includeFrom="zoneDS.zone" />
</fields>
</DataSource>
于 2014-12-16T08:07:25.927 回答