You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SQLDialectMSSQL.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2012 Alex Telepov.
  3. * Copyright 2012 James Moger.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.iciql;
  18. /**
  19. * MS SQL Server database dialect.
  20. */
  21. public class SQLDialectMSSQL extends SQLDialectDefault {
  22. @Override
  23. public String extractColumnName(String name) {
  24. return super.extractColumnName(name).replace('[', ' ').replace(']', ' ').trim();
  25. }
  26. /**
  27. * Append limit and offset rows
  28. *
  29. * @param stat Statement
  30. * @param limit Limit rows
  31. * @param offset Offset rows
  32. */
  33. @Override
  34. public void appendLimitOffset(SQLStatement stat, long limit, long offset) {
  35. if (offset > 0) {
  36. throw new IciqlException("iciql does not support offset for MSSQL dialect!");
  37. }
  38. StringBuilder query = new StringBuilder(stat.getSQL());
  39. // for databaseVersion >= 2012 need Offset
  40. if (limit > 0) {
  41. int indexSelect = query.indexOf("SELECT");
  42. if (indexSelect >= 0) {
  43. StringBuilder subPathQuery = new StringBuilder(" TOP ");
  44. subPathQuery.append(Long.toString(limit));
  45. query.insert(indexSelect + "SELECT".length(), subPathQuery);
  46. stat.setSQL(query.toString());
  47. }
  48. }
  49. }
  50. }