Esempio n. 1
0
BOOL CCsvDatabase::Open(HWND /*hWnd*/, LPCTSTR pstrConnectionString, LPCTSTR /*pstrUser*/, LPCTSTR /*pstrPassword*/, long /*iType*/)
{
   _ASSERTE(!::IsBadStringPtr(pstrConnectionString,(UINT)-1));

   Close();

   // Store filename
   ::lstrcpy(m_szFilename, pstrConnectionString);

   // Open and read the entire file into memory
   // NOTE: We'll assume the file is ANSI encoded.
   HANDLE hFile = ::CreateFile(pstrConnectionString, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   if( hFile == INVALID_HANDLE_VALUE ) return _Error((long)::GetLastError(), _T("File open error"));
   DWORD dwSize = ::GetFileSize(hFile, NULL);
   if( dwSize == 0 ) {
      ::CloseHandle(hFile);
      return _Error(1, _T("Empty file?"));
   }
   m_pstrText = (LPSTR) malloc(dwSize + 1);
   if( m_pstrText == NULL ) return _Error(ERROR_OUTOFMEMORY, _T("Out of memory"));
   DWORD dwRead = 0;
   if( !::ReadFile(hFile, m_pstrText, dwSize, &dwRead, NULL) ) {
      _Error(::GetLastError(), _T("File read error"));      
      ::CloseHandle(hFile);
      return FALSE;
   }
   ::CloseHandle(hFile);
   m_pstrText[dwSize] = '\0';

   // Generate row index
   return _BindColumns();
}
Esempio n. 2
0
AppX11::AppX11(QObject *parent)
: QObject(parent), d(new Data) {
    d->xssTimer.setInterval(20000);
    connect(&d->xssTimer, &QTimer::timeout, this, [this] () {
        if (d->xss && d->display) {
            _Trace("Call XResetScreenSaver().");
            XResetScreenSaver(d->display);
        } else
            _Error("Cannot run XResetScreenSaver().");
    });
    connect(&d->hbTimer, &QTimer::timeout, this, [this] () {
        if (!d->hbCommand.isEmpty()) {
            if (QProcess::startDetached(d->hbCommand))
                _Trace("Run command: %%", d->hbCommand);
            else
                _Error("Cannot run command: %%", d->hbCommand);
        } else
            _Error("No command for heartbeat");
    });
    d->connection = QX11Info::connection();
    d->display = QX11Info::display();
    d->root = QX11Info::appRootWindow();
    d->aNetWmState = d->getAtom("_NET_WM_STATE");
    d->aNetWmStateAbove = d->getAtom("_NET_WM_STATE_ABOVE");
    d->aNetWmStateStaysOnTop = d->getAtom("_NET_WM_STATE_STAYS_ON_TOP");
}
Esempio n. 3
0
BOOL COledbRecordset::Open(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
   _ASSERTE(m_pDb==NULL || m_pDb->IsOpen());
   _ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));
   HRESULT Hr;

   // Close old recordset
   Close();

   m_nRowsAffected = 0;

   // Create a new recordset
   CComQIPtr<IDBCreateCommand> spCreate = m_pDb->m_spSession;
   if( spCreate == NULL ) return FALSE;
   CComPtr<ICommand> spCommand;
   Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
   if( FAILED(Hr) ) return _Error(Hr);
   // Set type
   COledbDatabase::_SetRecordsetType(spCommand, lType, lOptions);
   // Set SQL
   CComQIPtr<ICommandText> spText = spCommand;
   _ASSERTE(spText);
   USES_CONVERSION;
   Hr = spText->SetCommandText(DBGUID_DBSQL, T2COLE(pstrSQL));
   if( FAILED(Hr) ) return _Error(Hr);

   // Execute...
   Hr = spText->Execute(NULL, IID_IRowset, NULL, &m_nRowsAffected, (LPUNKNOWN*) &m_spRowset);
   if( FAILED(Hr) ) return _Error(Hr);

   // Bind columns
   if( !_BindColumns() ) return FALSE;

   return MoveNext();
}
Esempio n. 4
0
BOOL CCsvDatabase::_BindColumns()
{
   USES_CONVERSION;
   // Count number of columns
   LPCSTR p = m_pstrText;
   if( *p == ';' ) p++;  // Sometimes column-definition line starts with a ';'-char
   if( *p == '\r' || *p == '\n' || *p == ' ' ) return _Error(1, _T("Junk at start of file"));
   m_nCols = 1;
   m_cSep = ',';
   m_bFixedWidth = false;
   bool bInsideQuote = false;
   bool bWasSpace = false;
   while( *p != '\n' ) {
      // Look for a possible new separator
      if( *p == ';' && m_nCols == 1 ) m_cSep = *p;
      if( *p == '\0' ) return _Error(2, _T("EOF before columns were defined"));
      // So is this a column, then?
      if( !bInsideQuote && *p == m_cSep ) m_nCols++;
      // Skip skip skip
      if( *p == '\"' ) bInsideQuote = !bInsideQuote;
      p++;
      if( *p == '\n' && bInsideQuote ) return _Error(2, _T("Unclosed quotes in field definition"));
   }
   // Create columns array
   m_pColumns = new CCsvColumn[m_nCols];
   // Ready for new run where we populate the columns
   p = m_pstrText;
   if( *p == ';' ) p++;
   bInsideQuote = false;
   bWasSpace = false;
   int iField = 0;
   int iWidth = 0;
   LPCSTR pstrName = p;
   while( *p != '\n' ) {
      if( !bInsideQuote && *p == m_cSep ) {
         // Populate column information
         m_pColumns[iField].iSize = iWidth;
         m_pColumns[iField].lOffset = p - pstrName;
         // A space before the field-separator indicates fixed-width.
         // The "fixed width"-flag is global so we only need to see it once.
         if( bWasSpace ) {
            m_bFixedWidth = true;
            // Trim name as well
            while( iWidth > 0 && pstrName[iWidth - 1] == ' ' ) iWidth--;
         }
         _tcsncpy(m_pColumns[iField].szName, A2CT(pstrName), iWidth);
         // Prepare for next column
         pstrName = ++p;
         iWidth = 0;
         iField++;
      }
      if( *p == '\"' ) bInsideQuote = !bInsideQuote;
      if( bInsideQuote ) m_pColumns[iField].iType = VT_BSTR;
      bWasSpace = (*p == ' ');
      iWidth++;
      p++;
   }
   return TRUE;
}
Esempio n. 5
0
void AppX11::setScreensaverDisabled(bool disabled) {
	if (d->inhibit == disabled)
		return;
	if (disabled) {
		if (!d->iface && !d->xss) {
			_Debug("Initialize screensaver functions.");
			_Debug("Try to connect 'org.gnome.SessionManager'.");
			d->iface = new QDBusInterface("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
			if (!(d->gnome = d->iface->isValid())) {
				_Debug("Failed to connect 'org.gnome.SessionManager'. Fallback to 'org.freedesktop.ScreenSaver'.");
				delete d->iface;
				d->iface = new QDBusInterface("org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver");
				if (!d->iface->isValid()) {
					_Debug("Failed to connect 'org.freedesktop.ScreenSaver'. Fallback to XResetScreenSaver().");
					delete d->iface;
					d->iface = nullptr;
					d->xss = true;
				}
			}
		}
		if (d->iface) {
			if (d->gnome)
				d->reply = d->iface->call("Inhibit", "CMPlayer", 0u, "Running player", 4u | 8u);
			else
				d->reply = d->iface->call("Inhibit", "CMPlayer", "Running player");
			if (!d->reply.isValid()) {
				_Error("DBus '%%' error: %%", d->iface->interface(), d->reply.error().message());
				_Error("Fallback to XResetScreenSaver().");
				delete d->iface;
				d->iface = nullptr;
				d->xss = true;
			} else
				_Debug("Disable screensaver with '%%'.", d->iface->interface());
		}
		if (d->xss) {
			_Debug("Disable screensaver with XResetScreenSaver().");
			d->ss_timer.start();
		}
	} else {
		if (d->iface) {
			auto response = d->iface->call(d->gnome ? "Uninhibit" : "UnInhibit", d->reply.value());
			if (response.type() == QDBusMessage::ErrorMessage)
				_Error("DBus '%%' error: [%%] %%", d->iface->interface(), response.errorName(), response.errorMessage());
			else
				_Debug("Enable screensaver with '%%'.", d->iface->interface());
		} else if (d->xss) {
			_Debug("Enable screensaver with XResetScreenSaver().");
			d->ss_timer.stop();
		}
	}
	d->inhibit = disabled;
}
Esempio n. 6
0
BOOL CSqlite3Recordset::Open(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
   _ASSERTE(m_pDb);
   _ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));

   USES_CONVERSION;
