• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python func.current_date函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlalchemy.func.current_date函数的典型用法代码示例。如果您正苦于以下问题:Python current_date函数的具体用法?Python current_date怎么用?Python current_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了current_date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_as_from

    def test_as_from(self):
        # TODO: shouldn't this work on oracle too ?
        x = func.current_date(bind=testing.db).execute().scalar()
        y = func.current_date(bind=testing.db).select().execute().scalar()
        z = func.current_date(bind=testing.db).scalar()
        w = select(['*'], from_obj=[func.current_date(bind=testing.db)]).\
            scalar()

        assert x == y == z == w
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:9,代码来源:test_functions.py


示例2: test_as_from

    def test_as_from(self):
        # TODO: shouldn't this work on oracle too ?
        x = func.current_date(bind=testing.db).execute().scalar()
        y = func.current_date(bind=testing.db).select().execute().scalar()
        z = func.current_date(bind=testing.db).scalar()
        w = select(['*'], from_obj=[func.current_date(bind=testing.db)]).\
            scalar()

        # construct a column-based FROM object out of a function,
        # like in [ticket:172]
        s = select([sql.column('date', type_=DateTime)],
                   from_obj=[func.current_date(bind=testing.db)])
        q = s.execute().first()[s.c.date]
        r = s.alias('datequery').select().scalar()

        assert x == y == z == w == q == r
开发者ID:anti-social,项目名称:sqlalchemy,代码行数:16,代码来源:test_functions.py


示例3: test_native_datetime

 def test_native_datetime(self):
     dbapi = testing.db.dialect.dbapi
     connect_args = {
         'detect_types': dbapi.PARSE_DECLTYPES | dbapi.PARSE_COLNAMES}
     engine = engines.testing_engine(
         options={'connect_args': connect_args, 'native_datetime': True})
     t = Table(
         'datetest', MetaData(),
         Column('id', Integer, primary_key=True),
         Column('d1', Date), Column('d2', sqltypes.TIMESTAMP))
     t.create(engine)
     try:
         engine.execute(t.insert(), {
             'd1': datetime.date(2010, 5, 10),
             'd2': datetime.datetime(2010, 5, 10, 12, 15, 25)
         })
         row = engine.execute(t.select()).first()
         eq_(
             row,
             (1, datetime.date(2010, 5, 10),
                 datetime.datetime(2010, 5, 10, 12, 15, 25)))
         r = engine.execute(func.current_date()).scalar()
         assert isinstance(r, util.string_types)
     finally:
         t.drop(engine)
         engine.dispose()
开发者ID:Attsun1031,项目名称:sqlalchemy,代码行数:26,代码来源:test_sqlite.py


示例4: test_conn_execute

    def test_conn_execute(self):
        from sqlalchemy.sql.expression import FunctionElement
        from sqlalchemy.ext.compiler import compiles

        class myfunc(FunctionElement):
            type = Date()

        @compiles(myfunc)
        def compile(elem, compiler, **kw):
            return compiler.process(func.current_date())

        conn = testing.db.connect()
        try:
            x = conn.execute(func.current_date()).scalar()
            y = conn.execute(func.current_date().select()).scalar()
            z = conn.scalar(func.current_date())
            q = conn.scalar(myfunc())
        finally:
            conn.close()
        assert (x == y == z == q) is True
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:20,代码来源:test_functions.py


示例5: req_has_access_to_node_id

    def req_has_access_to_node_id(node_id, accesstype, req=None, date=func.current_date()):
        # XXX: the database-independent code could move to core.node
        from core.transition import request
        from core.users import user_from_session

        if req is None:
            req = request

        user = user_from_session(req.session)

        # XXX: like in mysql version, what's the real solution?
        try:
            ip = IPv4Address(req.remote_addr)
        except AddressValueError:
            logg.warn("illegal IP address %s, refusing IP-based access", req.remote_addr)
            ip = None

        return Node.has_access_to_node_id(node_id, accesstype, user, ip, date)
开发者ID:mediatum,项目名称:mediatum,代码行数:18,代码来源:node.py


