How to use the invenio.legacy.dbquery.run_sql function in invenio

To help you get started, we’ve selected a few invenio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inveniosoftware / invenio / invenio / legacy / bibrank / downloads_grapher.py View on Github external
def create_list_tuple_data(intervals, id_bibrec, id_bibdoc_query_addition=""):
    """-Return a list of tuple of the form [('10/2004',3),(..)] used to plot graph
        Where 3 is the number of downloads between 01/10/2004 and 31/10/2004"""
    list_tuple = []
    for elem in intervals:
        main_date_end = string.split(elem[1], '/')
        end_of_month_end = calendar.monthrange(int(main_date_end[1]), int(main_date_end[0]))[1]
        s0 = string.split(elem[0], "/")
        s1 = string.split(elem[1], "/")
        elem0 = s0[1] + "-" + s0[0]
        elem1 = s1[1] + "-" + s1[0]
        date1 = "%s%s" % (elem0, "-01 00:00:00")
        date2 = "%s%s" % (elem1, "-%s 00:00:00" % str(end_of_month_end))
        sql_query = """select count(*) from "rnkDOWNLOADS" where id_bibrec=%s %s and download_time>='%s' and download_time<'%s';""" % (id_bibrec, id_bibdoc_query_addition, date1, date2)
        res = run_sql(sql_query)[0][0]
        list_tuple.append((elem[0], res))
    #list_tuple = sort_list_tuple_by_date(list_tuple)
    return (list_tuple)
github zenodo / zenodo / zenodo / base / upgrades / openaire_2013_02_18_zenodo_data.py View on Github external
def do_upgrade():
    from invenio import config

    # Portalboxes upgrade
    run_sql("""DELETE FROM collection_portalbox WHERE id_portalbox=1 or id_portalbox=2;""")
    run_sql("""DELETE FROM portalbox WHERE id=1 or id=2;""")

    # Main collection name
    run_sql("UPDATE collection SET name=%s WHERE id=1", (config.CFG_SITE_NAME,))

    # Available tabs
    run_sql("""DELETE FROM collectiondetailedrecordpagetabs;""")
    for r in run_sql("""SELECT id FROM collection"""):
        run_sql("""INSERT INTO collectiondetailedrecordpagetabs VALUES (%s,'usage;comments;metadata;files')""", r)
github inveniosoftware / invenio / invenio / legacy / bibindex / termcollectors.py View on Github external
def _get_phrases_for_tokenizing(self, tag, recIDs):
        """
        Gets phrases for later tokenization
        for a range of records and specific tag.
        @param tag: MARC tag
        @param recIDs: list of specific recIDs (not range)
        """
        if len(recIDs) == 0:
            return ()
        bibXXx = "bib" + tag[0] + tag[1] + "x"
        bibrec_bibXXx = "bibrec_" + bibXXx
        query = """SELECT bb.id_bibrec,b.value FROM %s AS b, %s AS bb
                   WHERE bb.id_bibrec BETWEEN %%s AND %%s
                   AND bb.id_bibxxx=b.id AND tag LIKE %%s""" % (bibXXx, bibrec_bibXXx)
        phrases = run_sql(query, (self.first_recID, self.last_recID, tag))
        if tag == '8564_u':
            ## FIXME: Quick hack to be sure that hidden files are
            ## actually indexed.
            phrases = set(phrases)
            for recID in recIDs:
                for bibdocfile in BibRecDocs(recID).list_latest_files():
                    phrases.add((recID, bibdocfile.get_url()))
        #authority records
        pattern = tag.replace('%', '*')
        matches = fnmatch.filter(CFG_BIBAUTHORITY_CONTROLLED_FIELDS_BIBLIOGRAPHIC.keys(), pattern)
        if not len(matches):
            return phrases
        phrases = set(phrases)
        for tag_match in matches:
            authority_tag = tag_match[0:3] + "__0"
            for recID in recIDs:
github inveniosoftware / invenio / invenio / modules / upgrader / upgrades / invenio_2013_09_25_virtual_indexes.py View on Github external
run_sql("""INSERT INTO tag VALUES (202,'909C5x','909C5%')""")
    run_sql("""INSERT INTO tag VALUES (203,'909CSx','909CS%')""")
    run_sql("""INSERT INTO tag VALUES (204,'909COx','909CO%')""")
    run_sql("""INSERT INTO tag VALUES (205,'909CKx','909CK%')""")
    run_sql("""INSERT INTO tag VALUES (206,'909CPx','909CP%')""")
    run_sql("""INSERT INTO tag VALUES (207,'981x','981%')""")
    run_sql("""INSERT INTO tag VALUES (208,'982x','982%')""")
    run_sql("""INSERT INTO tag VALUES (209,'983x','983%')""")
    run_sql("""INSERT INTO tag VALUES (210,'984x','984%')""")
    run_sql("""INSERT INTO tag VALUES (211,'985x','985%')""")
    run_sql("""INSERT INTO tag VALUES (212,'986x','986%')""")
    run_sql("""INSERT INTO tag VALUES (213,'987x','987%')""")
    run_sql("""INSERT INTO tag VALUES (214,'988x','988%')""")
    run_sql("""INSERT INTO tag VALUES (215,'989x','989%')""")
    run_sql("""INSERT INTO tag VALUES (216,'author control','100__0')""")
    run_sql("""INSERT INTO tag VALUES (217,'institution control','110__0')""")
    run_sql("""INSERT INTO tag VALUES (218,'journal control','130__0')""")
    run_sql("""INSERT INTO tag VALUES (219,'subject control','150__0')""")
    run_sql("""INSERT INTO tag VALUES (220,'additional institution control', '260__0')""")
    run_sql("""INSERT INTO tag VALUES (221,'additional author control', '700__0')""")

    #6th step: add field tag mapping
    run_sql("""INSERT INTO field_tag VALUES (%s,17,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,18,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,157,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,158,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,159,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,160,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,161,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,162,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,163,10)""" % misc_field)
    run_sql("""INSERT INTO field_tag VALUES (%s,164,10)""" % misc_field)
