running-elephant / datart

Datart is a next generation Data Visualization Open Platform
https://running-elephant.github.io/datart-docs/
Apache License 2.0
1.97k stars 590 forks source link

使用 SQL 语句创建数据视图执行错误 No database selected #2179

Open 276397082 opened 1 year ago

276397082 commented 1 year ago

Datart版本号 datart-server-1.0.0-rc.2-install.zip

错误描述 执行错误 No database selected

如何重现 重现错误的步骤,例如:

  1. 点击数据视图
  2. 点击...新建数据视图
  3. 点击...SQL视图
  4. 选择数据源
  5. 粘贴sql语句并执行
  6. 看到错误执行错误 No database selected

期望结果 怎么解决

截图 image

image

运行环境详情:(可选,取决于错误发生的具体位置)

276397082 commented 1 year ago

image

sql语句中所有的表名称前面都得加上数据库名称才行,

OK语句


select
    id,
    created_at,
    updated_at,
    name,
    category_type,
    use_default_eula,
    eula_text,
    require_acceptance,
    checkin_email,
    image,
    (
    select
        count(*)
    from
        snipeit.accessories
    where
        categories.id = accessories.category_id
        and accessories.deleted_at is null) as accessories_count,
    (
    select
        count(*)
    from
        snipeit.consumables
    where
        categories.id = consumables.category_id
        and consumables.deleted_at is null) as consumables_count,
    (
    select
        count(*)
    from
        snipeit.components
    where
        categories.id = components.category_id
        and components.deleted_at is null) as components_count,
    (
    select
        count(*)
    from
        snipeit.licenses
    where
        categories.id = licenses.category_id
        and licenses.deleted_at is null) as licenses_count,
    (
    select
        count(*)
    from
        snipeit.assets
    inner join snipeit.models on
        models.id = assets.model_id
    where
        categories.id = models.category_id
        and exists (
        select
            *
        from
            snipeit.status_labels
        where
            assets.status_id = status_labels.id
            and status_labels.archived = 0
            and status_labels.deleted_at is null)
        and assets.deleted_at is null
        and models.deleted_at is null) as assets_count
from
    snipeit.categories
where
    categories.deleted_at is null
order by
    assets_count asc
limit 20 offset 0

报错语句1

select
    `id`,
    `created_at`,
    `updated_at`,
    `name`,
    `category_type`,
    `use_default_eula`,
    `eula_text`,
    `require_acceptance`,
    `checkin_email`,
    `image`,
    (
    select
        count(*)
    from
        `accessories`
    where
        `categories`.`id` = `accessories`.`category_id`
        and `accessories`.`deleted_at` is null) as `accessories_count`,
    (
    select
        count(*)
    from
        `consumables`
    where
        `categories`.`id` = `consumables`.`category_id`
        and `consumables`.`deleted_at` is null) as `consumables_count`,
    (
    select
        count(*)
    from
        `components`
    where
        `categories`.`id` = `components`.`category_id`
        and `components`.`deleted_at` is null) as `components_count`,
    (
    select
        count(*)
    from
        `licenses`
    where
        `categories`.`id` = `licenses`.`category_id`
        and `licenses`.`deleted_at` is null) as `licenses_count`,
    (
    select
        count(*)
    from
        `assets`
    inner join `models` on
        `models`.`id` = `assets`.`model_id`
    where
        `categories`.`id` = `models`.`category_id`
        and exists (
        select
            *
        from
            `status_labels`
        where
            `assets`.`status_id` = `status_labels`.`id`
            and `archived` = 0
            and `status_labels`.`deleted_at` is null)
        and `assets`.`deleted_at` is null
        and `models`.`deleted_at` is null) as `assets_count`
from
    `categories`
where
    `categories`.`deleted_at` is null
order by
    `assets_count` asc
limit 20 offset 0

报错语句2

select
    `id`,
    `created_at`,
    `updated_at`,
    `name`,
    `category_type`,
    `use_default_eula`,
    `eula_text`,
    `require_acceptance`,
    `checkin_email`,
    `image`,
    (
    select
        count(*)
    from
        `snipeit.accessories`
    where
        `categories`.`id` = `accessories`.`category_id`
        and `accessories`.`deleted_at` is null) as `accessories_count`,
    (
    select
        count(*)
    from
        `snipeit.consumables`
    where
        `categories`.`id` = `consumables`.`category_id`
        and `consumables`.`deleted_at` is null) as `consumables_count`,
    (
    select
        count(*)
    from
        `snipeit.components`
    where
        `categories`.`id` = `components`.`category_id`
        and `components`.`deleted_at` is null) as `components_count`,
    (
    select
        count(*)
    from
        `snipeit.licenses`
    where
        `categories`.`id` = `licenses`.`category_id`
        and `licenses`.`deleted_at` is null) as `licenses_count`,
    (
    select
        count(*)
    from
        `snipeit.assets`
    inner join `snipeit.models` on
        `models`.`id` = `assets`.`model_id`
    where
        `categories`.`id` = `models`.`category_id`
        and exists (
        select
            *
        from
            `snipeit.status_labels`
        where
            `assets`.`status_id` = `status_labels`.`id`
            and `archived` = 0
            and `status_labels`.`deleted_at` is null)
        and `assets`.`deleted_at` is null
        and `models`.`deleted_at` is null) as `assets_count`
from
    `snipeit.categories`
where
    `categories`.`deleted_at` is null
order by
    `assets_count` asc
limit 20 offset 0
nianhua99 commented 1 year ago

如果你的数据源连接指定了默认数据库,那表名前就不需要加数据库名,如果没有,那当然要加数据库名,这和Datart程序无关