コード例 #1
0
        bl.save()
        print bl


    # select all Block.id after 3 june 2012 and Segment name is 1
    query = """
                SELECT Block.id, Segment.id, AnalogSignal.id
                FROM Block, Segment, AnalogSignal
                WHERE
                Block.id = Segment.block_id
                AND Segment.id = AnalogSignal.segment_id
                AND Block.rec_datetime > '2012-06-03'
                
                LIMIT 10
                """
    block_ids, segment_ids, analogsignal_ids= sql(query)
    print block_ids

    for i in range(block_ids.size):
        print i
        print ' block_id', block_ids[i]
        print ' segment_id', segment_ids[i]
        print ' analogsignal_id', analogsignal_ids[i]
        
        # load the Block
        bl = Block.load(block_ids[i])
        print ' ',bl.name
        
        # load the Segment
        seg = Segment.load( segment_ids[i] )
        print ' ',seg.name
コード例 #2
0
        bl.name = 'test sql %d' % i
        bl.save()
        print bl

    # select all Block.id after 3 june 2012 and Segment name is 1
    query = """
                SELECT Block.id, Segment.id, AnalogSignal.id
                FROM Block, Segment, AnalogSignal
                WHERE
                Block.id = Segment.block_id
                AND Segment.id = AnalogSignal.segment_id
                AND Block.rec_datetime > '2012-06-03'
                
                LIMIT 10
                """
    block_ids, segment_ids, analogsignal_ids = sql(query)
    print block_ids

    for i in range(block_ids.size):
        print i
        print ' block_id', block_ids[i]
        print ' segment_id', segment_ids[i]
        print ' analogsignal_id', analogsignal_ids[i]

        # load the Block
        bl = Block.load(block_ids[i])
        print ' ', bl.name

        # load the Segment
        seg = Segment.load(segment_ids[i])
        print ' ', seg.name
コード例 #3
0
            c = int(numpy.random.rand()*3)
            seg = Segment( 
                                        name = 'seg test',
                                        description = descriptions[c],
                                    )
            seg.block_id = bl.id
            seg.save()
    
    # static query for block
    query1 = """
                    SELECT block.id
                    FROM block
                    LIMIT 50
                    """
    #globals.globalsession.execute(query1)
    block_ids, = sql(query1)

    for block_id in block_ids:
        print 'block', block_id
        
        # variable query
        for description in descriptions:
            query2 = """
                            SELECT segment.id
                            FROM segment
                            WHERE
                            segment.block_id = :block_id
                            AND segment.description = :description
                            """
            # variables are given in sql with dict
            id_segments, = sql( query2, 
コード例 #4
0
    # create 5 Block with different dates
    for i in range(5):
        bl = Block(name = 'Block {}'.format(i),
                        rec_datetime = datetime.datetime(2012, 06, 1+i, 12,30,40)
                        )
        bl.save()
        print bl.id

    # select all Block.id after 3 june 2010
    query = """
                SELECT Block.id, Block.name
                FROM Block
                WHERE
                Block.rec_datetime > '2012-06-03'
                """
    ids, names = sql(query)
    print ids
    print names
    print type(names)



    # be CAREFUL if you select only one column
    # you need a coma even for one column

    # GOOD
    query = """
                SELECT Block.name
                FROM Block
                WHERE
                Block.rec_datetime > '2012-06-03'