-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtestXMLfunction.java
More file actions
52 lines (43 loc) · 3.38 KB
/
Copy pathtestXMLfunction.java
File metadata and controls
52 lines (43 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package mssql;
import gudusoft.gsqlparser.EDbObjectType;
import gudusoft.gsqlparser.EDbVendor;
import gudusoft.gsqlparser.EFunctionType;
import gudusoft.gsqlparser.TGSqlParser;
import gudusoft.gsqlparser.nodes.*;
import gudusoft.gsqlparser.stmt.TSelectSqlStatement;
import junit.framework.TestCase;
public class testXMLfunction extends TestCase {
public void test1(){
TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmssql);
sqlparser.sqltext = "SELECT p.Demographics.value('declare namespace awns=\"http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey\"; (awns:IndividualSurvey/awns:NumberCarsOwned) [1]',\n" +
" 'int') AS NumberCarsOwned,db1.schema1.func1(arg1)\n" +
"FROM Sales.Customer AS c INNER JOIN\n" +
" Person.Person AS p ON p.BusinessEntityID = c.PersonID INNER JOIN\n" +
" Person.BusinessEntityAddress AS a ON a.BusinessEntityID = p.BusinessEntityID INNER JOIN\n" +
" Person.AddressType AS t ON a.AddressTypeID = t.AddressTypeID INNER JOIN\n" +
" Person.Address AS ad ON ad.AddressID = a.AddressID INNER JOIN\n" +
" Person.EmailAddress AS ea ON ea.BusinessEntityID = p.BusinessEntityID INNER JOIN\n" +
" Person.StateProvince AS sp ON sp.StateProvinceID = ad.StateProvinceID\n" +
"WHERE (c.StoreID IS NULL) AND (t.Name = N'Home') AND (sp.CountryRegionCode = N'US')";
assertTrue(sqlparser.parse() == 0);
TSelectSqlStatement selectSqlStatement = (TSelectSqlStatement)sqlparser.sqlstatements.get(0);
TResultColumn column = selectSqlStatement.getResultColumnList().getResultColumn(0);
TExpression expression = column.getExpr();
TFunctionCall functionCall = expression.getFunctionCall();
//System.out.println(functionCall.getFunctionName().getObjectToken().toString());
assertTrue(functionCall.getFunctionType() == EFunctionType.xmlvalue_t);
assertTrue(functionCall.getFunctionName().getObjectToken().toString().equalsIgnoreCase("p"));
TExpressionCallTarget callTarget = functionCall.getCallTarget();
assertTrue(callTarget.getExpr().toString().equalsIgnoreCase("p.Demographics"));
TResultColumn column1 = selectSqlStatement.getResultColumnList().getResultColumn(1);
TExpression expression1 = column1.getExpr();
TFunctionCall functionCall1 = expression1.getFunctionCall();
//System.out.println(functionCall1.getFunctionName().getObjectToken().toString());
assertTrue(functionCall1.getFunctionName().getObjectToken().getDbObjType() == TObjectName.ttobjFunctionName);
//System.out.println(functionCall1.getFunctionName().getSchemaString().toString());
assertTrue(functionCall1.getFunctionName().getSchemaToken().getDbObjType() == TObjectName.ttobjSchemaName);
// System.out.println(functionCall1.getFunctionName().getDatabaseToken().toString());
//assertTrue((functionCall1.getFunctionName().getDatabaseToken().getDbObjType() == TObjectName.ttobjDatabaseName));
assertTrue(functionCall1.getFunctionName().getDatabaseToken().getDbObjectType() == EDbObjectType.database);
}
}