Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CDOQuery sql delete statement
CDOQuery sql delete statement [message #1276347] Mon, 24 March 2014 12:44 Go to next message
Areq Novak is currently offline Areq NovakFriend
Messages: 12
Registered: March 2014
Junior Member
Hi,

String query = "delete from art where cdo_id = '"
+ id + "'";

CDOSession cdoSession = standaloneCDOAc.openSession();
CDOTransaction transaction = cdoSession.openTransaction();
CDOQuery cqo = transaction.createQuery("sql", query);
System.out.println(cqo.getResultValue());

it doesn't works (with sql select work ok)

How may I delete something from db ?
Re: CDOQuery sql delete statement [message #1276357 is a reply to message #1276347] Mon, 24 March 2014 12:57 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 24.03.2014 13:44, schrieb Areq Novak:
> Hi,
>
> String query = "delete from art where cdo_id = '"
> + id + "'";
> CDOSession cdoSession = standaloneCDOAc.openSession();
> CDOTransaction transaction = cdoSession.openTransaction();
> CDOQuery cqo = transaction.createQuery("sql", query);
For safety reasons you must explicitely enable non-query statements:

cqo.setParameter("queryStatement", false);

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> System.out.println(cqo.getResultValue());
>
> it doesn't works (with sql select work ok)
>
> How may I delete something from db ?


Re: CDOQuery sql delete statement [message #1276373 is a reply to message #1276357] Mon, 24 March 2014 13:23 Go to previous messageGo to next message
Areq Novak is currently offline Areq NovakFriend
Messages: 12
Registered: March 2014
Junior Member
String query = "delete from art where cdo_id = '"
+ id + "'";

CDOSession cdoSession = standaloneCDOAc.openSession();
CDOTransaction transaction = cdoSession.openTransaction();
CDOQuery cqo = transaction.createQuery("sql", query);
cqo.setParameter("queryStatement", false);
System.out.println(cqo.getResultValue());

it doesn't work...
Re: CDOQuery sql delete statement [message #1276525 is a reply to message #1276373] Mon, 24 March 2014 17:36 Go to previous messageGo to next message
Areq Novak is currently offline Areq NovakFriend
Messages: 12
Registered: March 2014
Junior Member
Do you have any other ideas ? (Functionality such as delete/update is very important for me, at the moment only select works ok...)
Re: CDOQuery sql delete statement [message #1276535 is a reply to message #1276525] Mon, 24 March 2014 17:50 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 24.03.2014 18:36, schrieb Areq Novak:
> Do you have any other ideas ? (Functionality such as delete/update is very important for me, at the moment only select
> works ok...)
It's supposed to work the way I described. If it doesn't please describe in detail what happens instead. Please paste
the error messages, stack traces and everything that may help me to find the cause.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: CDOQuery sql delete statement [message #1276542 is a reply to message #1276535] Mon, 24 March 2014 18:03 Go to previous messageGo to next message
Areq Novak is currently offline Areq NovakFriend
Messages: 12
Registered: March 2014
Junior Member
Ok,, thanks.
I don't have any errors... after executing this code.
Unfortunately this record still exist in database, so it is strange situation.
cqo.getResultValue() returned - 1 (syso)

[Updated on: Mon, 24 March 2014 18:14]

Report message to a moderator

Re: CDOQuery sql delete statement [message #1276551 is a reply to message #1276542] Mon, 24 March 2014 18:11 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 24.03.2014 19:03, schrieb Areq Novak:
> Ok,, thanks.
> I don't have any errors... after executing this code. Unfortunately this record still exist in database, so it is
> strange situation.
Ok, the best I can suggest then is that you submit a bugzilla. Maybe you can copy&adjust one of our many test cases to
demo the problem?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: CDOQuery sql delete statement [message #1276941 is a reply to message #1276347] Tue, 25 March 2014 08:44 Go to previous message
Areq Novak is currently offline Areq NovakFriend
Messages: 12
Registered: March 2014
Junior Member
This code works ok:

String query = "select * from eve_art where cdo_id = '"
+ id + "'";
StandaloneCDOAccess standaloneCDOAccess = new StandaloneCDOAccess();
CDOSession cdoSession = standaloneCDOAccess.openSession();
CDOTransaction transaction = cdoSession.openTransaction();
CDOQuery cqo = transaction.createQuery("sql", query);
EObject object = cqo.getResultValue(clazz);


but this code works wrong (a lack of change in db):

String query = "delete from eve_art where cdo_id = '"
+ uid + "'";
StandaloneCDOAccess standaloneCDOAccess = new StandaloneCDOAccess();
CDOSession cdoSession = standaloneCDOAccess.openSession();
CDOTransaction transaction = cdoSession.openTransaction();
CDOQuery cqo = transaction.createQuery("sql", query);
cqo.setParameter("queryStatement", false);
System.out.println("!! " + cqo.getResult().get(0));

syso returned 1, record still exist in db


init and openSession from StandaloneCDOAccess :

private void init()
{
OMPlatform.INSTANCE.setDebugging(false);
OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);

IManagedContainer container = ContainerUtil.createContainer();
Net4jUtil.prepareContainer(container);
TCPUtil.prepareContainer(container);
CDONet4jUtil.prepareContainer(container);
container.activate();

IConnector connector = TCPUtil.getConnector(container, StandaloneCDOServer.DEFAULT_SERVER_ADDRESS);

configuration = CDONet4jUtil.createNet4jSessionConfiguration();
configuration.setConnector(connector);
configuration.setRepositoryName("opencoss");
}


public CDOSession openSession()
{
CDOSession session = configuration.openNet4jSession();

for (EPackage ePackage : getEPackages()) {
session.getPackageRegistry().putEPackage(ePackage);
}

return session;
}
Previous Topic:CDOQuery - update sql
Next Topic:GenModel - Java 8 support
Goto Forum:
  


Current Time: Thu Apr 25 06:18:13 GMT 2024

Powered by FUDForum. Page generated in 0.03212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top