williambryan777 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Parameters not being substituted #97

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
======================================
Basically I was trying to replicate the example on the Project Page showing how 
to substitute query parameters. here is the code:

// C# Code
 var rc = new RoleComment
                         {
                             ROLE_ID = 1,
                             CANDIDATE_ID=1,
                             PERSONNEL_ID = 1,
                             COMMENT = "Hello there",
                             DATE = DateTime.Now.ToLocalTime().ToString()
                         };
            using (IDbConnection conn = Dal.OpenConnection(_dto.Database))
            {
             var newId=conn.Execute(
                    @"
insert into role_comments
(id, role_id, candidate_id, personnel_id, comment, date)
values(seq_role_comments.nextval, @RoleId, @CandidateId, @PersonnelId, 
@Comment, @CDate)
",new{RoleId = rc.ROLE_ID, CandidateId = rc.CANDIDATE_ID,
     PersonnelId = rc.PERSONNEL_ID,
     Comment = rc.COMMENT,
     CDate = rc.DATE
     });

What is the expected output? 
============================
insert into role_comments
(id, role_id, candidate_id, personnel_id, comment, date)
values(seq_role_comments.nextval, 1, 1, 1, 'Hello there', '12-May-2012')

What do you see instead?
========================
insert into role_comments
(id, role_id, candidate_id, personnel_id, comment, date)
values(seq_role_comments.nextval, @RoleId, @CandidateId, @PersonnelId, 
@Comment, @CDate)

It looks like the parameters have not been substituted. Is this an issue or 
have I just made a mistake?

What version of the product are you using? On what operating system?
====================================================================
I dropped the latest version of SQLMapper.cs into my project. I am on Windows 
XP/SP3 running VS2K10/SP1 against an Oracle database using the 
System.Data.OracleClient.

Please provide any additional information below.
================================================
For oracle INT datatypes I have to map to POCO decimal type. Not really a 
problem as I can query using the decimal types and they get the same results as 
the int32.

Original issue reported on code.google.com by pjsTar...@gmail.com on 10 May 2012 at 10:10

GoogleCodeExporter commented 9 years ago
Parametrised queries is a RDBMS feature; there is no string-based substitution 
- rather, your literal SQL is sent, along with appropriately typed/values 
parameters. In Oracle, IIRC the parameter symbol is `:`; so try:

    values(seq_role_comments.nextval, :RoleId, :CandidateId, :PersonnelId, :Comment, :CDate)

Original comment by marc.gravell on 10 May 2012 at 12:36

GoogleCodeExporter commented 9 years ago
Thanks for that Marc. It worked a treat.

Original comment by pjsTar...@gmail.com on 11 May 2012 at 8:22

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 11 May 2012 at 1:36