File: tutorial.html

package info (click to toggle)
sqlkit 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,184 kB
  • sloc: python: 17,477; sql: 166; makefile: 95; xml: 23; sh: 11
file content (760 lines) | stat: -rw-r--r-- 36,737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      
      <title>
    Sqledit Tutorial
 &mdash; sqlkit v0.9.5 documentation</title>
      
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/sqlkit.css" type="text/css" />
    <link rel="stylesheet" href="../_static/print.css" type="text/css" media="print" />

    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="top" title="sqlkit v0.9.5 documentation" href="../index.html" />
        <link rel="up" title="Mailing list" href="tutorials.html" />
        <link rel="next" title="Sqledit - the standalone program to browse and edit data" href="sqledit.html" />
        <link rel="prev" title="Mailing list" href="tutorials.html" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../',
          0.9.5SION:     '0.9.5',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>


<!-- <link rel="stylesheet" href="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jMenu.jquery.css" type="text/css" /> -->
      <link rel="stylesheet" href="../_static/jMenu.jquery.css" type="text/css" />
      <script type="text/javascript" src="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jquery.js"></script>
      <script type="text/javascript" src="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jquery-ui.js"></script>

      <!-- <script type="text/javascript" src="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jMenu.jquery.js"></script> -->

      <script type="text/javascript">

	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-18221996-2']);
	_gaq.push(['_trackPageview']);

	(function() {
	  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();

      </script>
      <script type="text/javascript" src="../_static/jMenu.jquery.js"></script>
      <script type="text/javascript">
	      $(document).ready(function(){
		      $("#jMenu").jMenu({
			      ulWidth : '150',
			      effects : {
				      effectSpeedOpen : 300,
				      effectSpeedClose : 300,
				      effectTypeOpen : 'slide',
				      effectTypeClose : 'slide',
				      effectOpen : 'linear',
				      effectClose : 'linear'
			      },
			      TimeBeforeOpening : 100,
			      TimeBeforeClosing : 400,
			      animatedText : false,
			      paddingLeft: 1		});
	      })
      </script>
<!-- Preview -->
     <script type="text/javascript" src="../_static/imgpreview.js"></script>
     <script type="text/javascript">
       $(document).ready(function(){
           $('.preview').imgPreview();
       });
     </script>
     
     <!--[if !IE 7]>
	     <style type="text/css">
		     #wrap {display:table;height:100%}
	     </style>
     <![endif]-->
    </head>
    <body>
        




<div id="wrap">
    
<div id="header">

	<div class="logo"><a href="tour.html">
       <img src="../_static/sqlkit.png" align="left"  alt="Logo" border="0"/></a>
        </div>
	<div id="description">Acces to db made easy</div>
</div>


   <div style="clear:left;"></div>


<div >
	<ul id="jMenu">
            <li><a class="fNiv" href="../index.html" title="Home" 
                  >Home</a></li>

            <li><a li class="fNiv" href="../sqlkit/contents.html"
                  title="Sqlkit - the python package" 
                  >Sqlkit</a>

	       <ul>
		 <li ><a href="../sqlkit/contents.html"
		       title="Sqlkit - the python package" 
		       >Sqlkit</a></li>

		 <li ><a href="../sqlkit/sqlwidget.html" title="Widgets" 
		       >Widgets</a>
		       <ul> 
			 <li ><a href="../sqlkit/mask.html" title="Mask" 
			       >Mask view</a></li>
			 <li ><a href="../sqlkit/table.html" title="Table" 
			       >Table view</a></li>
		       </ul>
                 </li>
		 <li ><a href="../sqlkit/browsing.html" title="Browsing Data" 
		       >Browsing data</a>
		    <ul> 
		      <li ><a href="../sqlkit/constraints.html" title="Constraints" 
			    >Constraints</a></li>
		      <li ><a href="../sqlkit/filters.html" title="Filters" 
			    >Filters</a></li>
		      <li ><a href="../sqlkit/totals.html" title="Totals" 
			    >Totals</a></li>
		    </ul>
                 </li>
		 <li ><a href="../sqlkit/editing.html" title="Editing Data" 
		       >Editing data</a>
			 <ul> 
			   <li ><a href="../sqlkit/completion.html" title="Completion" 
				 >Completion</a></li>
			   <li ><a href="../sqlkit/validation.html" title="Validation" 
				 >Validation</a></li>
			   <li ><a href="../sqlkit/relationship.html" title="Relationships" 
				 >Relationships</a></li>
			 </ul>
		       </li>
		 <li ><a href="../sqlkit/printing.html" title="Printing" 
		       ><span>Printing</span></a></li>
		 <li ><a href="../sqlkit/advanced/contents.html" title="Advanced configuration" 
		       >Advanced configuration</a>
			 <ul> 
			   <li ><a href="../sqlkit/advanced/fields.html" title="Fields" 
				 >Fields</a></li>
			   <li ><a href="../sqlkit/advanced/views.html" title="Views" 
				 >Views</a></li>
			 </ul>
		       </li>

	       </ul>
            </li>

            <li><a class="fNiv" href="sqledit.html"
                  title="Sqledit GUI" 
                  >Sqledit GUI</a></li>

            <li><a class="fNiv" href="tutorials.html"
                  title="Support & tutorials" 
                  >Support & Tutorials</a>
	       <ul>
		 <li ><a href="sqledit.html"
		       title="Sqledit - the application" 
		       >Sqledit - the application</a></li>
		 <li ><a href="tour.html"
		       title="Sqlkit - the features'tour"
		       >Sqlkit - features' tour</a></li>
		 <li ><a href="sqledit.html"
		       title="Sqledit - the application" 
		       >Installing instructions</a></li>
		</ul> 
            </li>

            <li><a class="fNiv" href="../layout/contents.html" title="Layout"
                  >Layout</a></li>

            <li><a  class="fNiv"href="contents.html" title="Download" 
                  >Download</a>

	       <ul>
		 <li ><a href="contents.html"
		       title="Download"
		       >Download</a></li>
		 <li ><a href="http://sqlkit.argolinux.org/download/Changelog"  title="Changelog"
		       title="Changelog"
		       >Changelog</a></li>
		 <li ><a href="backward_incompatibilities.html"
		       title="Backward incompatibilities"
		       >Backward incompatibilities</a></li>
	       </ul>
            </li>



        </ul>
</div>
   <div style="clear:left;"></div>

    
    <div class="related">
      <ul>
	
<!-- <div class="prevnext"> -->
<!--    <li class="right"  style="margin-right: 10px">Indice -->
<!--      <a href="../genindex.html" title="Indice generale" -->
<!--                accesskey="I">indice</a></li> -->

        <li class="right">Prev:
        <a href="tutorials.html" title="previous chapter">Mailing list</a></li>
        <li class="right">Next:
        <a href="sqledit.html" title="next chapter">Sqledit - the standalone program to browse and edit data</a></li>
<!-- </div> -->


      </ul>

    </div>

    
  <div class="sphinxsidebar">
     <div class="sphinxsidebarwrapper">


	    <div class="topnav">
    <h3>Table of contents</h3>
		    <ul>
<li><a class="reference external" href="#">Sqledit Tutorial</a><ul>
<li><a class="reference external" href="#intended-audience">Intended audience</a></li>
<li><a class="reference external" href="#installation">Installation</a><ul>
<li><a class="reference external" href="#installing-under-debian-ubuntu">Installing under Debian/Ubuntu</a></li>
<li><a class="reference external" href="#installing-under-windows">Installing under Windows</a></li>
<li><a class="reference external" href="#installig-under-macos">Installig under MacOS</a></li>
<li><a class="reference external" href="#dependencies">Dependencies</a></li>
</ul>
</li>
<li><a class="reference external" href="#sqledit-sqlkit">sqledit/sqlkit</a></li>
<li><a class="reference external" href="#sqledit-table-listing">Sqledit table listing</a><ul>
<li><a class="reference external" href="#the-table-listing">The table listing</a></li>
</ul>
</li>
<li><a class="reference external" href="#tables">Tables</a><ul>
<li><a class="reference external" href="#filtering">filtering</a></li>
<li><a class="reference external" href="#totals">totals</a></li>
<li><a class="reference external" href="#completions">completions</a></li>
<li><a class="reference external" href="#changing-view">changing view</a></li>
</ul>
</li>
<li><a class="reference external" href="#mask">Mask</a><ul>
<li><a class="reference external" href="#completion">completion</a></li>
<li><a class="reference external" href="#filters">filters</a></li>
<li><a class="reference external" href="#layout">layout</a></li>
</ul>
</li>
<li><a class="reference external" href="#the-demo">The Demo</a></li>
<li><a class="reference external" href="#feedback">Feedback</a></li>
</ul>
</li>
</ul>

		<div class="clearboth"></div>
	    </div>



    <h3>Questions?</h3>

    <p>Subscribe to out mailing list <a href="http://groups.google.com/group/sqlkit">
       Google group</a>:</p>

    <form action="http://groups.google.com/group/sqlkit/boxsubscribe" style="padding-left: 1em">
      <input type="text" name="email" value="your@email"/>
      <input type="submit" name="sub" value="Subscribe" />
    </form>
    <div id="searchbox" style="display: none">

    <h3>Quick search</h3>
	<form class="search" action="../search.html" method="get">
	  <input type="text" name="q" size="18" />
	  <input type="submit" value="Search" />
	  <input type="hidden" name="check_keywords" value="yes" />

	  <input type="hidden" name="area" value="default" />
	</form>
	<p class="searchtip" style="font-size: 90%">
        Enter search terms or a module, class or function name.
	</p>
    <h3>License</h3>
	<img src="../_static/gplv3.png" alt="logo GPLv3">

    </div>
    <script type="text/javascript">$('#searchbox').show(0);</script>

     </div>
  </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">

            <div class="body">
                
<div class="section" id="sqledit-tutorial">
<span id="tutorial"></span><h1>Sqledit Tutorial<a class="headerlink" href="#sqledit-tutorial" title="Permalink to this headline">¶</a></h1>
<div class="section" id="intended-audience">
<h2>Intended audience<a class="headerlink" href="#intended-audience" title="Permalink to this headline">¶</a></h2>
<p>This is meant as a tutorial for the <strong>sqledit</strong> command that is part of
sqlkit. It&#8217;s intended audience is anybody who is interested in editing data
in a database (as opposed to editing the <em>structure</em> of the database).</p>
<p>No programming skill is required, but if you are supposed to install it
yourself, you may need to understand at least a little bit of your operating
system (but that may be as simple as a double click if you use bundles).</p>
</div>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<p>According to you operating system and setup you may find the very easy way
for you. You may not event need to know which are the dependancies that are
explained below for the curious ones.</p>
<div class="section" id="installing-under-debian-ubuntu">
<span id="ubuntu-install"></span><h3>Installing under Debian/Ubuntu<a class="headerlink" href="#installing-under-debian-ubuntu" title="Permalink to this headline">¶</a></h3>
<p>On Ubuntu lucid (10.04) and probably also others &gt;= 9.10
you can prepare dependencies:</p>
<div class="highlight-python"><pre>sudo add-apt-repository ppa:toobaz/sqlkit</pre>
</div>
<p>On Debian:</p>
<div class="highlight-python"><pre>echo deb http://ppa.launchpad.net/toobaz/sqlkit/ubuntu lucid main | sudo tee /etc/apt/sources.list.d/sqlkit.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 39012CF8</pre>
</div>
<p>and install it as follows (this installs python drivers for PostgreSQL and
Mysql as well):</p>
<div class="highlight-python"><pre>sudo apt-get update
sudo apt-get install python-sqlkit python-psycopg2 python-mysqldb</pre>
</div>
<p>I&#8217;ll try to keep this updated as the official package</p>
</div>
<div class="section" id="installing-under-windows">
<span id="windows-install"></span><h3>Installing under Windows<a class="headerlink" href="#installing-under-windows" title="Permalink to this headline">¶</a></h3>
<p>The easiest way is to use <a class="reference external" href="http://code.google.com/p/windows-package-manager">Windows Package Manager</a>  that handles
dependencies (that can turn usefull for other software too). The
installation process becomes as easy as:</p>
<blockquote>
<ul class="simple">
<li>download and install <a class="reference external" href="http://code.google.com/p/windows-package-manager">Windows Package Manager</a></li>
<li>start it, select sqlkit and install (you may want to select/inistall
also the database drivers for PostgreSql and MySQL)</li>
</ul>
</blockquote>
<p>If you want to go the &#8220;hard&#8221; way you can install all peaces separately but
still use the Pygtk all-in-one installer (thanks to Dieter Verfaillie):</p>
<blockquote>
<ul>
<li><p class="first">download and install <a class="reference external" href="http://www.python.org/download/">Python</a></p>
</li>
<li><p class="first">download and install <a class="reference external" href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/">Pygtk-all-in-one</a></p>
</li>
<li><p class="first">download <a class="reference external" href="http://sqlkit.argolinux.org/download/sqlkit-0.9.5.zip">sqlkit-0.9.5.zip</a> unzip and install by doing:</p>
<div class="highlight-python"><pre>python setup.py install</pre>
</div>
<p>Note that python may not be in the PATH so you may need to write it
explicetly.</p>
</li>
</ul>
</blockquote>
</div>
<div class="section" id="installig-under-macos">
<h3>Installig under MacOS<a class="headerlink" href="#installig-under-macos" title="Permalink to this headline">¶</a></h3>
<p>You can install and run Sqlkit under MacOS also. You can use the all-in-one
<a class="reference external" href="http://afb.users.sourceforge.net/zero-install/PyGTK.pkg">boundle</a> (thanks to Anders F. Björklund) or install from MacPorts.</p>
</div>
<div class="section" id="dependencies">
<h3>Dependencies<a class="headerlink" href="#dependencies" title="Permalink to this headline">¶</a></h3>
<p>Sqlkit depends on the following packages:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Python:</th><td class="field-body"><p class="first">sqledit it&#8217;s a Python script. It should work with python 2.4 and
following. But if you used 2.4 be sure to add the driver for sqlite
that was added to the main distribution only starting from 2.5.</p>
</td>
</tr>
<tr class="field"><th class="field-name">PyGTK:</th><td class="field-body"><p class="first">any Linux desktop distribution has it already installed, in case
it does not have it, it should be trivial to do. In Debian-derived
systems (e.g.: Ubuntu), you simply run:</p>
<div class="highlight-python"><pre>apt-get install python-gtk2</pre>
</div>
<p>In a Windows system it used to be a difficult task but now it&#8217;s
very simple. Please follow the instructions on the <a class="reference external" href="http://www.pygtk.org">pygtk site</a></p>
</td>
</tr>
<tr class="field"><th class="field-name">sqlalchemy:</th><td class="field-body"><p class="first">this is the core of the sql staff. It&#8217;s a layer that builds SQL
statements and invokes the backend drivers. It takes care of
inspecting the database and so on. You need at least release 0.5 but
0.5.4 would be much better.</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">python-dateutil:</th></tr>
<tr><td>&nbsp;</td><td class="field-body"><p class="first">needed for computation on dates, used in filters (e.g: date
&gt;= &#8216;m-1&#8217;, means date &gt;= starting of last month), see <a class="reference external" href="../sqlkit/filters.html#date-filters"><em>Date filters</em></a>.</p>
</td>
</tr>
<tr class="field"><th class="field-name">babel:</th><td class="field-body"><p class="first">needed for localization of numbers and dates</p>
</td>
</tr>
<tr class="field"><th class="field-name">setuptools:</th><td class="field-body"><p class="first">needed for the installation and to check version of sqlalchemy</p>
</td>
</tr>
<tr class="field"><th class="field-name">drivers:</th><td class="field-body"><p class="first last">don&#8217;t forget to add the driver for the backend of your choice, the
only driver included is for <tt class="docutils literal"><span class="pre">sqlite</span></tt>, that is the database of
the demo and is included in the python distribution since python
2.5.</p>
</td>
</tr>
</tbody>
</table>
<p>If you have setuptools installed in your system, you can install whatever
you need simply with:</p>
<div class="highlight-python"><pre>easy_install sqlkit</pre>
</div>
<p>and probably you&#8217;d have better results using <tt class="docutils literal"><span class="pre">pip</span></tt>:</p>
<div class="highlight-python"><pre>easy_install pip
pip install sqlkit</pre>
</div>
<p>remember to install the backend driver, these are the examples for postgresql
and mysql:</p>
<div class="highlight-python"><pre>pip install psycopg2
pip install MySQL-python</pre>
</div>
</div>
</div>
<div class="section" id="sqledit-sqlkit">
<h2>sqledit/sqlkit<a class="headerlink" href="#sqledit-sqlkit" title="Permalink to this headline">¶</a></h2>
<img align="right" alt="../_images/sqledit.png" class="align-right" src="../_images/sqledit.png" />
<p>Now you should have a working setup. The command we are going to familiarize
with is <tt class="docutils literal"><span class="pre">sqledit</span></tt> that is based on a library named <tt class="docutils literal"><span class="pre">sqlkit</span></tt>. If you are
a programmer and are interested in the sqlkit package you can find extensive
documentation in the <a class="reference external" href="http://sqlkit.argolinux.org">web site</a></p>
<p>Programming with sqlkit is a pretty simple experience that allows you to use
many more features than available with <tt class="docutils literal"><span class="pre">sqledit</span></tt>, nevertheless you can do
a lot of simple tasks by using <tt class="docutils literal"><span class="pre">sqledit</span></tt> alone.</p>
<p>
<span class="versionmodified">New in version 9.1.</span></p>
<p>Sqledit has a flexible <a class="reference external" href="sqledit.html#sqledit"><em>configuration system</em></a> that allows you
to add many code snippets w/o writing a true program, so that even if you
decide to start with sqledit due to it&#8217;s simplicity you can add more
configurations as far as you needs them. I personally started using that as
my preferred way.</p>
<p>Sqledit can be used:</p>
<ul class="simple">
<li>from command line, possibly adding arguments and options</li>
<li>from a menu entry interactively writing the URL of the database you want to edit.</li>
</ul>
<p>If you start it with no arguments you are presented a dialog with an entry
and 3 buttons:</p>
<ul>
<li><p class="first">you can write the url of a database of yours in the entry, e.g.:</p>
<div class="highlight-python"><pre>postgres://localhost/dbname     # sqlalchemy 5
postgresql://localhost/dbname   # sqlalchemy 6+
sqlite:///db.sqlite
mysql://name:pass@host/dbname</pre>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">the URL for a sqlite database has 3 &#8216;/&#8217;if the database is in your
current directory, 4 if you need to pass a file starting with &#8216;/&#8217;.</p>
</div>
</li>
<li><p class="first">start the demo tour</p>
</li>
</ul>
</div>
<div class="section" id="sqledit-table-listing">
<h2>Sqledit table listing<a class="headerlink" href="#sqledit-table-listing" title="Permalink to this headline">¶</a></h2>
<p>The demo tour is meant for developers, so that it shows source code as well,
but it&#8217;s also suitable for our introduction and is a living database, so we
will use that in this tutorial.</p>
<p>The demo presents you some examples on the left. Let&#8217;s start with...  the
last one! We start with the last one because it&#8217;s the window you will
see when you start sqledit with an address of a real database (the demo one
in this case).</p>
<div class="section" id="the-table-listing">
<h3>The table listing<a class="headerlink" href="#the-table-listing" title="Permalink to this headline">¶</a></h3>
<p>The table listing of the database is shown above: clicking on a table
name pops a menu that lets you choose between:</p>
<ul class="simple">
<li>table view: representation of the table in a spreadsheet fashion</li>
<li>mask view:  a form with each field is displayed</li>
<li>table reflection: sqledit reads the definition for that table</li>
</ul>
</div>
</div>
<div class="section" id="tables">
<h2>Tables<a class="headerlink" href="#tables" title="Permalink to this headline">¶</a></h2>
<p>Let&#8217;s choose a table view:</p>
<img alt="../_images/table.png" src="../_images/table.png" />
<p>each field of the table is represented in a column, each type has different
representations:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">text:</th><td class="field-body"><p class="first">a simple cell will render the text</p>
</td>
</tr>
<tr class="field"><th class="field-name">numbers:</th><td class="field-body"><p class="first">each number is adjusted to the right</p>
</td>
</tr>
<tr class="field"><th class="field-name">dates:</th><td class="field-body"><p class="first">dates are represented in you preferred locale that is argued from
LANG variable or from locale module information</p>
</td>
</tr>
<tr class="field"><th class="field-name">boolean:</th><td class="field-body"><p class="first">a checkbox is used. It the NULL value is accepted, clicking the
checkbox will loop between True, False and undefined</p>
</td>
</tr>
<tr class="field"><th class="field-name">intervals:</th><td class="field-body"><p class="first">intervals are really poorly rendered at the moment...</p>
</td>
</tr>
<tr class="field"><th class="field-name">foreign keys:</th><td class="field-body"><p class="first">foreign keys are represented via the value they point to in
the remote table. At present only simple (not compound keys) are
allowed. To help you detect that that&#8217;s a ForeignKey it&#8217;s drawn in blue.
Just to be pedantic: you won&#8217;t see the real value (that may happen to be
an id, normally not very interesting), you will rather see the value it
points to...</p>
<p>As you can realize there is not real <em>value</em> where is points. An id
points to a record of a table (e.g.: director id 1 may point to the record
in director table where <tt class="docutils literal"><span class="pre">last_name</span></tt> is <em>Fellini</em>), but <em>Fellini</em> is not
the value of the id: it&#8217;s rather a representation of the record that in
many circumstances may be enough (and in many other is not).</p>
<p>So I introduced a rule: I represent it with the value of the first
character field of the line. Clearly this rules is doomed to fail in some
cases and you can correct it forcing a representation of the line we
will call a format field. You can go in the main window of sqledit,
select databases and &#8216;edit sqlkit field&#8217; and you will be presented a
mask to edit the value you prefer.</p>
<img alt="../_images/sqledit_config.png" class="last" src="../_images/sqledit_config.png" />
</td>
</tr>
</tbody>
</table>
<div class="section" id="filtering">
<h3>filtering<a class="headerlink" href="#filtering" title="Permalink to this headline">¶</a></h3>
<p>you may have a lot of data and what sqlkit will help you at is to
<a class="reference external" href="../sqlkit/filters.html#filters"><em>filter</em></a> in a simple way. Each column has a clickable header
that pops a menu entry. The first menu entry pops a filter widget:</p>
<img alt="../_images/filter-panel.png" src="../_images/filter-panel.png" />
<p>in the image we have clicked on three column&#8217;s header: the filter on each
column is composed of 4 parts: the label with the name, the operator for the
filter, the checkbox to disable the filter and the entry for a value.</p>
<p>Some operators have pretty intuitive operators (&#8216;&gt;&#8217; as bigger than or later
that for dates) text have also regular expression (normally much more
useful so that it&#8217;s the default) or <tt class="docutils literal"><span class="pre">like</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">you can select more filter for column, click on the label in the filter
panel. You can for example say that you want all the films produced
between 2000 and 2005, that means having 2 filter on the field year.</p>
</div>
<p>Pressing <tt class="docutils literal"><span class="pre">Enter</span></tt> on a field or the reload button will run the query and
present the selected records in the TableView.</p>
<p>Dates are special in that you often have to filter with dates relative to the
moment you do the query (today, this month,...) so that i added some
shortcuts to accomplish this task (e.g.: &#8216;m&#8217; means the beginning of the
month). You can read more on this feature in <a class="reference external" href="../sqlkit/filters.html#date-filters"><em>Date filters</em></a>.</p>
</div>
<div class="section" id="totals">
<h3>totals<a class="headerlink" href="#totals" title="Permalink to this headline">¶</a></h3>
<img alt="../_images/totals.png" src="../_images/totals.png" />
<p>One more feature of sqlkit that comes very handy is the ability to make
totals in the fashion of a spreadsheet. This only works on numbers of course,
and you can trigger this feature from the column menu. Since our test
database does not have numbers other than for <em>year</em> of production, in the
example I joked and computed the total on the column of the year of production. In real
cases you will do sum with more interesting data...</p>
<p>Subtotals are a very useful feature of any total, so you can ask sqlkit to
create subtotals when some value change (e.g: date, month, year,
director...).</p>
</div>
<div class="section" id="completions">
<h3>completions<a class="headerlink" href="#completions" title="Permalink to this headline">¶</a></h3>
<p>When you enter data in a text entry or in a foreign key, you may
find yourself typing something that is already in the database. In this cases
you can have sqledit to search that text for you. Really that&#8217;s a must for
Foreign Keys where you can only pick the data among those proposed.</p>
<p>Since the possible values may be a lot and we don&#8217;t want to wast time
waiting to retrieve data that would only confuse us, we will require sqledit
to show possible values pressing enter in the entry. In this case the text
that we may have already entered will be used to filter the possible values
and to be more precise:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Shift Enter:</th><td class="field-body">will trigger a search using the text at the beginning of the
field</td>
</tr>
<tr class="field"><th class="field-name">Control Enter:</th><td class="field-body">will trigger a search using a <em>regexp</em>. If you don&#8217;t know what
a regexp is, consider that as a minimum it will do a search of the string
in any position, but can do much more and really also depends on the
database backend.</td>
</tr>
<tr class="field"><th class="field-name">Control Shift:</th><td class="field-body">will disregard what you have already written and do a search
on all possible values, thus emulating an <tt class="docutils literal"><span class="pre">enum</span></tt> field.</td>
</tr>
</tbody>
</table>
<p>You can find complete information on how to configure <a class="reference external" href="../sqlkit/completion.html#completion"><em>Completion</em></a> in
the docs.</p>
</div>
<div class="section" id="changing-view">
<h3>changing view<a class="headerlink" href="#changing-view" title="Permalink to this headline">¶</a></h3>
<p>When in a table view, you may want to jump on a <em>mask view</em> or even keep the
two open simultaneously. That can be simply done by clicking with right
button in a row: the menu that appears lets you edit the row with a mask. If
that&#8217;s a ForeignKey column you can even edit the value the foreign key points
to.</p>
</div>
</div>
<div class="section" id="mask">
<h2>Mask<a class="headerlink" href="#mask" title="Permalink to this headline">¶</a></h2>
<img align="right" alt="../_images/mask.png" class="align-right" src="../_images/mask.png" />
<p>The other view we can use is the <em>mask view</em>. The records are presented by
default in a form with the labels on the right and the forms on the left.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This is just a default and the only one possible at the moment, but
programmatically you can choose any fancy layout you want, but I won&#8217;t
digress as I want to limit the information for non developers in his
context.</p>
</div>
<div class="section" id="completion">
<h3>completion<a class="headerlink" href="#completion" title="Permalink to this headline">¶</a></h3>
<p>In this mask you can see that foreign keys use a combo with a completion
element popdown. Same shortcut as for the table one are used to complete. A
double click on the arrow let you use it as an enum field.</p>
</div>
<div class="section" id="filters">
<h3>filters<a class="headerlink" href="#filters" title="Permalink to this headline">¶</a></h3>
<p>Filters can be activated clicking on the label. the filter panel will be
presented as usual.</p>
<p>The difference is that when the query is issued the result is presented in a
tab of the filter panel and you browse the results clicking in the output
tab or clicking the forward and backward arrows of the mask.</p>
</div>
<div class="section" id="layout">
<h3>layout<a class="headerlink" href="#layout" title="Permalink to this headline">¶</a></h3>
<p>If the table has many fields, you may get a layout that is not very
usable. This is a limit of the interfaces at the moment, not of the sqlkit
package that can handle any fancy layout as you can see looking at the
examples of the demo.</p>
<p>The library also allows you to edit related tables (i.e.: director and
movies) with no effort, in order to do this you need at least a minimum of
programming, namely:</p>
<blockquote>
<ul class="simple">
<li>defining the model (as per SqlAlchemy)</li>
<li>defining the layout  (this is very easy and demo has plenty of examples)</li>
</ul>
</blockquote>
<p>These 2 definitions can be written in the configuration for the a nick of
sqledit, please read <a class="reference external" href="sqledit.html#sqledit"><em>sqledit manual</em></a> for details on nick
configuration.</p>
</div>
</div>
<div class="section" id="the-demo">
<h2>The Demo<a class="headerlink" href="#the-demo" title="Permalink to this headline">¶</a></h2>
<p>The demo is a pretty simple way to be introduced to more advanced features
that you would only have with a little of programming. I hope it will
encourage you to do it and possibly to approach Python.</p>
<p>The very important thing to understand when reading the snippets of the demo
is that each time you write the table as a string (e.g: table=&#8217;movies&#8217;) you
will trigger an inspection of the database, but no assumption is made on the
relationships between tables. When you pass a mapper or a class
(e.g. class_=model.Movie) you are passing possibly more information.</p>
<p>The model in fact (you can go and see in <tt class="docutils literal"><span class="pre">demo/sql/model/movies.py</span></tt>)
has lines as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Director</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;director&#39;</span>
    <span class="nb">id</span>             <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">last_name</span>   <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
    <span class="n">first_name</span>  <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">))</span>
    <span class="n">nation</span>      <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">6</span><span class="p">))</span>

    <span class="n">movies</span>      <span class="o">=</span> <span class="n">relation</span><span class="p">(</span><span class="s">&#39;movie&#39;</span><span class="p">,</span> <span class="n">backref</span><span class="o">=</span><span class="s">&#39;director&#39;</span><span class="p">,</span> <span class="n">cascade</span><span class="o">=</span><span class="s">&#39;all, delete-orphan&#39;</span><span class="p">,)</span>
</pre></div>
</div>
<p>where the last line instructs sqlalchemy of the relation existent between
the tables, and more: it adds an attribute on the class <tt class="docutils literal"><span class="pre">Director</span></tt> that
holds all the movies produces by that director (and vice verse thanks to the
argument <tt class="docutils literal"><span class="pre">backref</span></tt>).</p>
<p>Adding these information makes it possible to used the layout in a mask to
produce a mask with director and all the movies, if you are interested in
this part... let me know and I will add more info. For the moment I suggest
you to go and read more about <a class="reference external" href="../sqlkit/relationship.html#relationships"><em>Relationships</em></a></p>
</div>
<div class="section" id="feedback">
<h2>Feedback<a class="headerlink" href="#feedback" title="Permalink to this headline">¶</a></h2>
<p>I hope you found this tutorial useful.</p>
<p>If you like this piece of software, have suggestion on how to improve it or
improve the tutorial I&#8217;d be <a class="reference external" href="mailto:sandro&#37;&#52;&#48;e-den&#46;it">happy to know</a></p>
<p>cheers
sandro
*:-)</p>
</div>
</div>


            </div>
        </div>
     </div>
   </div>

        
</div> <!-- wrap -->

            <div class="bottomnav footer">
                <div class="doc_copyright">
                Alessandro Dentella -- Copyright 2006-2007-2008-2009-2010
		  Sqlkit release 0.9.5
<!--                 % if hasdoc('copyright'): -->
<!--                     &copy; <a href="../copyright.html">Copyright</a> 2008, Sandro Dentella. -->
<!--                 % else: -->
<!--                     &copy; Copyright 2008, Sandro Dentella. -->
<!--                 % endif -->
                    creato usando  <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
                </div>
            </div>
        












<br style="clear: left" />

    </body>
</html>