Skip to content

Instantly share code, notes, and snippets.

View Vladimir-Novick's full-sized avatar

Vladimir Novick Vladimir-Novick

View GitHub Profile
@Vladimir-Novick
Vladimir-Novick / CBlobRecordset.cpp
Last active August 17, 2023 12:50
Read BLOB object from SQL Database
#include "pch.h"
#include "CBlobRecordset.h"
CBlobRecordset::CBlobRecordset(CDatabase* db) : CRecordset(db) {
szErrorMessage[0] = 0;
nError = 0;
szSQLState[0] = 0;
}
long CBlobRecordset::GetBlobData(int nField, LPVOID pBuffer, int nBufferSize)
@Vladimir-Novick
Vladimir-Novick / CBlobDatabase.cpp
Last active August 17, 2023 12:52
CBlobDatabase- insert LogBynary object to SQL server database
#include "pch.h"
#include "CBlobDatabase.h"
CBlobDatabase::CBlobDatabase() : CDatabase() {
m_nImageLen = 0;
m_pabImage = nullptr;
}
void CBlobDatabase::BindParameters(HSTMT hstmt)
@Vladimir-Novick
Vladimir-Novick / CharArrayToHex
Created August 17, 2023 08:03
Convert char array to Hex String
string CharArrayToHex(char* data, size_t len)
{
constexpr char hexmap[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
std::string s(len * 2, ' ');
unsigned char p;
for (int i = 0; i < len; ++i) {
p = data[i];
s[2 * i] = hexmap[(p & 0xF0) >> 4];
s[2 * i + 1] = hexmap[p & 0x0F];
@Vladimir-Novick
Vladimir-Novick / Insert_BLOB_from file.txt
Last active August 17, 2023 12:59
Upload file to SQL server into varbynary(max) using SQL Server function OPENROWSET and BULK
CREATE TABLE myTable(FileName nvarchar(60),
FileType nvarchar(60), Document varbinary(max))
INSERT INTO myTable(FileName, FileType, Document)
SELECT 'ConnectionManager.pdb' AS FileName,
'.pdb' AS FileType,
* FROM OPENROWSET(BULK N'D:\TEST\BIN\ConnectionManager.pdb', SINGLE_BLOB) AS Document
POINT CDefaultAppFont::GetFontSize(CFont* pFont,CHAR *str)
{
POINT p = { 0 };
auto mainWindow = AfxGetApp()->GetMainWnd();
if (mainWindow != NULL) {
auto hDC = GetWindowDC(mainWindow->m_hWnd);
CDC* pDC = CDC::FromHandle(hDC);
CFont* pOldFont = pDC->SelectObject(pFont);
SIZE sizeText;
if (str == NULL) {
SIZE TextRect = { 0 };
RECT textrect = { 0 };
GetClientRect(hWnd, &rect);
textrect = rect;
DrawText(hdc, buff, -1, &textrect, DT_CALCRECT);
float rowCount = ((float)textrect.right / (float)(rect.right - rect.left)) + 0.9999;
rect.top += ((rect.bottom - rect.top) - (textrect.bottom *(int)rowCount))/ 2;
DrawText(hdc, buff, -1, rect, DT_CENTER | DT_WORDBREAK | DT_EXPANDTABS);
SelectObject(hdc, hOldFont);
::SetTextColor(hdc, oldtxtColor);
function show_elements(elements, specifiedDisplay) {
elements = elements.length ? elements : [elements];
for (var index = 0; index < elements.length; index++) {
elements[index].style.display = specifiedDisplay || 'block';
}
}
/*
// Usage:
@Vladimir-Novick
Vladimir-Novick / CPP17_CORRECT.H
Last active August 2, 2021 10:31
global compilation configuring windows sdk headers for Visual Studio 2019 ISO C++ 17 ( using byte as unsigned char )
#pragma once
// global compilation flag configuring windows sdk headers
// preventing inclusion of min and max macros clashing with <limits>
#define NOMINMAX 1
// override byte to prevent clashes with <cstddef>
typedef unsigned char byte;
// Define min max macros required by GDI+ headers.
#ifndef max
@Vladimir-Novick
Vladimir-Novick / WildCard_Match
Last active February 24, 2022 13:03
Algorithm for WildCard Pattern Searching
TEST_METHOD(wildcard_match) {
PgSQL pgsql;
bool ret;
ret = pgsql.match("n*ck", "novick");
Assert::AreEqual<bool>(true, ret, L"\"n*ck\", \"novick\" ", LINE_INFO());
ret = pgsql.match("nov?ck*", "novickfornovick");
Assert::AreEqual<bool>(true, ret, L"\"nov?ck*\", \"novickfornovick\" ", LINE_INFO());
ret = pgsql.match("n*k", "nov");
@Vladimir-Novick
Vladimir-Novick / RestoreFromDump
Last active March 22, 2021 14:39
PostgreSQL - Dump and restore schema from c++ application
int PgSQL_Dump::RestoreFromDump(ConnInfo* connInfo, string targetFileName) {
int ret = 0;
stringstream ss;
string connectionString;
for (auto& elemItem : connInfo->configInfo) {
if (elemItem.key.compare("CONFIG_STRING") == 0) {
connectionString = elemItem.value;
break;