This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-24
Channels
- # aws (14)
- # beginners (111)
- # boot (12)
- # cider (1)
- # cljsrn (7)
- # clojure (65)
- # clojure-dusseldorf (1)
- # clojure-germany (7)
- # clojure-greece (10)
- # clojure-italy (13)
- # clojure-poland (7)
- # clojure-russia (7)
- # clojure-spec (53)
- # clojure-uk (29)
- # clojurescript (27)
- # community-development (9)
- # cursive (2)
- # data-science (1)
- # datomic (17)
- # emacs (16)
- # events (6)
- # fulcro (155)
- # graphql (8)
- # instaparse (1)
- # leiningen (30)
- # lumo (29)
- # om-next (3)
- # other-languages (46)
- # pedestal (11)
- # portkey (7)
- # re-frame (13)
- # reagent (6)
- # ring (8)
- # rum (1)
- # shadow-cljs (75)
- # sql (1)
- # timbre (3)
- # unrepl (128)
Hi, I tried to do something like this in jdbc and get an Exception:
(j/db-do-prepared (:user-db @g-config) ["select
case
when (select 1 from user_favorstocks where uid=1823 and stockid='600123.SH') is not null
then (select 8)
else (select 5)
end as tmp"])
SQLException SQL String can not be NULL com.mysql.jdbc.SQLError.createSQLException (SQLError.java:957)
@cmal, don't you need to prepare the statement first?
The sql parameter can either be a SQL string or a PreparedStatement.
in clojure.java.jdbc doc
(deftest test-do-prepared4
(doseq [db (test-specs)]
(create-test-table :fruit2 db)
(sql/db-do-prepared db ["INSERT INTO fruit2 ( name, appearance, cost, grade ) VALUES ( ?, ?, ?, ? )" ["test" "test" 1 1.0] ["two" "two" 2 2.0]] {:multi? true})
(is (= 2 (sql/query db ["SELECT * FROM fruit2"] {:result-set-fn count})))))
maybe you're looking for execute!
?
SQLException Can not issue executeUpdate() or executeLargeUpdate() for SELECTs com.mysql.jdbc.SQLError.createSQLException (SQLError.java:957)
if I change to execute!
ah you need query
execute!
is only for "write"-y queries (INSERT, UPDATE, etc.)
I am just trying to select something from the table, and if found, check the value of some column ( and if satisfied some condition do update, otherwise nothing ), if not ,do insert. And return a value that tells me what has been done.
you're shifting the goalposts
better to ask one thing at a time, not "everything I've always wanted to know about SQL"
you can't nest INSERT inside of a compound statement - you'll need to do multiple queries, or use a stored procedure I think
I tried to write a stored procedure but ERROR 1548 (HY000): Cannot load from mysql.proc. The table is probably corrupted
happens. But it is not right to ask this here. It seems the mysql version is too old. some 5.1
version.
@dominicm maybe this? https://github.com/clojurebook/ClojureProgramming/tree/master/ch09-annotations
I want to use migratus
in my dev environment.
I also use environ
to manage environments variables.
How can I set a value in my project.clj
by evaluating data from environ
?
working example:
clojure
:migratus {:store :database
:migration-dir "migrations"
:db ""}
What I want:
clojure
:migratus {:store :database
:migration-dir "migrations"
:db ~(environ.core/env :db-url)}
Can (let [...] (defn ...))
be problematic?
(generally I'd never do that, but from time to time I need some dynamism e.g. defns emitted from macros)
Not that I know of; (def fname (let [,,,] (fn ,,,)))
may be more conventional
I’m using stuartsierra component and can’t figure out how to fix this error anyhow. any hints would be much appreciated:
IllegalArgumentException No implementation of method: :stop of protocol: #'com.stuartsierra.component/Lifecycle found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:568)
this is my application:
(ns application.system
(:require [application.web :refer [app]]
[com.stuartsierra.component :as component]
[org.httpkit.server :refer [run-server]]))
(defn- start-server [handler port]
(run-server app {:port port})
(println "Started server on localhost" port))
(defn- stop-server [server]
(when server
(server)))
(defrecord Application []
component/Lifecycle
(start [this]
(assoc this :server (start-server #'app 9009)))
(stop [this]
(stop-server (:server this))
(dissoc this :server)))
(defn create-system []
(Application.))
(defn -main [& args]
(.start (create-system)))
@bravilogy that error means one of your components returns nil instead of a valid component
(probably from a start method)
how would I know?
one of your components, when started, returns nil instead of a component
that's what causes that error
unless you call stop on the wrong object and it was not your component in the first place
OK - nothing in that code is calling the stop method
who calls the stop method?
I don't know component at all, but should 'start-server' return anything? It's returning nil at the moment.
@the2bears that's the error, good eye
@bravilogy - println returns nil, so start-server returns nil
we still don't know what is calling stop, but that's what is causing the error
is there a clojure builtin for "take this vec of 5 elements, pad it to a list of 10 elemes by adding :null" 's ?
no builtin, I'd use concat and repeat (concat coll (repeat 5 nil)) or (take 10 (concat coll (repeat nil)))