Exemplo n.º 1
0
    def edit_memo(author_id: int, name: str, content: str) -> bool:
        with DatabaseConnection() as cursor:
            cursor.execute(
                """
                                INSERT INTO
                                    memo_line (memo_id, content)
                                VALUES (
                                    (
                                        SELECT
                                            id
                                        FROM
                                            memo
                                        WHERE
                                            author_id = %(author_id)s
                                        AND
                                            name LIKE %(name)s
                                        LIMIT 1
                                    ),
                                    %(content)s)
                                """, {
                    "author_id": author_id,
                    "name": name + "%",
                    "content": content
                })

            return cursor.rowcount > 0
Exemplo n.º 2
0
    def get_memo_line(author_id: int, name_part: str,
                      line_position: int) -> Union[str, None]:
        """line_position starts at 1"""
        if line_position < 1:
            raise ValueError("line_position must be > 0")

        with DatabaseConnection() as cursor:
            cursor.execute("SET @row_number = 0;")
            cursor.execute(
                """
                                SELECT
                                    content
                                FROM
                                    memo_line
                                WHERE
                                    memo_id
                                        =  (
                                                SELECT
                                                    id
                                                FROM
                                                    memo
                                                WHERE
                                                    author_id = %(author_id)s
                                                AND
                                                    name LIKE %(name_part)s
                                                LIMIT 1
                                            )
                                ORDER BY
                                    id
                                LIMIT
                                    %(line_position)s, 1
                                    
                                """, {
                    "author_id": author_id,
                    "name_part": name_part + "%",
                    "line_position": line_position - 1
                })

            result = cursor.fetchone()
            return result[0] if result else None