示例6: has_access_to_node_id

    def has_access_to_node_id(node_id, accesstype, user=None, ip=None, date=None):
        # XXX: the database-independent code could move to core.node
        from core import db
        from core.users import get_guest_user

        if user is None:
            user = get_guest_user()

        if user.is_admin:
            return True

        if ip is None:
            ip = IPv4Address("0.0.0.0")

        if date is None:
            date = func.current_date()

        accessfunc = access_funcs[accesstype]
        group_ids = user.group_ids
        access = accessfunc(node_id, group_ids, ip, date)
        return db.session.execute(select([access])).scalar()
开发者ID:mediatum,项目名称:mediatum,代码行数:21,代码来源:node.py


示例7: returned_on

    def returned_on(self, date=None):
        """
        Marks the loan as returned and clears loaned flag in related movies.
        """

        if date is None:
            date = func.current_date()
        # note that SQLAlchemy will convert YYYYMMDD strings to datetime, no need to touch it

        if self.return_date: # already returned, just update the date
            self.return_date = date
            return True

        session = object_session(self)

        if self.collection_id:
            self.collection.loaned = False # will update the loaned flag in all associated movies as well
        if self.volume_id:
            self.volume.loaned = False # will update the loaned flag in all associated movies as well
        if self.movie_id:
            self.movie.loaned = False
        self.return_date = date
开发者ID:BackupTheBerlios,项目名称:griffith-svn,代码行数:22,代码来源:_objects.py


示例8: test_text_in_select_nonfrom

    def test_text_in_select_nonfrom(self):

        generate_series = text("generate_series(:x, :y, :z) as s(a)").\
            bindparams(x=None, y=None, z=None)

        s = select([
            (func.current_date() + literal_column("s.a")).label("dates")
        ]).select_from(generate_series)

        self.assert_compile(
            s,
            "SELECT CURRENT_DATE + s.a AS dates FROM "
            "generate_series(:x, :y, :z) as s(a)",
            checkparams={'y': None, 'x': None, 'z': None}
        )

        self.assert_compile(
            s.params(x=5, y=6, z=7),
            "SELECT CURRENT_DATE + s.a AS dates FROM "
            "generate_series(:x, :y, :z) as s(a)",
            checkparams={'y': 6, 'x': 5, 'z': 7}
        )
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:22,代码来源:test_text.py


示例9: build_accessfunc_arguments

def build_accessfunc_arguments(user=None, ip=None, date=None, req=None):
    """Build the expected arguments for the DB permission procedures has_*_access_to_node()
    IP and date are returned unchanged when passed to this function. 
    For missing arguments, default values are set from request information or current date.
    :returns: 3-tuple of group_ids, ip and date
        For admin users, it returns (None, None, None) which means: ignore all access checks.
        Users can test for this and skip permission checks completely.
    """
    from core.users import get_guest_user

    if user is None and ip is None:
        if req is None:
            req = request

        from core.users import user_from_session

        user = user_from_session(req.session)
        # XXX: like in mysql version, what's the real solution?
        try:
            ip = IPv4Address(req.remote_addr)
        except AddressValueError:
            logg.warn("illegal IP address %s, refusing IP-based access", req.remote_addr)
            ip = None

    if user is None:
        user = get_guest_user()

    # admin sees everything ;)
    if user.is_admin:
        return (None, None, None)

    if ip is None:
        ip = IPv4Address("0.0.0.0")
    
    if date is None:
        date = sqlfunc.current_date()

    return user.group_ids, ip, date
开发者ID:mediatum,项目名称:mediatum,代码行数:38,代码来源:__init__.py


示例10: compile

 def compile(elem, compiler, **kw):
     return compiler.process(func.current_date())
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:2,代码来源:test_functions.py


