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 30 public class DBaseSqlTests 31 { 32 private final XMultiServiceFactory m_xORB; 33 DBaseSqlTests(final XMultiServiceFactory _xORB)34 public DBaseSqlTests(final XMultiServiceFactory _xORB) 35 { 36 m_xORB = _xORB; 37 } 38 testFunctions()39 public void testFunctions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException 40 { 41 final XRowSet xRowRes = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, 42 m_xORB.createInstance("com.sun.star.sdb.RowSet")); 43 44 System.out.println("starting SQL test"); 45 // set the properties needed to connect to a database 46 final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); 47 xProp.setPropertyValue("DataSourceName", "Bibliography"); 48 xProp.setPropertyValue("CommandType", Integer.valueOf(com.sun.star.sdb.CommandType.COMMAND)); 49 50 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" like 'B%'"); 51 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" like 'B%'"); 52 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" not like 'B%'"); 53 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not(0 = 1)"); 54 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 = 0"); 55 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (0 = 0)"); 56 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 <> 1"); 57 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 < 1"); 58 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 2 > 1"); 59 execute(xRowRes,"1,1+1,'a' + 'b' FROM \"biblio\" \"biblio\" where 2 > 1"); 60 // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (0 = 0) is true"); 61 // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not (0 = 0) is not true"); 62 // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 1 between 0 and 2"); 63 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" is NULL"); 64 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" is not NULL"); 65 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" = \"Identifier\""); 66 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not(not(\"Identifier\" = \"Identifier\"))"); 67 execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (1 = 1 and 2 = 1) or 3 = 33 or 4 = 44 or ('a' = 'a' and 'b' = 'b')"); 68 } 69 execute(final XRowSet xRowRes, String sql)70 private void execute(final XRowSet xRowRes, String sql) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException 71 { 72 try 73 { 74 final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); 75 xProp.setPropertyValue("Command", "SELECT " + sql); 76 xRowRes.execute(); 77 } 78 catch(SQLException e) 79 { 80 System.err.println(sql + " Error: " + e.getMessage()); 81 } 82 } 83 84 85 } 86