小编was*_*tim的帖子

如何在SLICK中使用SQL"LIKE"运算符

也许是个愚蠢的问题.但到目前为止我还没有找到答案.那么如何在SLICK中表示SQL的"LIKE"运算符?

scala scalaquery slick

27
推荐指数
1
解决办法
1万
查看次数

如何在select子句中编写嵌套查询

我正在尝试使用SLICK 1.0.0生成此SQL:

    select
    cat.categoryId,
    cat.title,
    (
      select
        count(product.productId)
      from
        products product
        right join products_categories productCategory on productCategory.productId = product.productId
        right join categories c on c.categoryId = productCategory.categoryId
      where
        c.leftValue >= cat.leftValue and
        c.rightValue <= cat.rightValue
    ) as productCount
from
    categories cat
where
    cat.parentCategoryId = 2;
Run Code Online (Sandbox Code Playgroud)

我最成功的尝试是(我删除了"连接"部分,因此它更具可读性):

def subQuery(c: CategoriesTable.type) = (for {
        p <- ProductsTable

      } yield(p.id.count))
      for {
        c <- CategoriesTable
        if (c.parentId === 2)
      } yield(c.id, c.title, (subQuery(c).asColumn))
Run Code Online (Sandbox Code Playgroud)

这会在子查询中产生缺少括号的SQL:

   select 
    x2.categoryId, 
    x2.title, 
    select count(x3.productId) from products x3 
   from …
Run Code Online (Sandbox Code Playgroud)

scala scalaquery slick

11
推荐指数
1
解决办法
5010
查看次数

为什么Slick在调用take()方法时会生成子查询

我使用Slick 1.0.0-RC1.我有这个表对象的定义:

object ProductTable extends Table[(Int, String, String, String, Double, java.sql.Date, Int, Option[Int], Int, Boolean)]("products") {
  def id = column[Int]("productId", O.PrimaryKey, O.AutoInc)
  def title = column[String]("title")
  def description = column[String]("description")
  def shortDescription = column[String]("shortDescription")
  def price = column[Double]("price")
  def addedDate = column[java.sql.Date]("addedDate")
  def brandId = column[Int]("brandId")
  def defaultImageId = column[Option[Int]]("defaultImageId")
  def visitCounter = column[Int]("visitCounter")
  def archived = column[Boolean]("archived")
  def * = id ~ title ~ description ~ shortDescription ~ price ~ addedDate ~ brandId ~ defaultImageId ~ visitCounter ~ …
Run Code Online (Sandbox Code Playgroud)

sql scala slick

7
推荐指数
1
解决办法
1777
查看次数

如何获得类型

我需要使用如下方法:

DoSomething<(T)>();
Run Code Online (Sandbox Code Playgroud)

但我不知道我有哪种类型,只有类型的对象.如果我只有以下情况,我该如何调用此方法:

Type typeOfGeneric;
Run Code Online (Sandbox Code Playgroud)

c# generics

5
推荐指数
1
解决办法
2万
查看次数

MySql连接器j允许用户变量

请帮助我找出如何允许mysql连接器j定义用户变量并使此代码有效:

    Statement s = conn.createStatement();
    s.executeQuery ("set @categoryId := (Select CategoryId from categories order by CategoryId desc LIMIT 1);\n" +
                        "set @categoryId := IF(@categoryId is Null, 1, @categoryId);");
Run Code Online (Sandbox Code Playgroud)

现在它引发了一个异常:

MySQLSyntaxErrorException occured : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set @categoryId := IF(@categoryId is Null, 1, @categoryId)' at line 2
Run Code Online (Sandbox Code Playgroud)

我知道在.net中你可以在连接字符串中定义"允许用户变量=真"选项.如何在java中做到这一点?

java mysql jdbc

4
推荐指数
1
解决办法
1762
查看次数

3
推荐指数
1
解决办法
2326
查看次数

MyBatis Java和MySql局部变量

我是Java世界的新手。我有一个简单的查询问题:

<insert id="create" parameterType="models.entities.CategoryEntity">

    set @catId := (select categoryId from Categories limit 1);
     insert into Categories(CategoryId, Title, LeftValue, RightValue)
    values(@catId, 'Test in', 1,2);
   ....
</insert>
Run Code Online (Sandbox Code Playgroud)

当我尝试使用mybatis运行它时,它只是失败了:

PersistenceException occured : ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into Categories(CategoryId, Title, LeftValue, RightValue) values(' at line 2 ### The error may involve Category.create-Inline ### The error occurred …
Run Code Online (Sandbox Code Playgroud)

java mysql ibatis jdbc mybatis

3
推荐指数
1
解决办法
5348
查看次数

RESTful URL,用于从垃圾箱还原操作

我一直在实现具有以下操作的RESTful Web服务:

列出文章:

GET     /articles
Run Code Online (Sandbox Code Playgroud)

删除文章(只能将选定的文章删除到垃圾箱中):

DELETE  /articles
Run Code Online (Sandbox Code Playgroud)

列出垃圾箱中的文章:

GET     /trash/articles
Run Code Online (Sandbox Code Playgroud)

我必须执行一项操作,以将“文章”从“ /垃圾箱/文章”还原回“ /文章”。

这是问题。你平时怎么做?我必须使用什么网址?

我想出了两种方法。第一个是:

DELETE  /trash/articles
Run Code Online (Sandbox Code Playgroud)

但是感觉很奇怪,用户可以像“永久删除它,不要还原”那样阅读它。

第二种方法是

PUT     /trash/articles
Run Code Online (Sandbox Code Playgroud)

这更奇怪,并且用户将对该操作的执行感到困惑。

我是REST的新手,所以请建议您通常如何做。我尝试在Google中搜索,但不知道如何正确查询,因此没有得到任何有用的信息。

rest

3
推荐指数
1
解决办法
987
查看次数

标签 统计

scala ×3

slick ×3

c# ×2

java ×2

jdbc ×2

mysql ×2

scalaquery ×2

.net ×1

generics ×1

ibatis ×1

mschart ×1

mybatis ×1

rest ×1

sql ×1