function up() { $sql = "create table board (id serial primary key, name text unique)"; SqlAlterSchema($sql); SqlInsertRow("insert into board (name) values (:name)", array('name' => 'default')); $sql = "create table board_cell (\n\t\t\t\t\tid serial primary key, \n\t\t\t\t\tboard_id int4 references board,\n\t\t\t\t\trow_num int2 not null,\n\t\t\t\t\tcol_num int2 not null,\n\t\t\t\t\tletter varchar(1) not null\n\t\t\t\t)"; SqlAlterSchema($sql); }
public static function generateWordLetters($thisWord) { $letters = array(); for ($i = 0; $i < $thisWord['len']; $i++) { if (isset($letters[$thisWord['word'][$i]])) { $letters[$thisWord['word'][$i]]++; } else { $letters[$thisWord['word'][$i]] = 1; } } foreach ($letters as $letter => $count) { $sql = "insert into word_letter (word_id, letter, count) values (:wordId, :letter, :count)"; SqlInsertRow($sql, array('wordId' => $thisWord['id'], 'letter' => $letter, 'count' => $count)); } }
function pageImportWords() { $handle = fopen("/path/to/scrabble_dictionary.txt", "r"); $words = array(); if ($handle) { while (!feof($handle)) { $buffer = trim(fgets($handle, 4096)); // echo $buffer; $sql = "insert into word (word, len) values ('{$buffer}', length('{$buffer}'))"; echo $sql . '<br>'; SqlInsertRow($sql, array()); $words[] = $buffer; } fclose($handle); } }
public function getWords() { $words = array(); for ($row = 1; $row <= self::size; $row++) { $word = ''; for ($col = 1; $col <= self::size; $col++) { $letter = $this->cells[$row][$col]->getLetter(); if ($letter) { $word .= $letter; } else { if ($word) { $words[$word] = 1; $word = ''; } } } if ($word) { $words[$word] = 1; $word = ''; } } for ($col = 1; $col <= self::size; $col++) { $word = ''; for ($row = 1; $row <= self::size; $row++) { $letter = $this->cells[$row][$col]->getLetter(); if ($letter) { $word .= $letter; } else { if ($word) { $words[$word] = 1; $word = ''; } } } if ($word) { $words[$word] = 1; $word = ''; } } // SqlEchoOn(); foreach ($words as $thisWord => $thing) { SqlBeginTransaction(); $word = strtoupper($thisWord); $len = strlen($word); if ($len < 2) { continue; } $id = SqlFetchCell("select id from word where word = :word", array('word' => $word)); if (!$id) { echo "inserting word: {$word}<br>"; SqlInsertRow("insert into word (word, len) values (:wordwrap, :len)", array('word' => $word, 'len' => $len)); Learn::generateWordLetters($word); } SqlCommitTransaction(); } }