Hi,

On Thu, Apr 23, 2015 at 8:07 PM, Andreas Tille <[email protected]> wrote:

> Hi,
>
> However, to save my idea to avoid
> code duplication what about a helper returning a table
>
>    source   text,
>    bibentry text
>
> and use this helper in both functions that just return the bibentries.
> I'm just afraid that we might change anything later and will forget to
> change in both functions (been there to much times ;-)).
>
>
I was thinking we could modify generate_bibtex.py to:

 # create BibTeX file
      bf = open(self.bibtexfile, 'w')

      bibentry = "(SELECT DISTINCT source, package, rank FROM bibref) p "
      if self.all_ref == 1:
        query = "SELECT * FROM bibtex(bibentry)"
      else:
        bibentry += "INNER JOIN sources s ON s.source = p.source "
      query = "SELECT * FROM bibtex(bibentry)"

      cur.execute(query)
      for row in cur.fetchall():
          print >>bf, row[0]

      bf.close()

Thus, upgrade_bibtex.sql can take a parameter:

    CREATE OR REPLACE FUNCTION bibtex (text)
    RETURNS SETOF TEXT LANGUAGE SQL
    AS $$
        SELECT DISTINCT
             CASE
               ..........
               ..........
               ..........
     FROM $1
     LEFT OUTER JOIN bibref bibkey .......
     ........
     .......

What do you think of this solution to avoid code reduplication ? Do you
think this will work ?


Regards,
Akshita Jha

Reply via email to