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