Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

OLEDB: Prepared cmd with NULL input param for NOT NULL INT..

 
   Database Help (Home) -> Client RSS
Next:  Anyone using Plone with Ingres?  
Author Message
neophyte

External


Since: Feb 23, 2005
Posts: 1



(Msg. 1) Posted: Wed Feb 23, 2005 2:11 am
Post subject: OLEDB: Prepared cmd with NULL input param for NOT NULL INT c
Archived from groups: microsoft>public>sqlserver>clients (more info?)

Provider: SQLOLEDB
Version: SQL Server 2000 8.00.760

Script for creating table:

CREATE TABLE [dbo].[ADRVERTRETER] (
  [ROWID] [timestamp] NULL ,
  [ROWVERTRETER] [int] NOT NULL ,
  [FIRMA] [smallint] NOT NULL ,
  [VERTRETER] [int] NOT NULL ,
  [NAME] [varchar] (20) COLLATE Latin1_General_CS_AS NULL ,
  [ROWADRESSEN] [int] NULL ,
  [PROVISION] [decimal](14, 2) NULL ,
  [STEUERKZ] [smallint] NULL ,
  [MITARBEITER] [int] NULL
) ON [PRIMARY]
GO

Command:
select NAME from ADRVERTRETER where VERTRETER = ?

When i execute the above command with a NULL parameter , i get the error:
"Invalid Input Parameter Value. Check Status Value for details"
If the unprepared command is executed , it does not give an error.

I am giving my test code below:

