简体   繁体   English

Clojure.java.jdbc基于查询结构返回日期时间更改的类型

[英]Clojure.java.jdbc return type for datetime changes based on query structure

I have a Korma based software stack that constructs fairly complex queries against a MySQL database. 我有一个基于Korma的软件堆栈,可以针对MySQL数据库构建相当复杂的查询。 I noticed that when I am querying for datetime columns, the type that I get back from the Korma query changes depending on the syntax of the SQL query being generated. 我注意到,当我查询datetime列时,我从Korma查询返回的类型会根据生成的SQL查询的语法而改变。 I've traced this down to the level of clojure.java.jdbc/query. 我已将其追溯到clojure.java.jdbc / query的级别。 If the form of the query is like this: 如果查询的形式是这样的:

select modified from docs order by modified desc limit 10

then I get back maps corresponding to each database row in which :modified is a java.sql.Timestamp . 然后我找回对应于每个数据库行的映射,其中:modifiedjava.sql.Timestamp However, sometimes our query generator generates more complex union queries, such that we need to apply an order by ... limit ... constraint to the final result of the union. 但是,有时我们的查询生成器会生成更复杂的联合查询,因此我们需要order by ... limit ...约束对联合的最终结果应用order by ... limit ... Korma does this by wrapping the query in parentheses. Korma通过将查询包装在括号中来完成此操作。 Even with only a single subquery--ie, a simple parenthesized select--so long as we add an "outer" order by ... , the type of :modified changes. 即使只有一个子查询 - 即简单的括号选择 - 只要我们order by ...添加“外部” order by ... ,其类型:modified更改。

(select modified from docs order by modified desc limit 10) order by modified desc

In this case, clojure.java.jdbc/query returns :modified values as strings. 在这种情况下, clojure.java.jdbc/query:modified值作为字符串返回。 Some of our higher level code isn't expecting this, and gets exceptions. 我们的一些高级代码不期望这样,并获得例外。

We're using a fork of Korma, which is using an old (0.3.7) version of clojure.java.jdbc . 我们正在使用Korma的一个分支,它使用旧的(0.3.7)版本的clojure.java.jdbc I can't tell if the culprit is clojure.java.jdbc or java.jdbc or MySQL. 我不知道罪魁祸首是clojure.java.jdbc还是java.jdbc或MySQL。 Anyone seen this and have ideas on how to fix it? 有人看过这个,并有关于如何解决它的想法?

Moving to the latest jdbc in a similar situation changed several other things for us and was a decidedly "non-trvial" task. 在类似的情况下移动到最新的jdbc改变了我们的其他几件事,并且是一个明确的“非平凡”任务。 I would suggest getting off of a korma fork soon and then debugging this. 我建议很快离开korma前叉然后再调试一下。

For us the changes focused around what korma returned on update calls changed between the verions of the backing jdbc. 对于我们来说,更改集中在korma在更新调用上返回的内容在支持jdbc的版本之间发生了变化。 It was well worth getting current even though it's a moderately painful process. 尽管这是一个中等痛苦的过程,但值得获得最新动态。

Getting current with jdbc will give you fresh new problems! 通过jdbc获取最新信息将为您带来新的问题! best of luck with this :-) These things tend to be fairly specific to the DB server you are using. 祝你好运:-)这些东西往往与你正在使用的数据库服务器相当具体。

Other options for you is to have a policy of aways specifying an order-by parameter or building a library to coerce the strings into dates. 您可以使用其他选项来指定一个指定order-by参数的策略,或者构建一个库以将字符串强制转换为日期。 Both of these have some long term technical dept problems. 这些都有一些长期的技术部门问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM