|
If you're a young guy, I'll take your answer too. I work in the land of embedded systems where nothing ever dies. Some of the systems I support use CE 4.2/5.0 and Embedded Visual C++ - a bastardized clone of VC++ 6.0 (I think). In EVC++ I can place my cursor on something I am interested in and press help - and I get help.
Years pass, and now I also support a variant using WEC7 and VS2008. No matter how many times I have installed VS2008, help is trashed. It just does not work. I have spend days over the past years trying to resolve this issue. I want to do something stupid simple like click on CString and press F1 to pull up the class description. Nope, never happens.
Any of you resolve this issue? Spoilers?
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
AFAIR, the latest VC++ edition that worked with the MSDN help good enough was VC++0.
In every new VS edition it worked either worse either didn't work at all.
|
|
|
|
|
0? lol, I agree. It's totally bizarre. I'll keep digging, maybe write my first article.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Hi C++ Gurus,
Below code is generating error code -2. Its working fine for sql queries like "select * from emp", but where as in Insert statement its returning error code. Please help.
Regards,
Suresh
#include "database.h"
int main(){
SQLRETURN ret = 0;
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLSMALLINT msg_len = 0;
SQLCHAR sql_state[6], message[256];
SQLINTEGER native_error = 0;
try{
ret = SQLAllocEnv(&env);
ret = SQLAllocConnect(env, &dbc);
ret = SQLConnect(dbc, (SQLCHAR*)"KarTarDB", strlen("KarTarDB"), (SQLCHAR*)"sa",2,(SQLCHAR*)"KarTarPwd",9);
if(ret == SQL_INVALID_HANDLE || ret < 0) {
cout << "Connection open failure." << endl;
ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sql_state, &native_error, message, sizeof(message), &msg_len);
cout << ret << endl;
} else{
char sql[100]="INSERT INTO emp(name, age, dob) VALUES ('john', 23, '010101')";
ret = SQLPrepare(stmt,(unsigned char*)sql, SQL_NTS);
ret = SQLExecute(stmt);
if(ret == SQL_ERROR || ret < 0) {
cout << "ResultSet Error: " << ret << endl;
}else{
cout << "Done" << endl;
}
}
}catch(...) {
cout << "Database error.." << endl;
}
return 0;
}
|
|
|
|
|
What is -2? According to MSDN SQLExecute Function - SQL Server | Microsoft Docs it can return the following:
Quote: SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NEED_DATA, SQL_STILL_EXECUTING, SQL_ERROR, SQL_NO_DATA, SQL_INVALID_HANDLE, or SQL_PARAM_DATA_AVAILABLE.
Besides
Quote: When SQLExecute returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value can be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle.
|
|
|
|
|
Hi Victor, Thanks for your response.
As you can see in the code, I have already used SQLGetDiagRec.
ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sql_state, &native_error, message, sizeof(message), &msg_len)
But even that is returning -2 and not giving any other details, hence I commented it. Am I missing anything? How can I get more details from ret object apart from -2.
Regards,
Suresh
|
|
|
|
|
SureshBL wrote: But even that is returning -2 and not giving any other details, hence I commented it. Am I missing anything? How can I get more details from ret object apart from -2.
Well, -2 means SQL_INVALID_HANDLE.
So you need to go one step back and check why the handle is invalid!
|
|
|
|
|
Thanks
Do you see anything wrong with my Code?
As mentioned querying table is working fine with the connection, but Insert statement is making handle invalid.
SQLSTATE: l NativeError: 0 ErrMsg: 0x6cfce0
Apologies, I am learning c++ now. So I am not expert to understand lots of bits and pieces to debug the issue in every step.
Regards,
Suresh
modified 19-May-20 17:07pm.
|
|
|
|
|
Can't say I've ever used this, but shouldn't the SQLHSTMT variable 'stmt' be initialized with something?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
modified 19-May-20 17:31pm.
|
|
|
|
|
Ok got you. So I have to assign dbc to stmt?
ret = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
|
|
|
|
|
Great Its working now. Thank you very much.. 
|
|
|
|
|
You're welcome.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Does anybody know where kernel32.lib could be found?
|
|
|
|
|
kernel32.lib is the library for kernel32.dll. It may be found in the Windows SDK, which is freely downloadable.
Most Windows compilers bundle a copy of it, and place it with their other libraries.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
|
I recently lost out on a great job because I couldn't pass the coding challenge. I was given a header file that I COULD NOT modify, and asked to fill it out with a stack with a linked list backbone. The problem was to reverse stack data (integers) such that nodes 1..4 contained 1, 2, 3, 4, and the output would be 4, 3, 2, 1. I easily wrote this, with one problem: none of the methods in the class signatures contained any output method other than top(), which returned the top node. Everything else was a void method. So I modified the size() method t]such that it output the values of each node.
I believe this is where I failed. The code contained a "node" class with a data member and a pointer to the next node. The stack class had a pop method, a push method, that size method, top, and that's about it. Both were templates. Other than adding a friend class or resorting to dirty pointer tricks, I could not figure out how to display the data members of the node class.
I really don't understand how this is a valid problem to pose.
Here is the header I was given:
#include <cstddef>
#pragma once
//a basic stack class.
//Implement all member functions in the file stack.cpp.
// then add a reasonable set of unit tests, with output, to main.cpp.
//Don't modify stack.h or CMakeLists.txt at all, unless you spot a mistake.
template <class t=""> struct _node
{
T _data;
_node<t>* _next;
_node(const T&, _node<t>*);
~_node();
};
template <class t=""> class stack
{
private:
_node<t>* _head;
size_t _size;
public:
stack();
~stack();
size_t size() const; //return the size of the stack
T& top() const; //return a reference to the top value. Throw an exception if the stack is empty.
void push(const T&); //push a new value onto the stack
void pop(); //remove the top value from the stack. Do nothing if the stack is empty.
void invert(); //reverse the order of the entire stack, so that 1,2,3,4,5 becomes 5,4,3,2,1 and so on.
//Your function should work in the most effecient way you can devise, ideally without allocating any memory on the heap.
};
|
|
|
|
|
Tim ONeil wrote: // then add a reasonable set of unit tests, with output, to main.cpp. You are supposed to add code in main to display the values, which you extract by repeated calls to the top and pop functions. The call to top gives you a reference to the value at the top of the stack. So you can display that with cout /printf . Follow that with a call to pop and the value you just looked at is now removed, ready for the next call to top . And so on.
|
|
|
|
|
Right. All my attempts, including reinterpret_cast, to instantiate the _node class, which is private in _stack, yield compile errors.
|
|
|
|
|
You do not use reinterpret_cast to change public/private. However, I think there is something missing in that header file; I'd like to see their implementation.
|
|
|
|
|
Here is a version that builds, but without most of the implementation. I am not sure how much this differs from what you tried.
typedef int T; #include "stack.h"
#include <iostream>
template <class t>
stack<t>::stack()
{
_head = nullptr;
_size = 0;
}
template <class t>
stack<t>::~stack()
{
}
template <class t>
size_t stack<t>::size() const
{
return _size;
}
template <class t>
T& stack<t>::top() const
{
return _head->_data;
}
template <class t>
void stack<t>::push(const T& item)
{
}
template <class t>
void stack<t>::pop()
{
}
template <class t>
void stack<t>::invert()
{
}
int main()
{
stack<int> myStack;
std::cout << "stack size = " << myStack.size() << std::endl;
return 0;
}
modified 18-May-20 5:09am.
|
|
|
|
|
|
Sorry for the late reply, busy day
The good news is that you should be happy you didn't get the job. I'm fairly sure it would have been a miserable work environment. Who in this day and age still hires based on such "code challenges"?
What they forgot is that the code challenge tells as much about the one who wrote it as it does about the one who solves it. In this case:
- have they not heard that names starting with underscores are reserved the implementation? It says: "we are such primadonnas we don't care about frigging standards!"
- you have _node(const T&, _node<t>*); Who is "T" and "t"? You should at least bother to run your header through a compiler to see you that you don't have any syntax errors. If you are at it, look also for a spell-checker: it's "efficient" not "effecient". This shows lack of respect for the person you are interviewing.
- template <class t=""> struct _node Seriously? Show me the compiler that doesn't flag it as an error.
- the instructions suck also: "Implement all member functions in the file stack.cpp" Have you not heard that template implementations are normally in the same .h file? If I put it in stack.cpp, then in main.cpp I have to include "stack.cpp". Yey!
The code itself is fairly bland. I suspect they wanted to see you do some pointer acrobatics in the "invert" member function:
template<class T>
_node<T>::_node (const T& dat, _node<T>* ptr) :
_data (dat),
_next (ptr)
{
}
template<class T>
_node<T>::~_node ()
{
}
template<class T>
stack<T>::stack () :
_size (0),
_head (nullptr)
{
}
template<class T>
stack<T>::~stack ()
{
while (_head)
{
_node<T>* ptr = _head->_next;
delete _head;
_head = ptr;
}
}
template<class T>
size_t stack<T>::size () const
{
return _size;
}
template<class T>
T& stack<T>::top () const
{
if (!_size)
throw std::exception ("empty_stack");
return _head->_data;
}
template<class T>
void stack<T>::push (const T& data)
{
_node<T>* node = new _node<T> (data, _head);
_head = node;
_size++;
}
template<class T>
void stack<T>::pop ()
{
if (!_size)
return;
_node<T>* ptr = _head->_next;
delete _head;
_head = ptr;
--_size;
}
template<class T>
void stack<T>::invert ()
{
_node<T>* prev = nullptr;
_node<T>* crt = _head;
while (crt)
{
_node<T>* next = crt->_next;
crt->_next = prev;
prev = crt;
crt = next;
}
_head = prev;
}
I don't want to go on here talking about the dangers of not providing a copy constructor when you are knee-deep in pointer manipulations, not respecting the "big three" (or big five) rule, and so on and so forth.
For the "unit test" part you can write something like this:
int main (int argc, char** argv)
{
stack<int> the_stack;
cout << "Empty stack has size " << the_stack.size () << endl;
the_stack.push (1);
the_stack.push (2);
the_stack.push (3);
the_stack.push (4);
the_stack.push (5);
cout << "5 elements pushes, size is " << the_stack.size () << endl;
cout << "Top element is " << the_stack.top () << endl;
the_stack.invert ();
cout << "Stack inverted elements are (from top):" << endl;
int n = the_stack.size ();
for (int i = 0; i < n; i++)
{
cout << "Element " << i + 1 << " is " << the_stack.top () << endl;
the_stack.pop ();
}
return 0;
}
To wrap it up, my advice would be to look for an environment where they hire based on your work portfolio, where they understand that a coder must be also a person with good communication skills and with a good understanding of the problem domain. Build a portfolio of code writing high-quality code and learning from masters (Knuth, Wirth, Djikstra and so many others). Remember: if you cannot write your code to read like a poem, make it at least like a novel.
Mircea
|
|
|
|
|
That was my first thought too, that the company's culture, or at least this part of it, must be shite.
|
|
|
|
|
I think you missed the point which said "you must not modify stack.h". Part of the test is to keep the implementation separate from the header. Yes, I know purists would say that is wrong, but it is perfectly acceptable in the context of this test. And the difference between the lower case t and upper case T is important for the implementation.
|
|
|
|
|
Maybe you can add some explanations an I might learn something from this.
I'm using Visual Studio 2019 and it barks at me for template <class t=""> struct _node . I'm sorry but if I want to go ahead I need to change stack.h.
After I change it to template <class T> struct _node (that seems the only plausible alternative to me), and I put the my code in stack.cpp, all goes well until link time when it says it cannot find the implementation functions. This is normal (in my mind) because the templates haven't been instantiated. How is the compiler to know that it needs to generate a stack of "int" when compiling stack.cpp and how it can generate said stack when compiling main.cpp. I could probably force it to create one by placing an instantiation of stack<int> in stack.cpp. No one does anything like that.
Mircea
|
|
|
|
|