Skip to content

Commit 9246911

Browse files
author
Saumya Garg
committed
adding a connection class in c++
1 parent c7661d6 commit 9246911

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#include "connection.h"
5+
#include <iostream>
6+
7+
Connection::Connection(const std::wstring& conn_str) : _conn_str(conn_str) {}
8+
9+
Connection::~Connection() {
10+
close();
11+
}
12+
13+
SQLRETURN Connection::connect() {
14+
LOG("Connecting to MSSQL");
15+
// to be added
16+
}
17+
18+
SQLRETURN Connection::close() {
19+
LOG("Disconnect from MSSQL");
20+
// to be added
21+
}
22+
23+
SQLRETURN Connection::commit() {
24+
LOG("Committing transaction");
25+
// to be added
26+
}
27+
28+
SQLRETURN Connection::rollback() {
29+
LOG("Rolling back transaction");
30+
// to be added
31+
}
32+
33+
SQLRETURN Connection::end_transaction(SQLSMALLINT completion_type) {
34+
// to be added
35+
}
36+
37+
SQLRETURN Connection::set_autocommit(bool enable) {
38+
LOG("Setting autocommit mode C++");
39+
// to be added
40+
}
41+
42+
bool Connection::get_autocommit() const {
43+
LOG("Getting autocommit mode C++");
44+
// to be added
45+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#ifndef CONNECTION_H
5+
#define CONNECTION_H
6+
7+
#include "ddbc_bindings.h"
8+
9+
class Connection {
10+
public:
11+
Connection(const std::wstring& conn_str);
12+
~Connection();
13+
14+
SQLRETURN connect();
15+
SQLRETURN close();
16+
SQLRETURN commit();
17+
SQLRETURN rollback();
18+
SQLRETURN end_transaction(SQLSMALLINT completion_type);
19+
SQLRETURN set_autocommit(bool value);
20+
bool get_autocommit() const;
21+
22+
private:
23+
24+
std::wstring _conn_str;
25+
SqlHandlePtr _env_handle;
26+
SqlHandlePtr _dbc_handle;
27+
28+
bool _autocommit = false;
29+
std::shared_ptr<Connection> _conn;
30+
};
31+
#endif // CONNECTION_H

0 commit comments

Comments
 (0)