How to call a stored procedure in Visual Studio 2012 - c++

So I have this program and I need to execute a stored procedure. But this gives me an error, "Invalid SQL statement". Already tried with begin proceudre() end. Same error. Help?
//Eliminar um docente de uma Edicao
void BDados::eliminarDocenteUnidade(EdicaoDisciplina edicao, string docente)
{
try
{
list <int> ed = separarEdicao(edicao.getEdicao());
stringstream comando;
comando << "execute p_eliminarDocenteUnidade('" << edicao.getSigla() << "'," << ed.front() << "," << ed.back() << ",'" << docente << "')";
cout << comando.str() << endl;
instrucao = ligacao->createStatement(comando.str());
instrucao->execute();
cout << "Docente eliminado com sucesso." << endl;
}catch(SQLException erro)
{
cout << erro.getMessage() << endl;
return;
}
}

Related

Not able to receive the OnBarCodeEvent for zebra scanner in linux c++

I am using the zebra linux sdk for scanner to capture the barcode that is scanned.
I want to listen to the OnBarcodeEvent and capture the code.
I have tried the sample console-app code and gui app code
I have called the
::ExecCommand( CMD_REGISTER_FOR_EVENTS , inXml, outXml, &eStatus);
The OnBarcodeEvent doesn't get invoked when I scan a bar code.
Code provided below.
void SampleEventListener::connect_corescanner()
{
cout <<"connect_corescanner startp"<< endl;
int iScannerType = SCANNER_TYPE_ALL;
StatusID eStatus ;
::Open(this, SCANNER_TYPE_ALL , &eStatus );
std::cout << "Open eStatus line 634 ConsoleSampleEventListener.cpp" << ": " << eStatus << std::endl;
if ( eStatus != STATUS_OK )
{
cout <<eStatus<< endl;
cout <<"can't connect to the corescanner. "<< endl;
exit(0);
}
// register for all events //
std::string inXml;
std::ostringstream oss;
oss << "<inArgs>" << std::endl;
oss << " <cmdArgs>" << std::endl;
oss << " <arg-int>6</arg-int>" << std::endl;
oss << " <arg-int>1,2,4,8,16,32</arg-int>" << std::endl;
oss << " </cmdArgs>" << std::endl;
oss << "</inArgs>" ;
inXml = oss.str();
std::string outXml;
::ExecCommand( CMD_REGISTER_FOR_EVENTS , inXml, outXml, &eStatus);
std::cout << "ExecCommand eStatus line 658 ConsoleSampleEventListener.cpp" << ": " << eStatus << std::endl;
if( eStatus != STATUS_OK ){
cout <<"unable to register for events"<< endl;
exit(-1);
}
cout <<"subscribe to events successful."<< outXml;
cout <<"\nsubscribe to events successful."<< endl;
cout <<"connect_corescanner endp\n"<< endl;
}
void SampleEventListener::OnBarcodeEvent(short int eventType, std::string & pscanData)
{
cout << "Barcode Detected" << endl;
cout << "Out XML" << endl;
cout << pscanData << endl;
}

Two functions making my game crash when running in a row