#if _ATL_VER > 0x0700 && WINVER >= 0x0500
   _acp = CP_UTF8;
#endif

   Close();

   m_ppSnapshot = NULL;
   m_pVm = NULL;
   m_nCols = 0;
   m_nRows = 0;
   m_fEOF = TRUE;
   m_lType = lType;
   m_lOptions = lOptions;

   switch( lType ) {
   case DB_OPEN_TYPE_FORWARD_ONLY:
      {
         LPCSTR pTrail = NULL;
         LPCSTR pstrZSQL = T2CA(pstrSQL);
         int iErr = ::sqlite3_prepare(*m_pDb, pstrZSQL, strlen(pstrZSQL), &m_pVm, &pTrail);
         if( iErr != SQLITE_OK ) return _Error(::sqlite3_errcode(*m_pDb), iErr, ::sqlite3_errmsg(*m_pDb));
         _ASSERTE(strlen(pTrail)==0);  // We don't really support batch SQL statements
         m_iPos = -1;
         m_fEOF = FALSE;
         m_nCols = ::sqlite3_column_count(m_pVm);
         MoveNext();
         return TRUE;
      }
      break;
   default:
      {
         LPSTR pstrErrorMsg = NULL;
         int iErr = ::sqlite3_get_table(*m_pDb, T2CA(pstrSQL), &m_ppSnapshot, &m_nRows, &m_nCols, &pstrErrorMsg);
         if( iErr != SQLITE_OK ) {
            _Error(::sqlite3_errcode(*m_pDb), iErr, pstrErrorMsg);
            if( pstrErrorMsg != NULL ) ::sqlite3_free(pstrErrorMsg);
            return FALSE;
         }
         m_iPos = 0;
         return TRUE;
      }
   }
}
Esempio n. 7
0
bool
KeyboardLayout::_GetShape(const parse_state& state, const char* data, Key& key)
{
	// the default
	key.shape = kRectangleKeyShape;
	key.dark = false;

	while (isalpha(data[0])) {
		switch (tolower(data[0])) {
			case 'r':
				key.shape = kRectangleKeyShape;
				break;
			case 'c':
				key.shape = kCircleKeyShape;
				break;
			case 'l':
				key.shape = kEnterKeyShape;
				break;
			case 'd':
				key.dark = true;
				break;

			default:
				_Error(state, "unknown shape specifier '%c'", data[0]);
				return false;
		}

		data++;
	}

	float width, height;
	if (!_GetSize(state, data, width, height, &key.second_row))
		return false;

	// don't accept second row with anything but kEnterKeyShape
	if ((key.shape != kEnterKeyShape && key.second_row != 0)
		|| (key.shape == kEnterKeyShape && key.second_row == 0)) {
		_Error(state, "shape size mismatch");
		return false;
	}

	key.frame.left = 0;
	key.frame.top = 0;
	key.frame.right = width;
	key.frame.bottom = height;

	return true;
}
void FAR reverse(ParamBlk FAR *parm)
{
        int i;
        MHANDLE mh_out;
        char FAR *  in_string;
        char FAR * out_string;


    // Check to see if we can allocate the memory needed

    if ((mh_out = _AllocHand(parm->p[0].val.ev_length+1)) == 0)
        _Error(182);             /* "Insufficient memory." */

    /*  Since this routine does not call any functions which cause memory
        reorganization, it is not necessary to _HLock the handles prior to
        dereferencing them (_HandToPtr).                                */

    in_string = _HandToPtr(parm->p[0].val.ev_handle);
    out_string = (char FAR *) _HandToPtr(mh_out) + parm->p[0].val.ev_length;

    *(out_string--) = '\0';         /* _RetChar() needs null terminated string */

    for (i = 0; i < parm->p[0].val.ev_length; i++)
        *(out_string--) = *(in_string++);

    _HLock(mh_out);                 /* Lock MHANDLE during callback. */
    _RetChar(out_string+1);

    _FreeHand(mh_out);              /* Free MHANDLEs we allocate, but not handles
                                       passed in ParamBlk. */
}
Esempio n. 9
0
void VdaMixer::adjust(VideoFormatData *data, const mp_image *mpi) {
	Q_ASSERT(data->imgfmt == IMGFMT_VDA);
	auto buffer = (CVPixelBufferRef)mpi->planes[3];
	switch (CVPixelBufferGetPixelFormatType(buffer)) {
	case kCVPixelFormatType_422YpCbCr8:
		data->type = IMGFMT_UYVY;
		break;
	case kCVPixelFormatType_422YpCbCr8_yuvs:
		data->type = IMGFMT_YUYV;
		break;
	case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
		data->type = IMGFMT_NV12;
		break;
	case kCVPixelFormatType_420YpCbCr8Planar:
		data->type = IMGFMT_420P;
		break;
	default:
		_Error("Not supported format.");
		data->type = IMGFMT_NONE;
	}
	auto desc = mp_imgfmt_get_desc(data->type);
	if (CVPixelBufferIsPlanar(buffer)) {
		data->planes = CVPixelBufferGetPlaneCount(buffer);
		Q_ASSERT(data->planes == desc.num_planes);
		for (int i=0; i<data->planes; ++i) {
			data->alignedByteSize[i].rwidth() = CVPixelBufferGetBytesPerRowOfPlane(buffer, i);
			data->alignedByteSize[i].rheight() = CVPixelBufferGetHeightOfPlane(buffer, i);
			data->bpp += desc.bpp[i] >> (desc.xs[i] + desc.ys[i]);
		}
	} else {
Esempio n. 10
0
BOOL COledbRecordset::MoveCursor(LONG lSkip, LONG lAmount)
{
   _ASSERTE(IsOpen());
   HRESULT Hr;

   ::ZeroMemory(m_pData, m_dwBufferSize);

   // Move the cursor and get some data
   HROW* rghRows = NULL;
   ULONG nRecevied;
   Hr = m_spRowset->GetNextRows(DB_NULL_HCHAPTER, lSkip, lAmount, &nRecevied, &rghRows);
   // Update EOF marker (HRESULT can be anything but S_OK)
   m_fEOF = Hr != S_OK;
   if( Hr != S_OK ) return TRUE; // Error or reached bottom

   // Get field values
   Hr = m_spRowset->GetData(*rghRows, m_hAccessor, m_pData);

   // Before we check the result, release the rows
   m_spRowset->ReleaseRows(nRecevied, rghRows, NULL, NULL, NULL);

   // Finally, check GetData() result...
   if( FAILED(Hr) ) return _Error(Hr);

   return TRUE;
}
Esempio n. 11
0
BOOL CSqlite3Recordset::MoveTop()
{
   _ASSERTE(IsOpen());
   if( m_lType == DB_OPEN_TYPE_FORWARD_ONLY ) return _Error(1, 1, "Invalid recordset type");
   m_iPos = 0;
   return TRUE;
}
Esempio n. 12
0
void StartGame(void)
{
	FILE	*fp;
	long	i;

        if(_started) _Error();

	fp = fopen("xmas.in", "r");
	assert(fp != NULL);
	fscanf(fp, "%ld%ld", &_n, &_rot);
	_real = 0;
	if(_rot == -1){
		fscanf(fp, "%ld", &_rot);
		_real = 1;
	}
	for(i = 0; i < _n; i++)
		fscanf(fp, "%ld", &_discA[i]);
	fclose(fp);
	fp = fopen("xmas.dat", "w");
	assert(fp != NULL);
	fprintf(fp, "%ld\n", _n);
	for(i = 0; i < _n; i++)
		fprintf(fp, "%ld ", _discA[i]);
	fprintf(fp, "\n");
	fclose(fp);
	_call = 0;
        _started = 1;
}
Esempio n. 13
0
BOOL COledbDatabase::BeginTrans(ISOLEVEL isoLevel)
{
   CComQIPtr<ITransactionLocal> spTransaction = m_spSession;
   if( spTransaction == NULL ) return FALSE;
   HRESULT Hr = spTransaction->StartTransaction(isoLevel, 0, NULL, NULL);
   return SUCCEEDED(Hr) ? TRUE : _Error(Hr);
}
Esempio n. 14
0
bool
KeyboardLayout::_GetPair(const parse_state& state, const char*& data,
	BString& name, BString& value)
{
	// Get name
	name = "";
	while (data[0] != '\0' && data[0] != '=') {
		name += data[0];
		data++;
	}

	if (data[0] != '=') {
		_Error(state, "no valid pair");
		return false;
	}

	// Skip sign
	data++;

	// Get value
	value = "";
	while (data[0] != '\0' && data[0] != '\n') {
		value += data[0];
		data++;
	}

	_Trim(name, false);
	_Trim(value, true);

	return true;
}
void FAR memrepl(ParamBlk  FAR *param)
{
	Locator locate;
	Value val;
        int memchan,skip;
        long memseek, memread, memfind;



    locate.l_type = 'R';
    locate.l_where = 1;
    locate.l_NTI = 1;

//      Store the offset of the memo field.
    locate.l_offset = param->p[0].val.ev_long - 1;
    memchan = _MemoChan(WORKAREA);              // Get the FCHAN to the memo file

    if((memfind = _FindMemo(&locate)) < 0)      // Find the offset of the memo
		_Error((int) memfind);

    memread = _MemoSize(&locate);               // Find the size of the memo field

    memseek = _FSeek(memchan, memfind, 0);      // Move the file pointer

//      Read in the memo field into our handle.
	if ((dbhand = _AllocHand((unsigned) memread)) == BADHANDLE) // Read from the memo file
        _Error(182);                            // Insufficient Memory.

	memread = _FRead(memchan, _HandToPtr(dbhand), (int) memread);


    val.ev_type = 'C';
    val.ev_handle = dbhand;
    val.ev_length = memread;

//      Move to the correct record in the database.
    if (param->pCount == 2)
       _DBRead(WORKAREA, param->p[1].val.ev_long);
    else
       _DBSkip(WORKAREA, 1);


    skip = _DBReplace(&locate,&val);        // Replace the memo field.

    _FreeHand(dbhand);                      // Free the handle previously allocated.

}
Esempio n. 16
0
BOOL COledbCommand::Create(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
   _ASSERTE(m_pDb->IsOpen());
   _ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));
   HRESULT Hr;

   Close();

   // Open the command
   CComQIPtr<IDBCreateCommand> spCreate = m_pDb->m_spSession;
   if( spCreate == NULL ) return FALSE;
   CComPtr<ICommand> spCommand;
   Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
   if( FAILED(Hr) ) return _Error(Hr);
   COledbDatabase::_SetRecordsetType(spCommand, lType, lOptions);
   m_spText = spCommand;
   _ASSERTE(m_spText);
   USES_CONVERSION;
   Hr = m_spText->SetCommandText(DBGUID_DBSQL, T2COLE(pstrSQL));
   if( FAILED(Hr) ) return _Error(Hr);

   // Prepare the command
   if( (lOptions & DB_OPTION_PREPARE) != 0 ) {
      CComQIPtr<ICommandPrepare> spPrepare = m_spText;
      _ASSERTE(spPrepare);
      if( spPrepare ) {
         Hr = spPrepare->Prepare(0);
         if( FAILED(Hr) ) return _Error(Hr);
      }
   }

   // Create parameter bindings memory area
   long cbAlloc = MAX_PARAMS * sizeof(DBBINDING);
   m_rgBindings = (DBBINDING*) ::CoTaskMemAlloc(cbAlloc);
   if( m_rgBindings == NULL ) return FALSE;
   ::ZeroMemory(m_rgBindings, cbAlloc);

   m_pData = ::CoTaskMemAlloc(MAX_PARAMBUFFER_SIZE);
   _ASSERTE(m_pData);
   if( m_pData == NULL ) return FALSE;
   ::ZeroMemory(m_pData, MAX_PARAMBUFFER_SIZE);

   m_nParams = 0;
   m_dwBindOffset = 0L;

   return TRUE;
}
Esempio n. 17
0
/*
 * _CopyAllLines - copy lines to clipboard
 */
