blob: bdb8a5658aff8e040e93f92e83f74c56e34cfaf6 [file] [log] [blame]
/**********************************************************************
// @@@ START COPYRIGHT @@@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// @@@ END COPYRIGHT @@@
**********************************************************************/
/* -*-C++-*-
****************************************************************************
*
* File: clitest.cpp
* Description: Test driver useing exe util cli interface
*
*
*
*
****************************************************************************
*/
#include "Platform.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "BaseTypes.h"
#include "NAAssert.h"
#include "stdlib.h"
#include "stdio.h"
#include "sqlcli.h"
#include "ComDiags.h"
#include "ex_stdh.h"
#include "memorymonitor.h"
#include "ex_exe_stmt_globals.h"
#include "ex_esp_frag_dir.h"
#include "ComTdb.h"
#include "ex_tcb.h"
#include "ex_split_bottom.h"
#include "ex_send_bottom.h"
#include "NAExit.h"
#include "ExSqlComp.h"
#include "Globals.h"
#include "Int64.h"
#include "SqlStats.h"
#include "ComUser.h"
#include "ExpError.h"
#include "ComSqlId.h"
#include "ex_globals.h"
#include "ex_tcb.h"
#include "ExExeUtil.h"
#include "Globals.h"
#include "Context.h"
#include "blobtest.h"
//DEFINE_DOVERS(clitestdriver)
//
int main(int argc, const char * argv[])
{
if ((argc < 2) || (argc > 2))
{
cout << "Error - provide an option: " << endl;
cout << "Usage : clitestdriver <option number>" << endl;
cout << "TEST OPTION "<<endl;
cout << "-------------------------------------------"<<endl;
cout << "Blob test extract to buffer 1 "<< endl;
cout << "Blob test extract to file in chunks 2 "<< endl;
cout << "Blob test to insert to lob column 3 "<< endl;
cout << "Blob test to update lob column 4 "<< endl;
cout << "Blob test to append to lob column 5 "<< endl;
cout << "Blob test to update to lob lobhandle 6 "<< endl;
cout << "Blob test to append to lobhandle 7 "<< endl;
cout << "Blob test to truncate to lobhandle 8 "<< endl;
return 0;
}
Int32 retcode = 0;
SQLCTX_HANDLE defContext = 0;
Lng32 retCode = SQL_EXEC_CreateContext(&defContext, NULL, 0);
int option = atoi(argv[1]);
if(retcode != 0 )
cout << "Error creating a CLI context error " << endl;
CliGlobals * cliGlob = GetCliGlobals();
char tablename[50] = {'\0'};
char columnname[50] = {'\0'};
char filename[50] = {'\0'};
switch (option)
{
case 1:
{
cout <<"***********" <<endl;
cout << " Blob test extract to user buffer " << endl;
cout <<"***********" <<endl;
cout << "Extract from a lob column in a lob table" << endl << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name : " << tablename << endl;
cout << "Input lob column name to extract from :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
//extract lob handle
char *lobHandle = new char[1024];
str_cpy_all(lobHandle," ",1024);
cout << "Extracting lob handle for column " << columnname << "..." << endl;
retcode = extractLobHandle(cliGlob, lobHandle, (char *)columnname,(char *)tablename);
if (retcode)
{
cout << "extractLobHandle returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB handle for "<< columnname << ": " << lobHandle << endl;
//extract length of lob column from a table with 1 lob column.
cout << "Extracting LOB data length for the above handle..." << endl;
Int64 lengthOfLob= 0;
retCode = extractLengthOfLobColumn(cliGlob, lobHandle, lengthOfLob,columnname,(char *)tablename);
if (retcode)
{
cout << "extractLengthOfLobColumn returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB data length :" << lengthOfLob << endl;
//extract lob data to buffer
cout << "Extracting lob data into user buffer in a loop ..." << endl;
retCode = extractLobToBuffer(cliGlob,lobHandle, lengthOfLob,columnname,tablename);
if (retcode)
{
cout << "extractLobToBuffer returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
delete lobHandle;
return retcode;
}
break;
case 2:
{
cout <<"*************************************" <<endl;
cout << "Blob test extract to file in chunks " << endl;
cout <<"************************************" <<endl;
cout << "Extract from a lob column in a lob table" << endl << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name : " << tablename << endl;
cout << "Input lob column name to extract from :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
cout <<"Input a filename to extract to : " << endl;
cin.getline(filename,40);
cout << "Output File Name : " << filename << endl;
//extract lob handle
char *lobHandle = new char[1024];
str_cpy_all(lobHandle," ",1024);
cout << "Extracting lob handle for column " << columnname << "..." << endl;
retcode = extractLobHandle(cliGlob, lobHandle, (char *)columnname,tablename);
if (retcode)
{
cout << "extractLobHandle returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB handle for "<< columnname << ": " << lobHandle << endl;
//extract length of lob column from a table with 1 lob column.
cout << "Extracting LOB data length for the above handle..." << endl;
Int64 lengthOfLob= 0;
retCode = extractLengthOfLobColumn(cliGlob, lobHandle, lengthOfLob,columnname,tablename);
if (retcode)
{
cout << "extractLengthOfLobColumn returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB data length :" << lengthOfLob << endl;
//extract lob data to buffer
cout << "Extracting lob data into file in chunks of 1000 ..." << endl;
retCode = extractLobToFileInChunks(cliGlob,lobHandle, filename, lengthOfLob,columnname,tablename);
if (retcode)
{
cout << "extractLobToFileInChunks returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
delete lobHandle;
return retcode;
}
break;
case 3:
{
cout <<"*************************************" <<endl;
cout << "Blob test insert lobdata from a buffer " << endl;
cout << "Input lob table name (1st int column, 2nd blob column:" << endl;
cin.getline(tablename,40);
cout << "Table name : " << tablename << endl;
retcode = insertBufferToLob(cliGlob,tablename);
return retcode;
}
break;
case 4:
{
cout <<"*************************************" <<endl;
cout << "Blob test update lobdata from a buffer " << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name (1st int column ,2nd blob column): " << tablename << endl;
cout << "Input lob column name to update :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
retcode = updateBufferToLob(cliGlob,tablename,columnname);
return retcode;
}
break;
case 5:
{
cout <<"*************************************" <<endl;
cout << "Blob test update append lobdata from a buffer " << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name (1st int column , 2nd blob column: " << tablename << endl;
cout << "Input lob column name to update :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
retcode = updateAppendBufferToLob(cliGlob,tablename,columnname);
return retcode;
}
break;
case 6:
{
cout <<"*************************************" <<endl;
cout << "Blob test update lobhandle from a buffer " << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name : " << tablename << endl;
cout << "Input lob column name to get handle from :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
//extract lob handle
char *lobHandle = new char[1024];
str_cpy_all(lobHandle," ",1024);
cout << "Extracting lob handle for column " << columnname << "..." << endl;
retcode = extractLobHandle(cliGlob, lobHandle, (char *)columnname,tablename);
if (retcode)
{
cout << "extractLobHandle returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB handle for "<< columnname << ": " << lobHandle << endl;
retcode = updateBufferToLobHandle(cliGlob,lobHandle);
return retcode;
}
break;
case 7:
{
cout <<"*************************************" <<endl;
cout << "Blob test append lobhandle from a buffer " << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name : " << tablename << endl;
cout << "Input lob column name to get handle from :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
//extract lob handle
char *lobHandle = new char[1024];
str_cpy_all(lobHandle," ",1024);
cout << "Extracting lob handle for column " << columnname << "..." << endl;
retcode = extractLobHandle(cliGlob, lobHandle, (char *)columnname,tablename);
if (retcode)
{
cout << "extractLobHandle returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB handle for "<< columnname << ": " << lobHandle << endl;
retcode = updateAppendBufferToLobHandle(cliGlob,lobHandle);
return retcode;
}
break;
case 8:
{
cout <<"*************************************" <<endl;
cout << "Blob test empty lobhandle from a buffer " << endl;
cout << "Input lob table name :" << endl;
cin.getline(tablename,40);
cout << "Table name : " << tablename << endl;
cout << "Input lob column name to get handle from :" << endl;
cin.getline(columnname,40);
cout << "Column Name : " << columnname << endl;
//extract lob handle
char *lobHandle = new char[1024];
str_cpy_all(lobHandle," ",1024);
cout << "Extracting lob handle for column " << columnname << "..." << endl;
retcode = extractLobHandle(cliGlob, lobHandle, (char *)columnname,tablename);
if (retcode)
{
cout << "extractLobHandle returned " << retcode <<endl;
delete lobHandle;
return retcode;
}
cout << "LOB handle for "<< columnname << ": " << lobHandle << endl;
retcode = updateTruncateLobHandle(cliGlob,lobHandle);
return retcode;
}
break;
}//end switch
return 0;
}