Commit 83187a5b authored by Elemer Lelik's avatar Elemer Lelik
Browse files

Update to R5B

parent c926ebe3
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014 Ericsson
Copyright (c) 2015 Ericsson
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
......@@ -10,10 +10,8 @@
File: SQLasp_CNL113760.tpd
Description: tpd project file
Rev: R4A
Rev: R5B
Prodnr: CNL 113 760
Updated: 2014-09-24
Contact: http://ttcn.ericsson.se
-->
<TITAN_Project_File_Information version="1.0">
......
No preview for this file type
......@@ -14,7 +14,7 @@
//
// File: SQL.grp
// Description:
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
//
......
......@@ -13,7 +13,7 @@
//
// File: SQL_Functions.ttcn
// Description:
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
//
......@@ -539,6 +539,6 @@ private external function ef_SQL_strcmp(in charstring pl_string1, in charstring
}//end of module
with {
extension "version R4A"
extension "version R5B"
}
......@@ -13,7 +13,7 @@
//
// File: SQL_MySQL_interface.cc
// Description: SQL test port source
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
......
/******************************************************************************
* Copyright (c) 2012, 2014 Ericsson AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Gabor Szalai - initial implementation and initial documentation
* Zoltan Medve
* Janos Kovesdi
******************************************************************************/
//
// File: SQL_MySQL_interface.cc
// Description: SQL test port source
// Rev: R5B
// Prodnr: CNL 113 760
//
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <stdio.h>
#include <string>
#include <vector>
#include "SQL_interface.hh"
#include "memory.h"
#include "occi.h"
using namespace oracle::occi;
using namespace std;
namespace SQL_engine{
SQL_engine_base* new_OraSQl_engine();
}
static const SQL_engine::SQL_Engine_register_data OraSQL_register_data=SQL_engine::SQL_Engine_register_data(SQL_engine::OraSQL_engine,&SQL_engine::new_OraSQl_engine);
static const SQL_engine::SQL_registrator local_iff=SQL_engine::SQL_registrator(&OraSQL_register_data);
namespace SQL_engine{
class SQL_OraSQL_engine: public SQL_engine_base{
public:
Environment *env;
Connection *conn;
int state; // 0- not conencted
// 1- Connected, mysql_close must be called.
virtual int open_database_connection(const SQL_config_data*, SQL_error&);
virtual int execute_sql_command(const unsigned char* sql,
const unsigned long sql_length,
SQL_result_data& sql_res,
SQL_error&);
virtual int close_database_connection(SQL_error&);
SQL_OraSQL_engine();
virtual ~SQL_OraSQL_engine();
void clean_up();
};
void SQL_OraSQL_engine::clean_up(){
if(conn){
env->terminateConnection(conn);
conn=NULL;
}
if(env){
Environment::terminateEnvironment(env);
env=NULL;
}
state=0;
}
SQL_OraSQL_engine::SQL_OraSQL_engine(){
engine=OraSQL_engine;
state=0;
env=NULL;
conn=NULL;
}
SQL_OraSQL_engine::~SQL_OraSQL_engine(){
if(state){
clean_up();
}
}
int SQL_OraSQL_engine::open_database_connection(const SQL_config_data* config_data, SQL_error& err){
string connstr="";
string user="";
string passwd="";
string char_set="UTF8";
string nchar_set="UTF8";
log(SQLTP_LOG_DEBUG,"Creating new database connection.");
log(SQLTP_LOG_DEBUG,"Parse parameters.");
int i=0;
while(config_data[i].name){
if(!strcasecmp(config_data[i].name,"connection_string")){
connstr=config_data[i].value;
} else
if(!strcasecmp(config_data[i].name,"user")){
user=config_data[i].value;
} else
if(!strcasecmp(config_data[i].name,"password")){
passwd=config_data[i].value;
} else
if(!strcasecmp(config_data[i].name,"char_set")){
char_set=config_data[i].value;
}
if(!strcasecmp(config_data[i].name,"nchar_set")){
nchar_set=config_data[i].value;
}
i++;
}
log(SQLTP_LOG_DEBUG,"Parameters:");
log(SQLTP_LOG_DEBUG,"Connection string: %s",connstr.c_str());
log(SQLTP_LOG_DEBUG,"user: %s",user.c_str());
log(SQLTP_LOG_DEBUG,"password: %s",passwd.c_str());
log(SQLTP_LOG_DEBUG,"char_set: %s",char_set.c_str());
log(SQLTP_LOG_DEBUG,"nchar_set: %s",nchar_set.c_str());
try{
env = Environment::createEnvironment(char_set,nchar_set);
} catch (exception &excp ) {
err.error_code=4;
err.error_text=mprintf("Oracle SQL Environment::createEnvironment() failed with error message: %s.",excp.what() );
log(SQLTP_LOG_DEBUG,"Oracle SQL Environment::createEnvironment() failed with error message: %s.",excp.what());
clean_up();
return 1;
}
try{
conn = env->createConnection(user,passwd,connstr);
} catch (exception &excp ) {
err.error_code=4;
err.error_text=mprintf("Oracle SQL createConnection failed with error message: %s.",excp.what() );
log(SQLTP_LOG_DEBUG,"Oracle SQL createConnection failed with error message: %s.",excp.what());
clean_up();
return 1;
}
log(SQLTP_LOG_DEBUG,"The new database connection is ready.");
state=1;
return 0;
}
int SQL_OraSQL_engine::execute_sql_command(const unsigned char* sql,
const unsigned long sql_length,
SQL_result_data& sql_res,
SQL_error& err){
if(state==0){
err.error_code=5;
err.error_text=mprintf("The Oracle SQL engine isn't connected to the database. Please connect first.");
return 1;
}
Statement *stmt=NULL;
ResultSet *rs=NULL;
int retval=1;
try{
stmt = conn->createStatement((const char*)sql);
Statement::Status res = stmt->execute();
switch(res){
case Statement::RESULT_SET_AVAILABLE:{
log(SQLTP_LOG_DEBUG,"Oracle SQL query result set available");
rs=stmt->getResultSet();
int row_increase=1;
int row_count=0;
int row_size=0;
sql_res.number_of_rows= row_count;
sql_res.rows=NULL;
vector<MetaData> cmd= rs->getColumnListMetaData();
int num_fields=cmd.size();
log(SQLTP_LOG_DEBUG,"Oracle SQL query number of fields per row: %d.", num_fields);
while(rs->next()){
if(row_count>=row_size){ // add more row to the result list
sql_res.rows=(SQL_row_data *)Realloc(sql_res.rows,(row_size+row_increase)*sizeof(SQL_row_data));
row_size+=row_increase;
row_increase*=2;
}
log(SQLTP_LOG_DEBUG,"Oracle SQL row: %d, row_size %d",row_count,row_size );
sql_res.number_of_rows= row_count+1;
SQL_row_data* act_row= sql_res.rows+row_count;
act_row->num_of_fields=num_fields;
act_row->field_data=(SQL_field_data*)Malloc(num_fields*sizeof(SQL_field_data));
for(int k=1; k<=num_fields; k++){
SQL_field_data* act_field=act_row->field_data+k-1;
if(row_count==0){ // first row, store the field name
log(SQLTP_LOG_DEBUG,"Oracle SQL getting row name");
act_field->field_name=mcopystr(cmd[k-1].getString(MetaData::ATTR_NAME).c_str());
log(SQLTP_LOG_DEBUG,"Oracle SQL row name: %s",act_field->field_name);
log(SQLTP_LOG_DEBUG,"Oracle SQL query field %d, name %s, type %d", k, act_field->field_name,cmd[k-1].getInt(MetaData::ATTR_DATA_TYPE));
} else {
act_field->field_name=NULL;
}
switch(cmd[k-1].getInt(MetaData::ATTR_DATA_TYPE)){
case OCCIINT:
{ // integer types
log(SQLTP_LOG_DEBUG,"Oracle SQL store data as int");
act_field->field_type=int_data;
act_field->field_data.int_data=rs->getInt(k);
}
break;
case OCCIFLOAT:
case OCCIDOUBLE:
case OCCI_SQLT_NUM:
{ // float/double types
log(SQLTP_LOG_DEBUG,"Oracle SQL store data as float");
act_field->field_type=real_data;
act_field->field_data.real_data=rs->getDouble(k);
}
break;
case OCCI_SQLT_CHR:
{ // text data types
log(SQLTP_LOG_DEBUG,"Oracle SQL store data as text");
act_field->field_type=text;
string dt=rs->getString(k);
act_field->data_length=dt.size();
act_field->field_data.text_binary_data=(unsigned char*)Malloc(act_field->data_length*sizeof(unsigned char));
memcpy(act_field->field_data.text_binary_data,dt.c_str(),act_field->data_length);
}
break;
default:{
log(SQLTP_LOG_DEBUG,"Oracle SQL store data as binary");
act_field->field_type=binary_data;
string dt=rs->getString(k);
act_field->data_length=dt.size();
act_field->field_data.text_binary_data=(unsigned char*)Malloc(act_field->data_length*sizeof(unsigned char));
memcpy(act_field->field_data.text_binary_data,dt.c_str(),act_field->data_length);
}
break;
}
}
row_count++;
log(SQLTP_LOG_DEBUG,"Oracle SQL next row");
}
}
retval=0;
break;
case Statement::UPDATE_COUNT_AVAILABLE:
sql_res.number_of_rows= stmt->getUpdateCount();
log(SQLTP_LOG_DEBUG,"Oracle SQL query update count: %d.",sql_res.number_of_rows);
sql_res.rows=NULL;
retval=0;
break;
default:
err.error_code=6;
err.error_text=mprintf("Oracle SQL query returned an unsupported result: %d.", res);
log(SQLTP_LOG_DEBUG,"Oracle SQL query returned an unsupported result: %d.",res);
break;
}
} catch (exception &excp ) {
err.error_code=6;
err.error_text=mprintf("Oracle SQL query failed with error message: %s.",excp.what() );
log(SQLTP_LOG_DEBUG,"Oracle SQL query failed with error message: %s.",excp.what());
retval=1;
}
log(SQLTP_LOG_DEBUG,"Oracle SQL rs free");
if(rs){
stmt->closeResultSet(rs);
}
log(SQLTP_LOG_DEBUG,"Oracle SQL stmt free");
if(stmt){
conn->terminateStatement(stmt);
}
log(SQLTP_LOG_DEBUG,"Oracle SQL retval %d",retval);
return retval;
}
int SQL_OraSQL_engine::close_database_connection(SQL_error&){
log(SQLTP_LOG_DEBUG,"Closing database connection.");
clean_up();
return 0;
}
SQL_engine_base* new_OraSQl_engine(){
return new SQL_OraSQL_engine;
}
}
......@@ -13,7 +13,7 @@
//
// File: SQL_PortTypes.ttcn
// Description: SQL test port source
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
......@@ -65,7 +65,7 @@ type record SQL_Connection{
SQL_Connection_parameters parameters
}
type enumerated SQL_engine_type { SQlite_engine(1), MySQL_engine(2) }
type enumerated SQL_engine_type { SQlite_engine(1), MySQL_engine(2), Oracle_engine(3) }
type universal charstring SQL_Query;
......@@ -109,7 +109,7 @@ type port SQLasp_PT procedure {
} with {
extension "requiresTITAN CRL 113 200/1 R8H"
extension "version R4A"
extension "version R5B"
}
......@@ -13,7 +13,7 @@
//
// File: SQL_SQLite_interface.cc
// Description: SQL test port SQLite interface source
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
#include "SQL_interface.hh"
......
......@@ -13,7 +13,7 @@
//
// File: SQL_interface.hh
// Description: SQL test port source
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
......@@ -24,7 +24,7 @@ class SQL_engine_base;
typedef SQL_engine_base* (*new_engine_func)();
typedef enum { No_Engine=0,SQLite_engine=1,MySQL_engine=2} engine_types;
typedef enum { No_Engine=0,SQLite_engine=1,MySQL_engine=2,OraSQL_engine=3} engine_types;
class SQL_Engine_register_data {
public:
......
......@@ -14,7 +14,7 @@
******************************************************************************/
//
// File: SQL_parser.l
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
//
#include "SQL_parser_.tab.h"
......
......@@ -14,7 +14,7 @@
******************************************************************************/
//
// File: SQL_parser.y
// Rev: R4A
// Rev: R5B
// Prodnr: CNL 113 760
// Updated: 2014-06-04
//
......@@ -603,8 +603,8 @@ expression: '(' expression ')' {
| USERVAR { $$ = $1; }
| STRING {
$1 = strdup(replace_ENV_VAR($1));
$$ = $1;
$$ = replace_ENV_VAR($1);
free($1);
}
| INTNUM {
$$ = strdup(int2str($1));
......@@ -966,10 +966,11 @@ char* replace_ENV_VAR(char* string){
char* temp;
char* value;
int len;
char* temp2=NULL;
temp = strstr(string, "$");
if(temp == NULL){
return string; //No enviroment variable
return strdup(string); //No enviroment variable
} else {
result = CHARSTRING(temp-string,string);
temp++; //skip '$' sign
......@@ -988,17 +989,20 @@ char* replace_ENV_VAR(char* string){
if(var != NULL){
temp++; //skip '}' sign
//insert value and check for next variable(if present)
result += CHARSTRING(var)+CHARSTRING(replace_ENV_VAR(temp));
result += CHARSTRING(var)+CHARSTRING(temp2=replace_ENV_VAR(temp));
free(temp2);
} else {
//Enviroment variable was not found
TTCN_warning("No enviroment variable with name: %s", (char*)(const char*)evar_name);
TTCN_warning("No enviroment variable with name: %s", (const char*)evar_name);
//skip the undefined variable and search for the next (if present)
result += CHARSTRING(2,"${")+CHARSTRING(evar_name)+CHARSTRING(replace_ENV_VAR(temp));
result += CHARSTRING(2,"${")+CHARSTRING(evar_name)+CHARSTRING(temp2=replace_ENV_VAR(temp));
free(temp2);
};
} else {
//'${' found, but no } => possibly not an enviroment variable
//search for next variable (if present)
result += CHARSTRING(2,"${")+CHARSTRING(replace_ENV_VAR(var));
result += CHARSTRING(2,"${")+CHARSTRING(temp2=replace_ENV_VAR(var));
free(temp2);
};
//variable is in $... format
......@@ -1019,13 +1023,15 @@ char* replace_ENV_VAR(char* string){
if(value != NULL){
//insert value and check for next variable(if present)
result += CHARSTRING(value)+CHARSTRING(replace_ENV_VAR(temp));
result += CHARSTRING(value)+CHARSTRING(temp2=replace_ENV_VAR(temp));
free(temp2);
break;
} else {
//Enviroment variable was not found
TTCN_warning("No enviroment variable with name: %s", (char*)(const char*)evar_name);
TTCN_warning("No enviroment variable with name: %s", (const char*)evar_name);
//search for next variable (if present)
result += CHARSTRING(1,"$")+CHARSTRING(evar_name)+CHARSTRING(replace_ENV_VAR(temp));
result += CHARSTRING(1,"$")+CHARSTRING(evar_name)+CHARSTRING(temp2=replace_ENV_VAR(temp));
free(temp2);
break;
};
};
......@@ -1041,7 +1047,7 @@ char* replace_ENV_VAR(char* string){
result += CHARSTRING(value);
} else {
//Enviroment variable was not found
TTCN_warning("No enviroment variable with name: %s", (char*)(const char*)evar_name);
TTCN_warning("No enviroment variable with name: %s", (const char*)evar_name);
result += CHARSTRING(1,"$")+CHARSTRING(evar_name);
};
};
......@@ -1049,7 +1055,7 @@ char* replace_ENV_VAR(char* string){
};
};
return (char*)(const char*)result;
return strdup((const char*)result);
}
BOOLEAN SQL__Functions::ef__SQL__Execute (const CHARSTRING& pl__sql__file,
......
This diff is collapsed.
/* A Bison parser, made by GNU Bison 3.0.2. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_SQL_PARSER_SQL_PARSER_TAB_H_INCLUDED
# define YY_SQL_PARSER_SQL_PARSER_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int SQL_parser_debug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
END = 0,
EOL = 258,
NAME = 259,
STRING = 260,
USERVAR = 261,
ASC = 262,
DESC = 263,
BOOL = 264,
INTERVAL_VALUE = 265,
BIGINT = 266,
INTNUM = 267,
APPROXNUM = 268,
OR = 269,
ANDOP = 270,
NOT = 271,
BETWEEN = 272,
MOD = 273,
COMPARISON = 274,
ASSIGN = 275,
INSERT = 276,
INTO = 277,
VALUES = 278,
UPDATE = 279,
SET = 280,
DELETE = 281,
FROM = 282,
WHERE = 283,
LIKE = 284,
AND = 285,
OROP = 286,
USE = 287,
ORDER = 288,
BY = 289,
LIMIT = 290,
COMMENT = 291,
CREATE = 292,
DROP = 293,
TABLE = 294,
DATABASE = 295,
LEADING = 296,
TRAILING = 297,
BOTH = 298,
FOR = 299,
IN = 300,
IS = 301,
IF = 302,
NULLX = 303,
XOR = 304,
AUTO_INCREMENT = 305,
AUTOINCREMENT = 306,
SQLDEFAULT = 307,
UNIQUE = 308,
PRIMARY = 309,
KEY = 310,
INDEX = 311,
INTERVAL = 312,
BIT = 313,
TINYINT = 314,
SMALLINT = 315,
MEDIUMINT = 316,