void _CopyAllLines( LPWDATA w )
{
    LPLDATA     ld;
    ULONG       total;
    unsigned    len;
    char        *data;
    char        *ptr;
    unsigned    slen;
    LONG        rc;

    /*
     * get number of bytes
     */
    total = 0;
    for( ld = w->LineHead; ld != NULL; ld = ld->next ) {
        total += strlen( ld->data ) + 2;
    }
    if( total > MAX_BYTES ) {
        len = (unsigned) MAX_BYTES;
    } else {
        len = total;
    }

    /*
     * get memory block
     */
    rc = PAG_COMMIT | OBJ_GIVEABLE | PAG_WRITE;
    rc = DosAllocSharedMem( (PPVOID)&data, NULL, len + 1, rc );
    if( rc ) {
        _Error( NULLHANDLE, "Copy to Clipboard Error", "Out of Memory" );
        return;
    }

    /*
     * copy data into block
     */
    total = 0;
    ptr = data;
    for( ld = w->LineHead; ld != NULL; ld = ld->next ) {
        slen = strlen( ld->data ) + 2;
        if( total + slen > MAX_BYTES )
            break;
        memcpy( &ptr[total], ld->data, slen - 2 );
        ptr[total + slen - 2] = 0x0d;
        ptr[total + slen - 1] = 0x0a;
        total += slen;
    }
    ptr[total] = 0;

    /*
     * dump data to the clipboard
     */
    if( WinOpenClipbrd( _AnchorBlock ) ) {
        WinEmptyClipbrd( _AnchorBlock );
        WinSetClipbrdData( _AnchorBlock, (ULONG)data, CF_TEXT, CFI_POINTER );
        WinCloseClipbrd( _AnchorBlock );
    }

} /* _CopyAllLines */
Esempio n. 18
0
BOOL CSqlite3Database::Open(HWND /*hWnd*/, LPCTSTR pstrConnectionString, LPCTSTR /*pstrUser*/, LPCTSTR /*pstrPassword*/, long /*iType = DB_OPEN_DEFAULT*/)
{
   _ASSERTE(m_pSystem);
   _ASSERTE(pstrConnectionString);
   // Sqlite does not fail if the database doesn't exists; it creates it!
   if( ::GetFileAttributes(pstrConnectionString) == (DWORD) -1 ) return _Error(99, SQLITE_NOTFOUND, "Database does not exist");
   Close();
   // Open it...
   USES_CONVERSION;
   int iErr = ::sqlite3_open(T2CA(pstrConnectionString), &m_pDb);
   if( iErr != SQLITE_OK ) {
      if( m_pDb != NULL ) return _Error(::sqlite3_errcode(m_pDb), iErr, ::sqlite3_errmsg(m_pDb));
      return _Error(1, iErr, "Unable to open database");
   }
   ::sqlite3_busy_timeout(m_pDb, 10000L);
   return TRUE;
}
Esempio n. 19
0
BOOL CSqlite3Recordset::MoveBottom()
{
   _ASSERTE(IsOpen());
   if( m_lType == DB_OPEN_TYPE_FORWARD_ONLY ) return _Error(1, 1, "Invalid recordset type");
   if( m_nRows == 0 ) return FALSE;
   m_iPos = m_nRows - 1;
   return IsEOF();
}
Esempio n. 20
0
BOOL CSqlite3Recordset::MovePrev()
{
   _ASSERTE(IsOpen());
   if( m_lType == DB_OPEN_TYPE_FORWARD_ONLY ) return _Error(1, 1, "Invalid recordset type");
   if( m_iPos <= 0 ) return FALSE;
   --m_iPos;
   return TRUE;
}
Esempio n. 21
0
BOOL COledbDatabase::Connect()
{
   _ASSERTE(m_spInit);
   if( m_spInit == NULL ) return FALSE;

   // Initialize datasource
   HRESULT Hr = m_spInit->Initialize();
   if( FAILED(Hr) ) return _Error(Hr);

   // Create session
   CComQIPtr<IDBCreateSession> spCreateSession = m_spInit;
   if( spCreateSession == NULL ) return FALSE;
   Hr = spCreateSession->CreateSession(NULL, IID_IOpenRowset, (LPUNKNOWN*) &m_spSession);
   if( FAILED(Hr) ) return _Error(Hr);

   return TRUE;
}
Esempio n. 22
0
CBuffer *CPackager::PackUp( const void *pData, size_t dataLength )
{
	CCriticalSection::Owner lock( m_csRecv );

	if ( NULL == pData || dataLength < 3 /* cID + cPackFlag + ... */ )
	{
		return NULL;
	}

	BYTE cID = CPackager::Peek( pData );

	BUFFER_MAP::iterator it;

	if ( m_theRecv.end() == ( it = m_theRecv.find( cID ) ) )
	{
		CBuffer *pPack = m_theAllocator.Allocate();

		m_theRecv[cID] = pPack;
	}
	
	CBuffer *pBuffer = m_theRecv[cID];
	
	ASSERT( pBuffer );
	
	BYTE cFlag = CPackager::Peek( pData, 1 );

	const size_t nDataBegin = 1 + 1 + sizeof( unsigned long );
	
	if ( _Header( cFlag ) )
	{
		pBuffer->Empty();
		
		pBuffer->AddData( ( ( const char * )pData + nDataBegin ), dataLength - nDataBegin );
	}
	
	if ( _Middle( cFlag ) )
	{
		pBuffer->AddData( ( ( const char * )pData + nDataBegin ), dataLength - nDataBegin );
	}
	
	if ( _Tail( cFlag ) )
	{
		unsigned long lnUserData = *( const unsigned long * )( ( const char * )pData + 2 );

		pBuffer->SetUserData( lnUserData );

		pBuffer->AddRef();
		
		return pBuffer;
	}
	
	if ( _Error( cFlag ) )
	{
		ASSERT( NULL && "CPackager::PackUp - Invalid package!" );
	}

	return NULL;	
}
Esempio n. 23
0
BOOL CSqlite3Recordset::MoveAbs(DWORD dwPos)
{
   _ASSERTE(IsOpen());
   if( m_lType == DB_OPEN_TYPE_FORWARD_ONLY ) return _Error(1, 1, "Invalid recordset type");
   if( m_iPos < 0 ) return FALSE;
   if( m_iPos >= m_nRows ) return FALSE;
   m_iPos = (int) dwPos;
   return TRUE;
}
Esempio n. 24
0
bool
KeyboardLayout::_ParseTerm(const parse_state& state, const char*& data,
	BString& term, VariableMap& variables)
{
	if (!_GetTerm(data, _Delimiter(state.mode), term,
			state.mode == kKeyCodes)) {
		_Error(state, state.mode == kRowStart
			? "no valid row start" : "invalid term");
		return false;
	}

	BString unknown;
	if (!_SubstituteVariables(term, variables, unknown)) {
		_Error(state, "Unknown variable \"%s\"", unknown.String());
		return false;
	}

	return true;
}
Esempio n. 25
0
/*
 * _SaveAllLines - save all lines to a file
 */
