I can't get the syntax here; are there some more extensive examples for POCO-SQLite ?
I am getting a Poco::exception,
sendErrorResponse HTTP_INTERNAL_SERVER_ERROR
Poco::Data::SQLite::Connector::registerConnector();
// create a new session
Session updsession("SQLite", managers);
facilities UnitFacility;
Statement updateRecord(updsession);
updsession << "UPDATE facilities SET name = nameString, address = addressString, phone = phoneString WHERE facilityNumber = 3;";
updateRecord.execute();
//Updated: Simplified With or without [] still no go.
Poco::Data::SQLite::Connector::registerConnector();
Session updsession("SQLite", managers);
Statement updateRecord(updsession);
updsession << "UPDATE facilities SET Name = 'Frank' WHERE [FacilityNumber = 1];",now;
updateRecord.execute();
Both SQL queries are invalid.
Original Query:
UPDATE facilities SET name = nameString, address = addressString, phone = phoneString WHERE facilityNumber = 3
Result:
no such column: nameString: UPDATE facilities SET name = nameString, address = addressString, phone = phoneString WHERE facilityNumber = 3
Fixed query:
UPDATE facilities SET name = 'nameString', address = 'addressString', phone = 'phoneString' WHERE facilityNumber = 3
Result:
Query executed successfully: UPDATE facilities SET name = 'nameString', address = 'addressString', phone = 'phoneString' WHERE facilityNumber = 3 (took 0ms, 1 rows affected)
Original query:
UPDATE facilities SET Name = 'Frank' WHERE [FacilityNumber = 1]
Result:
no such column: FacilityNumber = 1: UPDATE facilities SET Name = 'Frank' WHERE [FacilityNumber = 1]
Fixed query:
UPDATE facilities SET Name = 'Frank' WHERE FacilityNumber = 1
Result:
Query executed successfully: UPDATE facilities SET Name = 'Frank' WHERE FacilityNumber = 1 (took 0ms, 1 rows affected)
It is not clear what does this question have to do with HTTP.
Related
I am just starting to work with openedge and I need to join information from two tables but I just need the first row from the second one.
Basically I need to do a typical SQL Cross Apply but in progress. I look in the documentation and the Statement FETCH FIRST 10 ROWS ONLY only in OpenEdge 11.
My query is:
SELECT * FROM la_of PUB.la_ofart ON la_of.empr_cod = la_ofart.empr_cod
AND la_of.Cod_Ordf = la_ofart.Cod_Ordf
AND la_of.Num_ordex = la_ofart.Num_ordex AND la_of.Num_partida = la_ofart.Num_partida
CROSS APPLY (
SELECT TOP 1 ofart.Cod_Ordf AS Cod_Ordf_ofart ,
ofart.Num_ordex AS Num_ordex_ofart
FROM la_ofart AS ofart
WHERE ofart.empr_cod = la_ofart.empr_cod
AND ofart.Num_partida = la_ofart.Num_partida
AND la_ofart.doc1_num = ofart.doc1_num
AND la_ofart.doc2_linha = ofart.doc2_linha
ORDER BY ofart.Cod_Ordf DESC) ofart
I am using SSMS to extract data from OE10 using an ODBC connector and querying to OE using OpenQuery.
Thanks for all help.
If I correctly understood your question, maybe you can use something like this. Maybe this isn't the best solution for your problem, but may suit your needs.
DEF BUFFER ofart FOR la_ofart.
DEF TEMP-TABLE tt-ofart NO-UNDO LIKE ofart
FIELD seq AS INT
INDEX ch-seq
seq.
DEF VAR i-count AS INT NO-UNDO.
EMPTY TEMP-TABLE tt-ofart.
blk:
FOR EACH la_ofart NO-LOCK,
EACH la_of NO-LOCK
WHERE la_of.empr_cod = la_ofart.empr_cod
AND la_of.Cod_Ordf = la_ofart.Cod_Ordf
AND la_of.Num_ordex = la_ofart.Num_ordex
AND la_of.Num_partida = la_ofart.Num_partida,
EACH ofart NO-LOCK
WHERE ofart.empr_cod = la_ofart.empr_cod
AND ofart.Num_partida = la_ofart.Num_partida
AND ofart.doc1_num = la_ofart.doc1_num
AND ofart.doc2_linha = la_ofart.doc2_linha
BREAK BY ofart.Cod_Ordf DESCENDING:
ASSIGN i-count = i-count + 1.
CREATE tt-ofart.
BUFFER-COPY ofart TO tt-ofart
ASSIGN ofart.seq = i-count.
IF i-count >= 10 THEN
LEAVE blk.
END.
FOR EACH tt-ofart USE-INDEX seq:
DISP tt-ofart WITH SCROLLABLE 1 COL 1 DOWN NO-ERROR.
END.
In my entity I have this field
#ElementCollection
#CollectionTable
#MapKeyColumn(name = "SERVER_ID")
#Column(name = "IS_SYNC")
private Map<String, Boolean> serverSyncs = new HashMap<>();
I'm trying to get all entities of my table that do not have an entry with the key equals to "serverId" (passed as parameter in my function) or that have an entry but the value is false.
This is what I've done for now
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<T> criteriaQuery = builder.createQuery(clazz);
Root<T> root = criteriaQuery.from(clazz);
MapJoin<T, String, Boolean> mapRoot = root.joinMap("serverSyncs");
List<T> result = session.createQuery(
criteriaQuery.where(
builder.or(
mapRoot.isNull(),
builder.not(mapRoot.key().in(serverId)),
builder.and(
mapRoot.key().in(serverId),
mapRoot.value().in(false)
)
)
)
).list();
The thing is I get this error on my query
Could not locate CollectionPersister for role : ca.tecsar.core.model.AbstractServerEntity.serverSyncs
Question is : how can I achieve what I want with JPA 2.0 Criteria?
Example of what I need to retrieve
id|SERVER_ID|IS_SYNC
1|0000000001|true
1|0000000002|false
2|0000000003|false
If I ask for SERVER_ID = 3,I should get entity 1 and 2
If I ask for SERVER_ID = 2,I should get entity 1
If I ask for SERVER_ID = 1,I should get nothing
So I couldn't do it with JPA 2 Criteria but I've succeeded with a SQL Query. I have a table named PUNCH and the map table is PUNCH_SERVERSYNCS.
SELECT p.PUNCHID
FROM PUNCH p
LEFT JOIN PUNCH_SERVERSYNCS pss
ON p.PUNCHID = pss.PUNCH_PUNCHID
WHERE (pss.IS_SYNC = false AND pss.SERVER_ID = 'Server2')
OR NOT EXISTS (SELECT p.PUNCHID FROM PUNCH_SERVERSYNCS pss2 WHERE
pss2.PUNCH_PUNCHID = p.PUNCHID AND pss2.SERVER_ID = 'Server2')
GROUP BY p.PUNCHID
Am working with Web2py and sqlite Db in Ubuntu. Iweb2py, a user input posts an item into an sqlite DB such as 'Hello World' as follows:
In the controller default the item is posted into ThisDb as follows:
consult = db.consult(id) or redirect(URL('index'))
form1 = [consult.body]
form5 = form1#.split()
name3 = ' '.join(form5)
conn = sqlite3.connect("ThisDb.db")
c = conn.cursor()
conn.execute("INSERT INTO INPUT (NAME) VALUES (?);", (name3,))
conn.commit()
Another code picks or should read the item from ThisDb, in this case 'Hello World' as follows:
location = ""
conn = sqlite3.connect("ThisDb.db")
c = conn.cursor()
c.execute('select * from input')
c.execute("select MAX(rowid) from [input];")
for rowid in c:break
for elem in rowid:
m = elem
c.execute("SELECT * FROM input WHERE rowid = ?", (m,))
for row in c:break
location = row[1]
name = location.lower().split()
my DB configuration for the table 'input' where Hello World' should be read from is this:
CREATE TABLE `INPUT` (
`NAME` TEXT
);
This code previously workd well while coding with windows7 and 10 but am having this problem ion Ubuntu 16.04. And I keep getting this error:
File "applications/britamintell/modules/xxxxxx/define/yyyy0.py", line 20, in xxxdefinition
location = row[1]
IndexError: tuple index out of range
row[0] is the value in the first column.
row[1] is the value in the second column.
Apparently, your previous database had more than one column.
I am fetching data from SQLite database using following query:
SELECT p.sent,
e.*,
e.no _id
FROM ecare e
LEFT OUTER JOIN pweb p ON e.h_id = p.h_id
WHERE (ant = 'N' or ant = 'D')
GROUP BY e.h_id
ORDER BY p.sent
By using the above SQLite query, I am getting all the records belonging to sent (where sent = 1 and sent = 0).
Now, I would like to get only those records from database, where sent status is sent = 0. (In short, I don't want to fetch all the records belonging to sent, or records where sent = 1).
Have you tried with below query ?
SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON
e.h_id=p.h_id WHERE (ant = 'N' or ant = 'D') AND p.sent = '0' GROUP
BY e.h_id
Check below query for your question:
return db.rawQuery("SELECT p.sent,e.*, e.no _id from ecare e LEFT OUTER JOIN pweb p ON e.h_id=p.h_id WHERE (ant = 'N' or ant = 'D') AND p.sent = '1' GROUP BY e.h_id ORDER BY p.sent ", null);
You are already filtering on the ant column.
Adding a filter for sent works the same way:
SELECT ...
...
WHERE (ant = 'N' OR ant = 'D')
AND sent = 0
...
Guys I have such a problem.
I know how to write a good select statement but I have no idea how to turn it into a corresponding update.
Im still learning plsql
Here is my select
select * --count(*)
from POLISY_OT ot
join polisy p on p.poli_id = ot.ot_poli_id
join sou.rai_skl rs on rs.ot_id = ot.ot_id
where ot_under_promil = 0
and ot_skladka_rok <> ot_skladka_netto_rok
and ot_rodzaj_um = 'OP'
and ot_rodzaj = 'D'
and ot_produkt_id = 17
and p.poli_status in ('AK', 'CZ')
and rs.skl_roczna = ot.ot_skladka_rok;
now I would like to wrap it up with an update and create something like this
update (
select * --count(*)
from POLISY_OT ot
join polisy p on p.poli_id = ot.ot_poli_id
join sou.rai_skl rs on rs.ot_id = ot.ot_id
where ot_under_promil = 0
and ot_skladka_rok <> ot_skladka_netto_rok
and ot_rodzaj_um = 'OP'
and ot_rodzaj = 'D'
and ot_produkt_id = 17
and p.poli_status in ('AK', 'CZ')
and rs.skl_roczna = ot.ot_skladka_rok)
set ot_skladka_rok = ot_skladka_netto_rok;
First, I really hope you aren't a student asking for homework help. That really bugs me.
On the assumption it's not, it's a little hard to tell exactly which columns belong to which tables, given that you didn't include the table aliases throughout.
I read this as that you wanted to update a column based on the value in another table, restricting the table updates to records that match a third table).
So I think you want something like this:
UPDATE polisy_ot ot
SET ot_skladka_rok =
(SELECT ot_skladka_netto_rok
FROM sou.rai_skl rs
WHERE rs.ot_id = ot.ot_id
AND rs.skl_roczna = ot.ot_skladka_rok)
WHERE ot_under_promil = 0
AND ot_skladka_rok <> ot_skladka_netto_rok
AND ot_rodzaj_um = 'OP'
AND ot_rodzaj = 'D'
AND ot_produkt_id = 17
AND EXISTS (SELECT NULL
FROM polisy p
WHERE p.poli_id = ot.ot_poli_id
AND p.poli_status IN ('AK', 'CZ'))
Good luck,
Stew