create table images(id int, image bytea);
insert into images values (1, pg_read_file('/path/to/image.jpg')::bytea);
create table images (id int, image oid);
insert into images values (1, lo_import('/path/to/image.jpg'));
import java.awt.Desktop;
import java.net.URI;
public class Main {
public static void main(final String args[]) {
URI uri = new URI("http://toster.ru");
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
def get_name(self,id):
with shelve.open("file.shv") as db:
return db[id].get('file_path')
ptext = '{} {} {} {}'.format(
row[0].strftime('%d.%m.%Y'),
row[1].strftime('%d.%m.%Y'),
row[2],
row[3]
)
Story.append(Paragraph(ptext, styles["Normal"]))
ptext = ''
for ndx, field in enumerate(row):
if ndx:
ptext += ' '
if isinstance(field, date):
ptext += field.strftime('%d.%m.%Y')
else:
ptext += str(field)
Story.append(Paragraph(ptext, styles["Normal"]))
ptext = ' '.join(field.strftime('%d.%m.%Y') if isinstance(field, date) else str(field) for field in row)
Story.append(Paragraph(ptext, styles["Normal"]))
class Session_cinema(db.Model):
film_id = db.Column(db.Integer(), db.ForeignKey('film.id'))
...
film = relationship('Film')
<td>{{ item.film.name }}</td>
JButton button = new JButton(
new ImageIcon("/path/to/image.png")
.getImage()
.getScaledInstance(buttonHeight, buttonWidth, java.awt.Image.SCALE_SMOOTH)
);
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class TestButton {
public static void main(String[] args) {
new TestButton();
}
private BufferedImage master;
public TestButton() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
try {
master = ImageIO.read(new File("/path/to/image.png"));
JButton btn = new JButton() {
@Override
public Dimension getPreferredSize() {
return new Dimension(90, 50);
}
};
btn.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
JButton btn = (JButton) e.getComponent();
Dimension size = btn.getSize();
Insets insets = btn.getInsets();
size.width -= insets.left + insets.right;
size.height -= insets.top + insets.bottom;
if (size.width > size.height) {
size.width = -1;
} else {
size.height = -1;
}
Image scaled = master.getScaledInstance(size.width, size.height, java.awt.Image.SCALE_SMOOTH);
btn.setIcon(new ImageIcon(scaled));
}
});
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(btn);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} catch (IOException exp) {
exp.printStackTrace();
}
}
});
}
}
@app.route('/session/list', methods=['GET', 'POST'])
def session_list():
return render_template('session_list.html', items=Session_cinema.query.all())
<!doctype html>
<html>
<body>
<table>
<tr>
<th>Дата</th>
<th>Время</th>
<th>Зал</th>
<th>Цена</th>
</tr>
{% for item in items %}
<tr>
<td>{{ item.date }}</td>
<td>{{ item.time }}</td>
<td>{{ item.hall }}</td>
<td>{{ item.price }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
create table rooms (id integer primary key, type varchar(7), number integer);
insert into rooms
(id, type, number)
values
(1, 'lux', 301),
(2, 'lux', 302),
(3, 'lux', 303);
create table booking (
id integer primary key,
start_date date,
end_date date,
room integer,
foreign key(room) references rooms(id)
);
insert into booking (id, start_date, end_date, room)
values
(1, '2016-11-29', '2016-12-01', 1),
(2, '2016-12-01', '2016-12-02', 2),
(3, '2016-12-02', '2016-12-02', 1),
(4, '2016-12-02', '2016-12-02', 3);
select number from rooms
where id not in (
select room from booking
where start_date > '2016-11-28' and start_date < '2016-11-30'
) and type = 'lux'
order by number
limit 1;
select distinct
a.question_id,
isnull(t5.val, 0) as '5',
isnull(t4.val, 0) as '4',
isnull(t3.val, 0) as '3',
isnull(t2.val, 0) as '2',
isnull(t1.val, 0) as '1'
from answers as a
left outer join (
select question_id, count(*) as val from answers where value = 5 group by question_id
) as t5 on a.question_id = t5.question_id
left outer join (
select question_id, count(*) as val from answers where value = 4 group by question_id
) as t4 on a.question_id = t4.question_id
left outer join (
select question_id, count(*) as val from answers where value = 3 group by question_id
) as t3 on a.question_id = t3.question_id
left outer join (
select question_id, count(*) as val from answers where value = 2 group by question_id
) as t2 on a.question_id = t2.question_id
left outer join (
select question_id, count(*) as val from answers where value = 1 group by question_id
) as t1 on a.question_id = t1.question_id;