示例11: setup_class

    def setup_class(cls):
        global t, f, f2, ts, currenttime, metadata, default_generator

        db = testing.db
        metadata = MetaData(db)
        default_generator = {"x": 50}

        def mydefault():
            default_generator["x"] += 1
            return default_generator["x"]

        def myupdate_with_ctx(ctx):
            conn = ctx.connection
            return conn.execute(sa.select([sa.text("13")])).scalar()

        def mydefault_using_connection(ctx):
            conn = ctx.connection
            try:
                return conn.execute(sa.select([sa.text("12")])).scalar()
            finally:
                # ensure a "close()" on this connection does nothing,
                # since its a "branched" connection
                conn.close()

        use_function_defaults = testing.against("postgresql", "mssql", "maxdb")
        is_oracle = testing.against("oracle")

        # select "count(1)" returns different results on different DBs also
        # correct for "current_date" compatible as column default, value
        # differences
        currenttime = func.current_date(type_=sa.Date, bind=db)
        if is_oracle:
            ts = db.scalar(
                sa.select([func.trunc(func.sysdate(), sa.literal_column("'DAY'"), type_=sa.Date).label("today")])
            )
            assert isinstance(ts, datetime.date) and not isinstance(ts, datetime.datetime)
            f = sa.select([func.length("abcdef")], bind=db).scalar()
            f2 = sa.select([func.length("abcdefghijk")], bind=db).scalar()
            # TODO: engine propigation across nested functions not working
            currenttime = func.trunc(currenttime, sa.literal_column("'DAY'"), bind=db, type_=sa.Date)
            def1 = currenttime
            def2 = func.trunc(sa.text("sysdate"), sa.literal_column("'DAY'"), type_=sa.Date)

            deftype = sa.Date
        elif use_function_defaults:
            f = sa.select([func.length("abcdef")], bind=db).scalar()
            f2 = sa.select([func.length("abcdefghijk")], bind=db).scalar()
            def1 = currenttime
            deftype = sa.Date
            if testing.against("maxdb"):
                def2 = sa.text("curdate")
            elif testing.against("mssql"):
                def2 = sa.text("getdate()")
            else:
                def2 = sa.text("current_date")
            ts = db.scalar(func.current_date())
        else:
            f = len("abcdef")
            f2 = len("abcdefghijk")
            def1 = def2 = "3"
            ts = 3
            deftype = Integer

        t = Table(
            "default_test1",
            metadata,
            # python function
            Column("col1", Integer, primary_key=True, default=mydefault),
            # python literal
            Column("col2", String(20), default="imthedefault", onupdate="im the update"),
            # preexecute expression
            Column("col3", Integer, default=func.length("abcdef"), onupdate=func.length("abcdefghijk")),
            # SQL-side default from sql expression
            Column("col4", deftype, server_default=def1),
            # SQL-side default from literal expression
            Column("col5", deftype, server_default=def2),
            # preexecute + update timestamp
            Column("col6", sa.Date, default=currenttime, onupdate=currenttime),
            Column("boolcol1", sa.Boolean, default=True),
            Column("boolcol2", sa.Boolean, default=False),
            # python function which uses ExecutionContext
            Column("col7", Integer, default=mydefault_using_connection, onupdate=myupdate_with_ctx),
            # python builtin
            Column("col8", sa.Date, default=datetime.date.today, onupdate=datetime.date.today),
            # combo
            Column("col9", String(20), default="py", server_default="ddl"),
        )
        t.create()
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:88,代码来源:test_defaults.py


示例12: User


# Create dummy user
User1 = User(name="Guru Shetti", email="[email protected]",
             picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png')
session.add(User1)
session.commit()

# Menu for UrbanBurger
catalog_header1 = CatalogHeader(user_id=1, name="Soccer")

session.add(catalog_header1)
session.commit()

catalogItem2 = CatalogItem(user_id=1, name="Soccer Cleats", description="Really Fast",
                     price="$7.50", section="Women", first_stock_date= func.current_date(), image="shoes.jpg",  catalog_header=catalog_header1)

session.add(catalogItem2)
session.commit()


catalogItem1 = CatalogItem(user_id=1, name="Shin Guards", description="Max Protection",
                     price="$2.99", section="Men", first_stock_date= datetime.date(2015,06,15), image="shoes.jpg", catalog_header=catalog_header1)

session.add(catalogItem1)
session.commit()

catalogItem2 = CatalogItem(user_id=1, name="Shirt", description="Dry Fit",
                     price="$5.50", section="Women", first_stock_date= datetime.date(2015,06,15), image="swimtrunk.jpg", catalog_header=catalog_header1)

session.add(catalogItem2)
开发者ID:gurugithub,项目名称:catalog,代码行数:29,代码来源:lotsofitems.py


示例13: showCatalogHeaders

def showCatalogHeaders():
    catalog_headers = session.query(CatalogHeader).order_by(asc(CatalogHeader.name))
    items_with_category = session.query(CatalogHeader, CatalogItem).filter(CatalogHeader.id == CatalogItem.catalog_header_id).filter(CatalogItem.first_stock_date == func.current_date()).all()
    
    if 'username' not in login_session:
        return render_template('publiccatalog.html', catalog_headers=catalog_headers, items_with_category=items_with_category)
    else:
        return render_template('catalog.html', catalog_headers=catalog_headers, items_with_category=items_with_category)
开发者ID:gurugithub,项目名称:catalog,代码行数:8,代码来源:application.py


示例14: Column

    Column('image', Unicode(128)), # XXX: deprecated
    )

