Coder Social home page Coder Social logo

Comments (10)

bar avatar bar commented on June 15, 2024 3

@cemmerven I'm pretty sure you didn't mean to tag me, right?

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024 1

thanks for the feedback - I think I will implement a CommandType enum and corresponding command_type kwarg on relevant methods

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024 1

I still plan to work on this, I've just had a busy month. Plan to pick this up in the next week or so.

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024

Thanks for the issue! I’ll dig into this a bit and try to add some stored proc calls to the docs/test suite

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024

@cemmerven

this is taking a bit longer as calling sprocs doesn't "just work". Per the db api for procs, I need to think about how I can provide an interface for callproc. Which feels more natural?

Note that in pydapper, you pass params as ?paramname? as opposed to the @Param used by dapper.

Option 1

with pydapper.connect() as commands:
    commands.query_proc("MyProc ?param1? ?param2?", params={"param1": "Hello", "param2": "world"})

Option 2

with pydapper.connect() as commands:
    commands.query("MyProc ?param1? ?param2?", params={"param1": "Hello", "param2": "world"}, proc=True)

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024

it would be great to get some others input on this as well, esp if you have had experience using dapper directly. Tagging a few below..

@troyswanson
@deasko
@JonTheTurnip
@otosky
@bruce-dunwiddie

from pydapper.

bruce-dunwiddie avatar bruce-dunwiddie commented on June 15, 2024

this is taking a bit longer as calling sprocs doesn't "just work". Per the db api for procs, I need to think about how I can provide an interface for callproc. Which feels more natural?

Note that in pydapper, you pass params as ?paramname? as opposed to the @Param used by dapper.

Option 1

with pydapper.connect() as commands:
    commands.query_proc("MyProc ?param1? ?param2?", params={"param1": "Hello", "param2": "world"})

Option 2

with pydapper.connect() as commands:
    commands.query("MyProc ?param1? ?param2?", params={"param1": "Hello", "param2": "world"}, proc=True)

Option 2 is how I've seen it done in many languages, including core .Net classes, where it's just called through the same method, but specifying a "command type":

pyodbc apparently just depends on the "EXEC" syntax, https://code.google.com/archive/p/pyodbc/wikis/StoredProcedures.wiki , which seems to match up to @cemmerven 's second syntax attempt above:

commands.query_first( "execute sp_TestCall", param= { "foo": 1, "bar": U"some text" } )

from pydapper.

JonTheTurnip avatar JonTheTurnip commented on June 15, 2024

Hi all, I haven't thought about this too much but I think I'm also more in favor of option 2, I can't see any obvious problems with that approach.

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024

in the mean time @cemmerven, this should work for you with the current release

commands.query_first("exec sp_TestCall ?foo? ?bar?", param=dict(foo=1, bar="some text"))

from pydapper.

zschumacher avatar zschumacher commented on June 15, 2024

after trying multiple different solutions, I ultimately couldn't find something that work well in python without being kind of awkward for at least one of the DBMS' that pydapper supports. The reality is that callproc is inconsistently implemented across the various dbapis, and because of that its hard to come up with a consistent interface that works for everything.

For now, I'm not planning on putting this into a future release, but I will plan to continue to think on it.

The below will work on all pydapper methods, however and is the solution I recommend in the interim. As @bruce-dunwiddie mentioned, this is the path that pyodbc took for the same reason.

with pydapper.connect(MSSQL_URL) as commands:
    result = commands.query("EXEC GetTaskById @Id = ?id?", param={"id": 1})

from pydapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.