github inveniosoftware / invenio / invenio / legacy / webbasket / db_layer.py View on Github external
query2A = "SELECT id_bibrec_or_bskEXTREC FROM bskREC WHERE id_bskBASKET=%s"
    local_and_external_ids = run_sql(query2A, (bskid,))
    external_ids = [local_and_external_id[0] for local_and_external_id in \
                    local_and_external_ids if local_and_external_id[0]<0]
    for external_id in external_ids:
        delete_item(bskid=bskid, recid=external_id, update_date_modification=False)

    query2B = "DELETE FROM bskREC WHERE id_bskBASKET=%s"
    run_sql(query2B, (bskid,))

    query3 = "DELETE FROM bskRECORDCOMMENT WHERE id_bskBASKET=%s"
    run_sql(query3, (bskid,))

    query4 = "DELETE FROM user_bskBASKET WHERE id_bskBASKET=%s"
    run_sql(query4, (bskid,))

    query5 = "DELETE FROM usergroup_bskBASKET WHERE id_bskBASKET=%s"
    run_sql(query5, (bskid,))

    return int(res)
github zenodo / zenodo / zenodo / base / upgrades / openaire_2013_03_07_zenodo_collections.py View on Github external
def do_upgrade():
    """ Implement your upgrades here  """
    # Wipe old collections
    run_sql("DELETE FROM collection")
    run_sql("DELETE FROM collectiondetailedrecordpagetabs")
    run_sql("DELETE FROM collection_collection")
    run_sql("DELETE FROM collectionname")

    run_sql("DELETE FROM accROLE_accACTION_accARGUMENT WHERE id_accROLE=12 OR id_accROLE=1 OR id_accROLE=3 OR id_accROLE=11")  # admin, any, auth, curator
    run_sql("DELETE FROM accROLE_accACTION_accARGUMENT WHERE id_accACTION=34 or id_accACTION=29")  # viewrestcoll/submit actions
    run_sql("DELETE FROM accARGUMENT")
    run_sql("UPDATE accROLE SET name='curators' WHERE id=12")

    for coll in collections:
        run_sql("INSERT INTO collection (id, name, dbquery) VALUES (%s, %s, %s)", coll)
        run_sql("INSERT INTO collectiondetailedrecordpagetabs (id_collection, tabs) VALUES (%s, 'usage;comments;metadata;files')", (coll[0],))

    for r in relations:
        run_sql("INSERT INTO collection_collection (id_dad, id_son, type, score) VALUES (%s, %s, %s, %s)", r)

    for arg in accargs:
        run_sql("INSERT INTO accARGUMENT (id, keyword, value) VALUES (%s, %s, %s)", arg)

    for r in restrictions:
        run_sql("INSERT INTO accROLE_accACTION_accARGUMENT (id_accROLE, id_accACTION, id_accARGUMENT, argumentlistid) VALUES (%s, %s, %s, %s)", r)

    for n in names:
github inveniosoftware / invenio / invenio / legacy / webstat / api.py View on Github external
    @param cols: Optionally, the name of the additional columns.
    @type cols: [str]

    @return: A status message
    @type: str
    """
    if event_id is None:
        return "Please specify a human-readable ID for the event."

    # Only accept id and name with standard characters
    if not re.search("[^\w]", str(event_id) + str(name)) is None:
        return "Please note that both event id and event name needs to be " + \
                  "written without any non-standard characters."

    # Make sure the chosen id is not already taken
    if len(run_sql("SELECT NULL FROM staEVENT WHERE id = %s",
                   (event_id, ))) != 0:
        return "Event id [%s] already exists! Aborted." % event_id

    # Check if the cols are valid titles
    for argument in cols:
        if (argument == "creation_time") or (argument == "id"):
            return "Invalid column title: %s! Aborted." % argument

    # Insert a new row into the events table describing the new event
    sql_param = [event_id]
    if name is not None:
        sql_name = "%s"
        sql_param.append(name)
    else:
        sql_name = "NULL"
    if len(cols) != 0:
github inveniosoftware / invenio / invenio / modules / upgrader / upgrades / invenio_2013_12_04_seqSTORE_larger_value.py View on Github external
def do_upgrade():
    """ Implement your upgrades here  """
    run_sql("ALTER TABLE seqSTORE MODIFY COLUMN seq_value varchar(60);")
github inveniosoftware / invenio / invenio / legacy / weblinkback / db_layer.py View on Github external
FROM lnkENTRYURLTITLE
                   WHERE
                """

    where_sql = ""

    if title_status == CFG_WEBLINKBACK_PAGE_TITLE_STATUS['NEW']:
        where_sql = " title='' AND manual_set=0 AND"
    elif title_status == CFG_WEBLINKBACK_PAGE_TITLE_STATUS['OLD']:
        where_sql = " title<>'' AND manual_set=0 AND"
    elif title_status == CFG_WEBLINKBACK_PAGE_TITLE_STATUS['MANUALLY_SET']:
        where_sql = " manual_set=1 AND"

    where_sql += " broken=0"

    return run_sql(top_query + where_sql)
github inveniosoftware / invenio / scripts / password_migration_kit.py View on Github external
def __get_admin_pwd():
    query = "SELECT password FROM user WHERE nickname='admin'"
    return run_sql(query)[0][0]