Thursday, July 29th 2010, 1:22pm UTC+2

You are not logged in.

  • Login
  • Register

undefined

Super Moderator

Posts: 4,248

Location: Germany

1

Friday, November 11th 2005, 7:49pm

SQLite Clipboard

Ein einfaches Clipboard in SQLite

PHP Source code

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
<?php
/**
 * @callgraph
 * @class      SQLiteClipboard
 * @short      Simple Read/Write Clipboard Class
 * @version    0.0.1
 * @since      Fr Sep  9 08:14:45 CEST 2005
 * @code
   $sqlite = new SQLiteClipboard( MY_TEMP_DIR );
   if ( $sqlite->INSERTING = time() )
      var_dump( $sqlite->INSERTING );
   else
      echo "Nothing done!";
 * @endcode
 */

final class SQLiteClipboard
{
   private $SQL;
   private $DB "Clipboard.sqlite";
   private $TB "Clipboard";
   private $ID "ID";
   private $PA "PARAM";
   private $VA "VAL";

   function __construct$path )
   {
      $this->DB chop$path "/" $this->DB );
      $this->sql_init();
   }

   private function sql_init()
   {
      $this->SQL = new SQLiteDatabase$this->DB0660 );
      if ( ! file_exists$this->DB ) )
         die( "Permission Denied!" );

      $q $this->SQL->query("PRAGMA table_info(" $this->TB ")");
      if ( $q->numRows() == ) {
         $this->SQL->query"CREATE TABLE " $this->TB " ( " $this->ID " INTEGER PRIMARY KEY, " $this->PA " CHAR(255), " $this->VA " CHAR(255) );" );
      }
   }

   private function sql_check$p )
   {
      $o null;
      $q $this->SQL->query"SELECT " $this->ID " FROM " $this->TB " WHERE ( " $this->PA "='$p' ) ORDER BY " $this->ID " LIMIT 1" );
      while( $q->valid() ) {
         $r $q->current();
         return $r[$this->ID];
         $q->next();
      }
      return false;
   }

   public function __get$p )
   {
      $q $this->SQL->query"SELECT " $this->VA " FROM " $this->TB " WHERE ( " $this->PA "='$p' ) ORDER BY " $this->ID );
      while( $q->valid() ) {
            $r $q->current();
            $o $r[$this->VA];
            $q->next();
      }
      return $o;
   }

   public function __set$p$v )
   {
      if ( $this->sql_check$p ) && ! empty( $v ) )
         return $this->SQL->query"UPDATE " $this->TB " SET " $this->VA "='$v' WHERE ( " $this->PA "='$p' );" );
      elseif  ( ! $this->sql_check$p ) && ! empty( $v ) )
         return $this->SQL->query"INSERT INTO " $this->TB " ( " $this->PA ", " $this->VA " ) VALUES ('$p', '$v' );" );
      elseif  ( $this->sql_check$p ) && empty( $v ) )
         return $this->SQL->query"DELETE FROM " $this->TB " WHERE ( " $this->PA "='$p' );" );
      else
         return false;
   }

} // end Class

?>
Undefined Behavior (undefiniertes Verhalten) bedeutet meistens etwas ungültiges.
PHP Katepart - Speichenrechner - .htpasswd - RPM XDG Tool - Kcmnvview - QTidy
  • Go to the top of the page