I usually find answers for my problems on this forum, but this time I can't. This is why I am asking you. (Sorry in advance for the mistakes I'm doing in english or c++)
So here is my void function, it is just the start of a little game I'm making in the console. It is just showing some informations. By the way it's a french game, but I don't think that a traduction is needed to solve my problem.
void showIntro (Personnage a, Personnage b, Personnage c)
{
cout << endl;
cout << "VOUS ENTREZ DANS LES MINES DE LA MORIA" << endl << endl;
cout << "ENNEMIS PRESENTS : " << endl << endl;
cout << " " << "Orc robuste" << endl << endl << endl;
a.afficherEtatIntro ();
cout << endl << endl;
cout << " " << "Orc robuste" << endl << endl << endl;
b.afficherEtatIntro ();
cout << endl << endl;
cout << " " << "Orc robuste" << endl << endl << endl;
c.afficherEtatIntro ();
cout << endl << endl;
cout << "Le combat va commencer";
Sleep(1000);
cout << ".";
Sleep(1000);
cout << ".";
Sleep(1000);
cout << "." << endl << endl << endl;
cout << "Gimli : ";
string phraseGimli ("Je vengerai mes freres!");
for (int f = 0; f <= phraseGimli.size(); f++) // Just writing a sentence
{
cout << phraseGimli[f];
Sleep(100);
}
cout << endl << "Legolas : ";
string phraseLegolas ("Nous sommes avec toi mon ami");
for (int g = 0; g <= phraseLegolas.size(); g++) // Writing a sentence
{
cout << phraseLegolas[g];
Sleep(100);
}
cout << endl << "Aragorn : ";
string phraseAragorn ("POUR LE GONDOR");
for (int i = 0; i <= phraseAragorn.size(); i++) // Writing a sentence
{
cout << phraseAragorn[i];
Sleep(100);
}
}
And here is the other one.
void choixAttaque (Personnage joueur, Personnage a, Personnage b, Personnage c, string nom)
{
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "Qui souhaitez vous attaquer ?" << endl;
cout << endl;
cout << endl;
cout << " " << nom << endl << endl << endl;
a.afficherEtatIntro ();
cout << endl << "Tapez 1" << endl;
cout << " " << nom << endl << endl << endl;
b.afficherEtatIntro ();
cout << endl << "Tapez 2" << endl;
cout << " " << nom << endl << endl << endl;
c.afficherEtatIntro ();
cout << endl << "Tapez 3" << endl;
int choix;
do
{
cin >> choix;
} while (choix <= 0 || choix >= 4);
switch (choix)
{
case 1:
joueur.attaquer(a);
case 2:
joueur.attaquer(b);
case 3:
joueur.attaquer(c);
}
}
afficherEtatIntro ()
void Personnage::afficherEtatIntro () const
{
cout << " " << "Vie : " << m_vie << endl;
cout << " ";
m_arme->afficher();
}
m_arme means m_weapon, I used "->" because it is from a pointer. I'm new to all of this, so it can be really possible that the mistake comes from here.
When I'm using only one, it works, but when I'm using both in a row, it does that.
first void function showing properly
And then.
Path of things in my computer
I hope I gave the informations needed to solve the problem, and I hope it can be solved. Thanks in advance for everything, and sorry for all the mistakes I may have made in english, c++ or by linking my lines of code. ^^'
(Btw, all the "cout << endl;" looks ugly I guess, but that is just until I learn how to use Qt..)
From debugger: "Program received signal SIGSEGV, Segmentation fault."
And a picture in comment. (Need more reputation for 3 links..)

How do I print an individual value from an array within text?

I'm trying to pull individual values from an array and put them into text, but keep running into errors with syntax.
#include <iostream>
#include <ostream>
using namespace std;
// PV, PM, FUE, RAP, PRE, SAB, ESP
int luch_bas [7] = {6,3,5,3,2,1,2};
int main ()
{ cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " luch_bas[0] "\n";
cout << "Puntos de Magia (PM)..." luch_bas[1] "\n";
cout << "Fuerza (FUE) ..." luch_bas[2] "\n";
cout << "Rapidez (RAP) ..." luch_bas[3] "\n";
cout << "Precisión (PRE) ..." luch_bas[4] "\n";
cout << "Sabiduría (SAB) ..." luch_bas[5] "\n";
cout << "Espíritu (ESP) ..." luch_bas[6] "\n";
}
The error log I keep getting is "expected ';' before 'luch_bas'", but I'm not exactly sure where the missing ; is supposed to go? I'm sure there's a much better way to code this; I am still learning.
try this
int main ()
{ cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... \t" << luch_bas[0]<< "\n";
...
}
The error log I keep getting is "expected ';' before 'luch_bas'", but I'm not exactly sure where the missing ; is supposed to go?
You don't wan't to put a ; as the error message suggests. You want to chain the output operator calls respectively.
The std::ostream& operator<<(std::ostream& os, Type t) returns a std::ostream& reference as you can see.
The correct way is to chain the operator<<() calls:
cout << "Puntos de Vida (PV)... " << luch_bas[0] << "\n";
// ^^ ^^
It should be:
cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " << luch_bas[0] << endl;
cout << "Puntos de Magia (PM)..." << luch_bas[1] << endl;
cout << "Fuerza (FUE) ..." << luch_bas[2] << endl;
cout << "Rapidez (RAP) ..." << luch_bas[3] << endl;
cout << "Precisión (PRE) ..." << luch_bas[4] << endl;
cout << "Sabiduría (SAB) ..." << luch_bas[5] << endl;
cout << "Espíritu (ESP) ..." << luch_bas[6] << endl;
use more "streaming" operators
#include <iostream>
#include <ostream>
using namespace std;
// PV, PM, FUE, RAP, PRE, SAB, ESP
int luch_bas [7] = {6,3,5,3,2,1,2};
int main ()
{ cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " << luch_bas[0] << "\n";
cout << "Puntos de Magia (PM)..." << luch_bas[1] << "\n";
cout << "Fuerza (FUE) ..." << luch_bas[2] << "\n";
cout << "Rapidez (RAP) ..." << luch_bas[3] << "\n";
cout << "Precisión (PRE) ..." << luch_bas[4] << "\n";
cout << "Sabiduría (SAB) ..." << luch_bas[5] << "\n";
cout << "Espíritu (ESP) ..." << luch_bas[6] << "\n";
}

Must have pointer to object type c++ (Array)

I have a pointer to object error type for the variable "carrierTime" i have created. If i make this an array, carrierTime becomes an error in the first if statement, however if i leave it without any array i get an error on the last line of the code where i have used carrierTime in a multiplication.
can anyone help??
platform used:visual studios
#include "AMcore.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
cout << "Amplitude Modulation Coursework" << endl;
cout << "Name: Mohammad Faizan Shah" << endl;
cout << "Student ID: 5526734 \n\n\n" << endl;
std::ifstream file,file2;
string filename1,filename2;
int rowCounter = 0;
double informationTime;
double informationAmplitudeAmount[361];
long double carrierTime;
double carrierAmplitudeAmount[361];
double totalAmplitudeAmount[1000];
int plotPoint;
cout << "Please enter the filename of the Carrier wave \n" << endl;
cin >> filename1;
file.open("carrier.txt");
if (file.is_open())
{
file >> carrierTime;
while (!file.fail())
{
cout << "row" << setw(3) << rowCounter;
cout << " Time = " << setw(5) << carrierTime;
file >> carrierAmplitudeAmount[rowCounter];
rowCounter++;
if (!file.fail())
{
cout << " Carrier signal= " << setw(5) << carrierAmplitudeAmount;
file >> carrierTime;
}
cout << endl;
}
if (file.eof())
cout << "Reached the end of file marker" << endl;
else
cout << "Error whilst reading input file" << endl;
}
else
{
cout << "Error opening input file, ";
cout << "check carrier.txt exists in the current directory." << endl;
}
file.close();
cout << "\n\n" << endl;
cout << "Please enter the filename of the information wave \n\n\n" << endl;
cin >> filename2;
file2.open("information.txt");
if (file2.is_open())
{
file2 >> informationTime;
while (!file2.fail())
{
cout << "row" << setw(3) << rowCounter;
cout << " Time = " << setw(5) << informationTime;
file2 >> informationAmplitudeAmount[361];
rowCounter++;
if (!file2.fail())
{
cout << " Carrier signal= " << setw(5) << informationAmplitudeAmount;
file2 >> informationTime;
}
cout << endl;
}
if (file2.eof())
cout << "Reached the end of file marker" << endl;
else
cout << "Error whilst reading input file" << endl;
}
else
{
cout << "Error opening input file, ";
cout << "check carrier.txt exists in the current directory." << endl;
}
file.close();
cout << "Reading from txt file has completed" << endl << endl;
cout << "\n\n" << endl;
cout << "\n\n" << endl;
cout << "please enter number of sample points to plot:| \n" << endl;
do{
cin >> plotPoint;
if (plotPoint <= 361)
{
cout << "\n plotting the graph.\n" << endl;
}
else if (plotPoint > 361)
{
cout << "Value is too high.. Try value lower than 361\n" << endl;
}
} while (plotPoint > 361);
cout << "row" << setw(3) << rowCounter;
file >> carrierAmplitudeAmount[361];
rowCounter++;
plotPoint = 361 / plotPoint;
cout << " Time \| Amplitude Modulation plot\n------------+--------------------------------------------------\n";
totalAmplitudeAmount[0] = carrierAmplitudeAmount[0] * informationAmplitudeAmount[0];
cout << setw(6) << carrierTime << setw(4) << "\|" << setw(48) << "*" << totalAmplitudeAmount[0] << endl;
for (int i = 1; i <= 361; i = i + plotPoint) {
totalAmplitudeAmount[i] = informationAmplitudeAmount[i] * carrierAmplitudeAmount[i];
int y = totalAmplitudeAmount[i] * 22;
cout << setw(6) << carrierTime[i++] << setw(4) << "\|" << setw(26 + y) << "*" << totalAmplitudeAmount[i] << endl;
}
cout << "End of program" << endl;
system("pause");
return 0;
}
cout << setw(6) << carrierTime[i++] << setw(4) << "\|" << setw(26 + y) << "*" << totalAmplitudeAmount[i] << endl;
carrierTime[i++] does not look correct. The variable is not defined as a pointer.
Also, proper debugging would help you catch these errors for yourself.

GetConsoleSelectionInfo C++

cI want to select some text with my cursor using the Mark Function from Console, but my code doesn't work ...
CONSOLE_SELECTION_INFO c;
if(GetConsoleSelectionInfo(&c))
{
while((c.dwFlags & CONSOLE_MOUSE_DOWN) == 0) { if(c.dwFlags) cout << c.dwFlags; }
cout << "SelectionAnchor: " << c.dwSelectionAnchor.X << " " << c.dwSelectionAnchor.Y;
cout << "RectangleSelection: " << c.srSelection.Top << " " << c.srSelection.Left << c.srSelection.Bottom << c.srSelection.Right;
}
else cout << "\n\nError: " << GetLastError();
Whatever I'm selecting or I'm doing, always c.dwFlags will be 0 ...