1*c3ab0d6aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c3ab0d6aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c3ab0d6aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c3ab0d6aSAndrew Rist * distributed with this work for additional information 6*c3ab0d6aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c3ab0d6aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c3ab0d6aSAndrew Rist * "License"); you may not use this file except in compliance 9*c3ab0d6aSAndrew Rist * with the License. You may obtain a copy of the License at 10*c3ab0d6aSAndrew Rist * 11*c3ab0d6aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*c3ab0d6aSAndrew Rist * 13*c3ab0d6aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c3ab0d6aSAndrew Rist * software distributed under the License is distributed on an 15*c3ab0d6aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c3ab0d6aSAndrew Rist * KIND, either express or implied. See the License for the 17*c3ab0d6aSAndrew Rist * specific language governing permissions and limitations 18*c3ab0d6aSAndrew Rist * under the License. 19*c3ab0d6aSAndrew Rist * 20*c3ab0d6aSAndrew Rist *************************************************************/ 21*c3ab0d6aSAndrew Rist 22*c3ab0d6aSAndrew Rist 23cdf0e10cSrcweir package complex.connectivity.dbase; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 26cdf0e10cSrcweir import com.sun.star.sdbc.*; 27cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 29cdf0e10cSrcweir import complex.connectivity.TestCase; 30cdf0e10cSrcweir import complex.connectivity.SubTestCase; 31cdf0e10cSrcweir 32cdf0e10cSrcweir public class DBaseSqlTests extends SubTestCase 33cdf0e10cSrcweir { 34cdf0e10cSrcweir private final XMultiServiceFactory m_xORB; 35cdf0e10cSrcweir DBaseSqlTests(final XMultiServiceFactory _xORB,final TestCase i_testCase)36cdf0e10cSrcweir public DBaseSqlTests(final XMultiServiceFactory _xORB,final TestCase i_testCase) 37cdf0e10cSrcweir { 38cdf0e10cSrcweir super( i_testCase ); 39cdf0e10cSrcweir m_xORB = _xORB; 40cdf0e10cSrcweir } 41cdf0e10cSrcweir testFunctions()42cdf0e10cSrcweir public void testFunctions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException 43cdf0e10cSrcweir { 44cdf0e10cSrcweir final XRowSet xRowRes = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, 45cdf0e10cSrcweir m_xORB.createInstance("com.sun.star.sdb.RowSet")); 46cdf0e10cSrcweir 47cdf0e10cSrcweir getLog().println("starting SQL test"); 48cdf0e10cSrcweir // set the properties needed to connect to a database 49cdf0e10cSrcweir final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); 50cdf0e10cSrcweir xProp.setPropertyValue("DataSourceName", "Bibliography"); 51cdf0e10cSrcweir xProp.setPropertyValue("CommandType", Integer.valueOf(com.sun.star.sdb.CommandType.COMMAND)); 52cdf0e10cSrcweir 53cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" like 'B%'"); 54cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" like 'B%'"); 55cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" not like 'B%'"); 56cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not(0 = 1)"); 57cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 = 0"); 58cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (0 = 0)"); 59cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 <> 1"); 60cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 < 1"); 61cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 2 > 1"); 62cdf0e10cSrcweir execute(xRowRes,"1,1+1,'a' + 'b' FROM \"biblio\" \"biblio\" where 2 > 1"); 63cdf0e10cSrcweir // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (0 = 0) is true"); 64cdf0e10cSrcweir // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not (0 = 0) is not true"); 65cdf0e10cSrcweir // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 1 between 0 and 2"); 66cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" is NULL"); 67cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" is not NULL"); 68cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" = \"Identifier\""); 69cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not(not(\"Identifier\" = \"Identifier\"))"); 70cdf0e10cSrcweir execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (1 = 1 and 2 = 1) or 3 = 33 or 4 = 44 or ('a' = 'a' and 'b' = 'b')"); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir execute(final XRowSet xRowRes, String sql)73cdf0e10cSrcweir private void execute(final XRowSet xRowRes, String sql) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException 74cdf0e10cSrcweir { 75cdf0e10cSrcweir try 76cdf0e10cSrcweir { 77cdf0e10cSrcweir final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); 78cdf0e10cSrcweir xProp.setPropertyValue("Command", "SELECT " + sql); 79cdf0e10cSrcweir xRowRes.execute(); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir catch(SQLException e) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir getLog().println(sql + " Error: " + e.getMessage()); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir } 89