void _SaveAllLines( LPWDATA w )
{
    char                fname[CCHMAXPATH + 1];
    FILEDLG             fdlg;
    HWND                hwmenu;
    FILE                *f;
    LPLDATA             ld;

    /*
     * go get file name
     */
    fname[0] = 0;
    memset( &fdlg, 0, sizeof( FILEDLG ) );
    fdlg.cbSize = sizeof( FILEDLG );
    fdlg.fl = FDS_SAVEAS_DIALOG | FDS_CENTER | FDS_PRELOAD_VOLINFO | FDS_ENABLEFILELB;
    fdlg.pszTitle = "Save File Name Selection";
    fdlg.pszOKButton = "~Save";
    strcpy( fdlg.szFullFile, "*.*" );

    hwmenu = WinWindowFromID( _MainFrameWindow, FID_MENU );
    if( WinFileDlg( HWND_DESKTOP, hwmenu, &fdlg ) ) {
        /*
         * save lines
         */
        if( fdlg.lReturn != DID_OK ) {
            return;
        }
        f = fopen( fdlg.szFullFile, "w" );
        if( f == NULL ) {
            _Error( hwmenu, fdlg.szFullFile, "Error opening file" );
            return;
        }
        for( ld = w->LineHead; ld != NULL; ld = ld->next ) {
            fprintf( f,"%s\n", ld->data );
        }
        fclose( f );
        _Error( hwmenu, fdlg.szFullFile, "Data saved to file" );
    } else {
        _Error( hwmenu, "Error", "Could not create dialog box" );
    }

} /* _SaveAllLines */
Esempio n. 26
0
BOOL COledbDatabase::CommitTrans()
{
   CComQIPtr<ITransaction> spTransaction = m_spSession;
   if( spTransaction == NULL ) return FALSE;
   BOOL bRetaining = FALSE;
   DWORD grfTC = XACTTC_SYNC;
   DWORD grfRM = 0;
   HRESULT Hr = spTransaction->Commit(bRetaining, grfTC, grfRM);
   _ASSERTE(SUCCEEDED(Hr));
   return SUCCEEDED(Hr) ? TRUE : _Error(Hr);
}
Esempio n. 27
0
BOOL COledbDatabase::RollbackTrans()
{
   CComQIPtr<ITransaction> spTransaction = m_spSession;
   if( spTransaction == NULL ) return FALSE;
   BOID* pboidReason = NULL;
   BOOL bRetaining = FALSE;
   BOOL bAsync = FALSE;
   HRESULT Hr = spTransaction->Abort(pboidReason, bRetaining, bAsync);
   _ASSERTE(SUCCEEDED(Hr));
   return SUCCEEDED(Hr) ? TRUE : _Error(Hr);
}
Esempio n. 28
0
BOOL COledbCommand::Execute(IDbRecordset* pRecordset /*= NULL*/)
{
   _ASSERTE(m_spText);
   HRESULT Hr;

   //CComQIPtr<ICommandWithParameters> spParams = m_spRowset;
   //_ASSERTE(spParams);
   //if( spParams==NULL ) return FALSE;
   //spParams->SetParameterInfo(m_nParams, ...);

   m_nRowsAffected = 0;

   // Create accessor
   CComQIPtr<IAccessor> spAccessor = m_spText;
   if( spAccessor == NULL ) return FALSE;

   if( m_nParams > 0 ) {
#ifdef _DEBUG
      DBBINDSTATUS stat[MAX_PARAMS] = { 0 };
      Hr = spAccessor->CreateAccessor(DBACCESSOR_PARAMETERDATA, m_nParams, m_rgBindings, m_dwBindOffset, &m_hAccessor, stat);
#else
      Hr = spAccessor->CreateAccessor(DBACCESSOR_PARAMETERDATA, m_nParams, m_rgBindings, m_dwBindOffset, &m_hAccessor, NULL);
#endif
      if( FAILED(Hr) ) return _Error(Hr);
   }

   DBPARAMS Params;
   Params.pData = m_pData;
   Params.cParamSets = m_nParams > 0 ? 1 : 0;
   Params.hAccessor = m_hAccessor;

   Hr = m_spText->Execute(NULL, IID_IRowset, &Params, &m_nRowsAffected, (LPUNKNOWN*) &m_spRowset);
   if( FAILED(Hr) ) return _Error(Hr);

   // Did we want to see the result set?
   if( m_spRowset != NULL && pRecordset != NULL ) {
      COledbRecordset* pRec = static_cast<COledbRecordset*>(pRecordset);
      return pRec->Attach(m_spRowset);
   }
   return TRUE;
}
Esempio n. 29
0
BOOL COledbDatabase::ExecuteSQL(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/, DWORD* pdwRowsAffected/*= NULL*/)
{
   USES_CONVERSION;
   HRESULT Hr;

   if( pdwRowsAffected ) *pdwRowsAffected = 0;
   CComQIPtr<IDBCreateCommand> spCreate = m_spSession;
   if( spCreate == NULL ) return FALSE;
   CComPtr<ICommand> spCommand;
   Hr = spCreate->CreateCommand(NULL, IID_ICommand, (LPUNKNOWN*) &spCommand);
   if( FAILED(Hr) ) return _Error(Hr);
   _SetRecordsetType(spCommand, lType, lOptions);
   CComQIPtr<ICommandText> spText = spCommand;
   _ASSERTE(spText);
   Hr = spText->SetCommandText(DBGUID_DBSQL, T2CW(pstrSQL));
   if( FAILED(Hr) ) return _Error(Hr);
   CComPtr<IRowset> spRowset;
   Hr = spText->Execute(NULL, IID_IRowset, NULL, (LONG*) pdwRowsAffected, (LPUNKNOWN*) &spRowset);
   if( FAILED(Hr) ) return _Error(Hr);
   return TRUE;
}
Esempio n. 30
0
CStringz operator +(CStringz&p1,CStringz &p2){	//add
	CStringz temp;
	temp.mh=_AllocHand(strlen(p1.str)+strlen(p2.str)+1);
	if (temp.mh==0) _Error(182);
	_HLock(temp.mh);
	temp.str=(char *)_HandToPtr(temp.mh);
	p1.Refresh();
	strcpy(temp.str,p1.str);
	p2.Refresh();
	strcat(temp.str,p2.str);
	_HUnLock(temp.mh);
	return temp;
}