fetchStyle in Editor server-side Result class

fetchStyle in Editor server-side Result class

csdatumcsdatum Posts: 30Questions: 10Answers: 0

There is currently no way to specify which fetch style to use in a sql query. A simple argument would be a very easy addition to the Results class. Something like this would work well:

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    How would you handle all the errors arising from bad "fetch styles" being submitted?

  • csdatumcsdatum Posts: 30Questions: 10Answers: 0

    I think documenting that it must be a PDO::fetch_* constant would be sufficient since it is simply passing it through to the fetch() and fetchAll() functions.

    Alternatively, some sort of Result->getStatement() function could be provided so users can get data in whatever style they like.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    The Editor libraries assume FETCH_ASSOC which is why it is specified that way in the drivers. I don't really see a problem with the suggestion you make though since it wouldn't effect anything in Editor (I presume you are making use of the Database classes external to Editor?).

    Allan

  • csdatumcsdatum Posts: 30Questions: 10Answers: 0

    Thank you for the response, yes that's correct. I wrote a couple of functions that use the database classes to apply some extra joins and where clauses as Editor fetches data. I'm trying to re-use those functions for different things apart from Editor, and having the ability to specify a fetch style would be very useful.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    I've done that now and it will be in Editor 1.7.4 - you simply pass the PDO fetch type you want into the Result->fetch() or Result->fetchAll() method.

    Worth noting that the Oracle and Db2 integrations in the PHP libraries don't use PDO so they won't work there.

    Allan

This discussion has been closed.