void main()
{


  HRESULT hr;
  CLSID clsid;
  ICommandText *pICommandText = NULL;
  ICommand *pICommand = NULL;
  IDBCreateSession *pIDBCreateSession = NULL;
  IDBCreateCommand *pIDBCreateCommand = NULL;
  IDBInitialize *pIDBInitialize = NULL;
  IDBProperties *pIDBProperties = NULL;
  ICommandPrepare *pICommandPrepare = NULL;
  ICommandWithParameters *pICommandWithParameters = NULL;
  IRowset *pIRowset = NULL;
  ICommandProperties *pICommandProperties = NULL;
  IAccessor *pIAccessor;
  HACCESSOR hAccessor;

  const ULONG nProps = 1;
  LONG cRowsAffected;
  DBBINDSTATUS* rgStatus = NULL;
  DBBINDSTATUS *pRowStatus = NULL;
  DBPROP InitProperties[ nProps ];
  DBPROPSET rgInitPropSet;


  DBPARAMS m_Params;
  DBBINDING ParamBinding[1];


  InitProperties[ 0 ].dwPropertyID = DBPROP_INIT_PROVIDERSTRING;
  InitProperties[ 0 ].vValue.vt = VT_BSTR;
  InitProperties[ 0 ].dwOptions = DBPROPOPTIONS_REQUIRED;
  InitProperties[ 0 ].colid = DB_NULLID;
  InitProperties[ 0 ].dwStatus = DBPROPSTATUS_OK;
  InitProperties[ 0 ].vValue.bstrVal =
  SysAllocString( OLESTR( "SERVER=son1205;DATABASE=pubs;uid=sa;pwd=sa;" ) );

  rgInitPropSet.guidPropertySet = DBPROPSET_DBINIT;
  rgInitPropSet.cProperties = nProps;
  rgInitPropSet.rgProperties = InitProperties;

  if( FAILED( hr = CoInitialize( NULL ) ) )
  {
   printf( "CoInitialize failed\n " );
   return;
  }

  hr = CLSIDFromProgID( L"SQLOLEDB", & clsid );

  if( FAILED( hr = CoCreateInstance( clsid,
   NULL,
   CLSCTX_INPROC_SERVER,
   IID_IDBInitialize,
   ( void ** ) & pIDBInitialize ) ) )
  {
   printf( "CoCreateInstance failed\n " );
   return;
  }

  hr = pIDBInitialize->QueryInterface( IID_IDBProperties,
   ( void ** ) & pIDBProperties );
  hr = pIDBProperties->SetProperties( 1, & rgInitPropSet );
  SysFreeString( InitProperties[ 0 ].vValue.bstrVal );
  pIDBProperties->Release();
  if( FAILED( hr = pIDBInitialize->Initialize() ) )
  {
   printf( "Failed to initializa Database\n " );
   return;
  }
  hr = pIDBInitialize->QueryInterface( IID_IDBCreateSession,
   ( void ** ) & pIDBCreateSession );

  if( FAILED( hr = pIDBCreateSession->CreateSession( NULL,
   IID_IDBCreateCommand,
   ( IUnknown ** ) & pIDBCreateCommand ) ) )
  {
   printf( "Session Initialization failed\n " );
   return;
  }

  if( FAILED( hr = pIDBCreateCommand->CreateCommand( NULL,
   IID_ICommand,
   ( IUnknown ** ) & pICommand ) ) )
  {
   printf( "Create Command failed\n " );
   return;
  }

  pIDBCreateCommand->Release();


  DBLENGTH cbRowSize = 0;
  ParamBinding[ 0 ].iOrdinal = 1;
  ParamBinding[ 0 ].obStatus = cbRowSize;
  cbRowSize += ROUNDUP(sizeof(DBSTATUS));
  ParamBinding[ 0 ].obLength = cbRowSize;
  cbRowSize += ROUNDUP(sizeof(DBLENGTH));
  ParamBinding[ 0 ].obValue = cbRowSize;
  ParamBinding[ 0 ].pTypeInfo = NULL;
  ParamBinding[ 0 ].pBindExt = NULL;
  ParamBinding[ 0 ].dwPart = DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;
  ParamBinding[ 0 ].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
  ParamBinding[ 0 ].eParamIO = DBPARAMIO_INPUT;
  ParamBinding[ 0 ].dwFlags = 0;
  ParamBinding[ 0 ].bPrecision = 0;
  ParamBinding[ 0 ].bScale = 0;
  ParamBinding[ 0 ].pObject = NULL;
  ParamBinding[ 0 ].wType = DBTYPE_NUMERIC;
  ParamBinding[ 0 ].cbMaxLen = 19;

  cbRowSize += ParamBinding[ 0 ].cbMaxLen;
  cbRowSize = ROUNDUP( cbRowSize );

  WCHAR* wSQLString = L"select NAME from ADRVERTRETER where VERTRETER = ?";

  hr = pICommand->QueryInterface( IID_ICommandText, ( void ** ) &
pICommandText );



  hr = pICommandText->SetCommandText( DBGUID_DBSQL, wSQLString );

  hr = pICommandText->QueryInterface( IID_IAccessor,
  ( void ** ) & pIAccessor );

  SAFE_ALLOC(rgStatus, DBBINDSTATUS, 1);

  hr = pIAccessor->CreateAccessor( DBACCESSOR_PARAMETERDATA,1,
   ParamBinding,
   sizeof( ParamBinding ),
   & hAccessor,
   rgStatus );

  SAFE_FREE(rgStatus);

  m_Params.cParamSets = 1;
  m_Params.hAccessor = hAccessor;


  //Also allocate memory
  SAFE_ALLOC(m_Params.pData, BYTE, cbRowSize);

  void* pValue = VALUE_IS_BOUND(ParamBinding[0]) ?
&BINDING_VALUE(ParamBinding[0], m_Params.pData) : NULL;

  if(STATUS_IS_BOUND(ParamBinding[0]))
   BINDING_STATUS(ParamBinding[0], m_Params.pData) = DBSTATUS_S_ISNULL;
  if(LENGTH_IS_BOUND(ParamBinding[0]))
   BINDING_LENGTH(ParamBinding[0], m_Params.pData) = 0;


  hr = pICommand->QueryInterface( IID_ICommandPrepare,
  (LPVOID*) &pICommandPrepare);

  if( SUCCEEDED( hr ) )
  hr = pICommandPrepare->Prepare( 0 );

  pICommandPrepare->Release();
  IRowset *pRowset = NULL;
  hr = pICommand->Execute( NULL,
   IID_IRowset,
   &m_Params,
   & cRowsAffected,
   (LPUNKNOWN *)&pRowset );

  if(FAILED(hr))
   GetError(pICommand,hr);

  m_Params.cParamSets = 0;
  SAFE_FREE(m_Params.pData);


  pIAccessor->ReleaseAccessor( hAccessor, NULL );
  pIAccessor->Release();
  pICommandText->Release();
  pICommand->Release();
  pIDBCreateSession->Release();
  pIDBInitialize->Release();
  CoUninitialize();
}

Please let me know if there is any error in th ecode.

Thanks

Neophyte

 >> Stay informed about: OLEDB: Prepared cmd with NULL input param for NOT NULL INT.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
[MS Design Tools] - Class not registered." - On a Windows 2000 pro workstation I am using SQL 2000 enterprise manager I am trying to return all rows, I get the error message "An unexpected error happened during this operation. [MS Design Tools] - Class not registered." I have reinstall...

Need help choosing front end for SQL Server - I've been working on an Access 97 database that's pretty much reached it's limit in terms of performance and reliability. Although it supports relatively few users (5-10 concurrent) it contains a lot of data (around 30 tables, some with several million..

SQL server tables read-only to ADP - I have successfully migrated an Access 2003 database to SQL server - at least all the tables and queries that resolve into views migrated successfully. I also sucessfully migrated all my forms and code into an ADP project. Everything works with one..

Opening table in SQL Server 2005? - This ought to be easy. But I can't figure out how to do it. Using Enterprise Manager in SQL Server 2000, I point to a table, select it, right click and choose Open Table-> Return all rows. Now I have the table open and I can edit to my heart's..

Programmatically Connect ADP/ADE to MSDERelA Subscription - What SQL Database Publication and Subscription security settings do I need for Users to be able to use my database in the following scenario: SQL database using Windows Authentication, on Laptops running WXPPro,SP2 logged onto <servername>.local...
   Database Help (Home) -> Client All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]