people = Table('people', metadata,
    Column('person_id', Integer, primary_key=True),
    Column('name', Unicode(256), nullable=False, unique=True),
    Column('email', Unicode(128)),
    Column('phone', Unicode(64)))

loans = Table('loans', metadata,
    Column('loan_id', Integer, primary_key=True),
    Column('person_id',  ForeignKey(people.c.person_id), nullable=False),
    Column('movie_id', ForeignKey(movies.c.movie_id), nullable=False),
    Column('volume_id', ForeignKey(volumes.c.volume_id)),
    Column('collection_id', ForeignKey(collections.c.collection_id)),
    Column('date', Date, nullable=False, default=func.current_date()),
    Column('return_date', Date, nullable=True))

languages = Table('languages', metadata,
    Column('lang_id', Integer, primary_key=True),
    Column('name', Unicode(64), nullable=False, unique=True))

acodecs = Table('acodecs', metadata,
    Column('acodec_id', Integer, primary_key=True),
    Column('name', Unicode(64), nullable=False, unique=True))

achannels = Table('achannels', metadata,
    Column('achannel_id', Integer, primary_key=True),
    Column('name', Unicode(64), nullable=False, unique=True))

subformats = Table('subformats', metadata,
开发者ID:BackupTheBerlios,项目名称:griffith-svn,代码行数:31,代码来源:tables.py


示例15: setup_class

    def setup_class(cls):
        global t, f, f2, ts, currenttime, metadata, default_generator

        db = testing.db
        metadata = MetaData(db)
        default_generator = {'x': 50}

        def mydefault():
            default_generator['x'] += 1
            return default_generator['x']

        def myupdate_with_ctx(ctx):
            conn = ctx.connection
            return conn.execute(sa.select([sa.text('13')])).scalar()

        def mydefault_using_connection(ctx):
            conn = ctx.connection
            try:
                return conn.execute(sa.select([sa.text('12')])).scalar()
            finally:
                # ensure a "close()" on this connection does nothing,
                # since its a "branched" connection
                conn.close()

        use_function_defaults = testing.against('postgresql', 'mssql')
        is_oracle = testing.against('oracle')

        class MyClass(object):
            @classmethod
            def gen_default(cls, ctx):
                return "hi"

        # select "count(1)" returns different results on different DBs also
        # correct for "current_date" compatible as column default, value
        # differences
        currenttime = func.current_date(type_=sa.Date, bind=db)
        if is_oracle:
            ts = db.scalar(sa.select([func.trunc(func.sysdate(), sa.literal_column("'DAY'"), type_=sa.Date).label('today')]))
            assert isinstance(ts, datetime.date) and not isinstance(ts, datetime.datetime)
            f = sa.select([func.length('abcdef')], bind=db).scalar()
            f2 = sa.select([func.length('abcdefghijk')], bind=db).scalar()
            # TODO: engine propigation across nested functions not working
            currenttime = func.trunc(currenttime, sa.literal_column("'DAY'"), bind=db, type_=sa.Date)
            def1 = currenttime
            def2 = func.trunc(sa.text("sysdate"), sa.literal_column("'DAY'"), type_=sa.Date)

            deftype = sa.Date
        elif use_function_defaults:
            f = sa.select([func.length('abcdef')], bind=db).scalar()
            f2 = sa.select([func.length('abcdefghijk')], bind=db).scalar()
            def1 = currenttime
            deftype = sa.Date
            if testing.against('mssql'):
                def2 = sa.text("getdate()")
            else:
                def2 = sa.text("current_date")
            ts = db.scalar(func.current_date())
        else:
            f = len('abcdef')
            f2 = len('abcdefghijk')
            def1 = def2 = "3"
            ts = 3
            deftype = Integer

        t = Table('default_test1', metadata,
            # python function
            Column('col1', Integer, primary_key=True,
                   default=mydefault),

            # python literal
            Column('col2', String(20),
                   default="imthedefault",
                   onupdate="im the update"),

            # preexecute expression
            Column('col3', Integer,
                   default=func.length('abcdef'),
                   onupdate=func.length('abcdefghijk')),

            # SQL-side default from sql expression
            Column('col4', deftype,
                   server_default=def1),

            # SQL-side default from literal expression
            Column('col5', deftype,
                   server_default=def2),

            # preexecute + update timestamp
            Column('col6', sa.Date,
                   default=currenttime,
                   onupdate=currenttime),

            Column('boolcol1', sa.Boolean, default=True),
            Column('boolcol2', sa.Boolean, default=False),

            # python function which uses ExecutionContext
            Column('col7', Integer,
                   default=mydefault_using_connection,
                   onupdate=myupdate_with_ctx),

#.........这里部分代码省略.........
开发者ID:Affirm,项目名称:sqlalchemy,代码行数:101,代码来源:test_defaults.py


示例16: daily_amount_select

 def daily_amount_select():
     return select([func.cast(func.sum(SalesOrderLine.unit_price * SalesOrderLine.quantity)
                    /func.greatest(func.cast(func.date_part('DAY', func.current_date() - Supplier.create_date),Integer), 1), Integer)]).as_scalar()
开发者ID:betterlife,项目名称:psi,代码行数:3,代码来源:supplier_sales.py


示例17: get_where

 def get_where(current_sel):
     return current_sel.where(SalesOrder.order_date >= func.date_trunc('month', func.current_date()))
开发者ID:betterlife,项目名称:psi,代码行数:2,代码来源:supplier_sales.py


示例18: newCatalogItem

def newCatalogItem(catalog_header_id):
    print "In new items"
    
    if 'username' not in login_session:
        return redirect('/login')
    catalog_header = session.query(CatalogHeader).filter_by(id=catalog_header_id).one()
    print catalog_header.user_id, login_session['user_id']
    if login_session['user_id'] != catalog_header.user_id:
        return "<script>function myFunction() {alert('You are not authorized to add catalogitems items to this catalog. Please create your own catalog in order to add items.');}</script><body onload='myFunction()''>"
     
    if request.method == 'POST':
            print "In post"
            newItem = CatalogItem(name=request.form['name'], description=request.form['description'], price=request.form[
                               'price'], section=request.form['section'], catalog_header_id=catalog_header_id, user_id=catalog_header.user_id, first_stock_date=func.current_date())
            session.add(newItem)
            session.commit()
            flash('New Catalog Item %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showCatalogItems', catalog_header_id=catalog_header_id))
    else:
        print "In login not same"
        return render_template('newcatalogitem.html', catalog_header_id=catalog_header_id)
开发者ID:gurugithub,项目名称:catalog,代码行数:21,代码来源:application.py


示例19: list

def list(request):
    events = Event.query.filter(cast(Event.start_time, Date) >= func.current_date()).order_by(Event.start_time.asc())
    return {'events': events}
开发者ID:binarydud,项目名称:almanac,代码行数:3,代码来源:views.py


示例20: __init__

 def __init__(self, diag, paciente):
     self.fecha= func.current_date()
     self.comentarios= diag
     self.paciente = paciente
开发者ID:Lufedi,项目名称:DABM-Bitalino,代码行数:4,代码来源:Base.py



注:本文中的sqlalchemy.func.current_date函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python func.current_timestamp函数代码示例发布时间:2022-05-27
下一篇:
Python func.count函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap