~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/datadic_xt.cc

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005 PrimeBase Technologies GmbH
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
2
2
 *
3
3
 * PrimeBase XT
4
4
 *
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * 2006-05-16   Paul McCullagh
20
20
 *
396
396
struct charset_info_st;
397
397
 
398
398
class XTTokenizer {
399
 
        MX_CONST_CHARSET_INFO   *tkn_charset;
 
399
        MX_CHARSET_INFO                 *tkn_charset;
400
400
        char                                    *tkn_cstring;
401
401
        char                                    *tkn_curr_pos;
402
402
        XTToken                                 *tkn_current;
1324
1324
class XTCreateTable : public XTParseTable {
1325
1325
        public:
1326
1326
        bool                                    ct_convert;
1327
 
        MX_CONST_CHARSET_INFO   *ct_charset;
 
1327
        MX_CHARSET_INFO                 *ct_charset;
1328
1328
        XTPathStrPtr                    ct_tab_path;
1329
1329
        u_int                                   ct_contraint_no;
1330
1330
        XTDDTable                               *ct_curr_table;
2049
2049
        if (!(ot = xt_db_open_table_using_tab(tr_fkey->co_table->dt_table, self)))
2050
2050
                xt_throw(self);
2051
2051
 
 
2052
        /* {FREE-ROWS-BAD} */
 
2053
        /*
 
2054
        row_count = ((xtInt8) ot->ot_table->tab_row_eof_id) - 1;
 
2055
        row_count -= (xtInt8) ot->ot_table->tab_row_fnum;
 
2056
        */
2052
2057
        /* Check if there are any rows in the referencing table: */
2053
2058
        if (!xt_tab_seq_init(ot))
2054
2059
                goto failed;
2291
2296
{
2292
2297
        XTDDTable *ref_tab;
2293
2298
 
2294
 
        xt_recurrwlock_xlock(self, &co_table->dt_ref_lock);
2295
 
        pushr_(xt_recurrwlock_unxlock, &co_table->dt_ref_lock);
 
2299
        xt_xlock_rwlock(self, &co_table->dt_ref_lock);
 
2300
        pushr_(xt_unlock_rwlock, &co_table->dt_ref_lock);
2296
2301
 
2297
2302
        if ((ref_tab = fk_ref_table)) {                 
2298
2303
                fk_ref_table = NULL;
2302
2307
 
2303
2308
        fk_ref_index = UINT_MAX;
2304
2309
 
2305
 
        freer_(); // xt_recurrwlock_unxlock(&co_table->dt_ref_lock);
 
2310
        freer_(); // xt_unlock_rwlock(&co_table->dt_ref_lock);
2306
2311
}
2307
2312
 
2308
2313
/*
2321
2326
        /* This lock ensures that the foreign key references are not
2322
2327
         * changed.
2323
2328
         */
2324
 
        xt_recurrwlock_slock_ns(&co_table->dt_ref_lock);
 
2329
        xt_slock_rwlock_ns(&co_table->dt_ref_lock);
2325
2330
 
2326
2331
        if (!(loc_ind = getIndexPtr()))
2327
2332
                goto failed;
2406
2411
        xt_db_return_table_to_pool_ns(ot);
2407
2412
 
2408
2413
        failed:
2409
 
        xt_recurrwlock_unslock_ns(&co_table->dt_ref_lock);
 
2414
        xt_unlock_rwlock_ns(&co_table->dt_ref_lock);
2410
2415
        return false;
2411
2416
 
2412
2417
        success:
2413
 
        xt_recurrwlock_unslock_ns(&co_table->dt_ref_lock);
 
2418
        xt_unlock_rwlock_ns(&co_table->dt_ref_lock);
2414
2419
        return true;
2415
2420
}
2416
2421
 
2438
2443
 
2439
2444
void XTDDTable::init(XTThreadPtr self)
2440
2445
{
2441
 
        xt_recurrwlock_init_with_autoname(self, &dt_ref_lock);
 
2446
        xt_init_rwlock_with_autoname(self, &dt_ref_lock);
2442
2447
        dt_trefs = NULL;
2443
2448
}
2444
2449
 
2475
2480
                ptr->release(self);
2476
2481
        }
2477
2482
 
2478
 
        xt_recurrwlock_free(&dt_ref_lock);
 
2483
        xt_free_rwlock(&dt_ref_lock);
2479
2484
}
2480
2485
 
2481
2486
XTDDColumn *XTDDTable::findColumn(char *name)
2551
2556
                        throw_();
2552
2557
        }
2553
2558
 
2554
 
        xt_recurrwlock_xlock(self, &dt_ref_lock);
2555
 
        pushr_(xt_recurrwlock_unxlock, &dt_ref_lock);
 
2559
        xt_xlock_rwlock(self, &dt_ref_lock);
 
2560
        pushr_(xt_unlock_rwlock, &dt_ref_lock);
2556
2561
 
2557
2562
        if (!(tr = new XTDDTableRef()))
2558
2563
                xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
2567
2572
         */
2568
2573
        xt_heap_reference(self, fk->co_table->dt_table);
2569
2574
 
2570
 
        freer_(); // xt_recurrwlock_unxlock(&dt_ref_lock);
 
2575
        freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2571
2576
}
2572
2577
 
2573
2578
/*
2577
2582
{
2578
2583
        XTDDTableRef    *tr, *prev_tr = NULL;
2579
2584
 
2580
 
        xt_recurrwlock_xlock(self, &dt_ref_lock);
2581
 
        pushr_(xt_recurrwlock_unxlock, &dt_ref_lock);
 
2585
        xt_xlock_rwlock(self, &dt_ref_lock);
 
2586
        pushr_(xt_unlock_rwlock, &dt_ref_lock);
2582
2587
 
2583
2588
        tr = dt_trefs;
2584
2589
        while (tr) {
2592
2597
                prev_tr = tr;
2593
2598
                tr = tr->tr_next;
2594
2599
        }
2595
 
        freer_(); // xt_recurrwlock_unxlock(&dt_ref_lock);
 
2600
        freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2596
2601
        if (tr)
2597
2602
                tr->release(self);
2598
2603
}
2619
2624
 
2620
2625
                        dt->attachReference(self, fk);
2621
2626
 
2622
 
                        xt_recurrwlock_xlock(self, &dt_ref_lock);
2623
 
                        pushr_(xt_recurrwlock_unxlock, &dt_ref_lock);
 
2627
                        xt_xlock_rwlock(self, &dt_ref_lock);
 
2628
                        pushr_(xt_unlock_rwlock, &dt_ref_lock);
2624
2629
                        /* Referenced the table, not the index!
2625
2630
                         * We do this because we know that if the table is referenced, the
2626
2631
                         * index will remain valid!
2630
2635
                         */
2631
2636
                        xt_heap_reference(self, dt->dt_table);
2632
2637
                        fk->fk_ref_table = dt;
2633
 
                        freer_(); // xt_recurrwlock_unxlock(&dt_ref_lock);
 
2638
                        freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2634
2639
                }
2635
2640
        }
2636
2641
}
2694
2699
        XTDDTableRef    *tr;
2695
2700
        XTDDTable               *tab;
2696
2701
 
2697
 
        xt_recurrwlock_xlock(self, &dt_ref_lock);
2698
 
        pushr_(xt_recurrwlock_unxlock, &dt_ref_lock);
 
2702
        xt_xlock_rwlock(self, &dt_ref_lock);
 
2703
        pushr_(xt_unlock_rwlock, &dt_ref_lock);
2699
2704
 
2700
2705
        for (u_int i=0; i<dt_fkeys.size(); i++) {
2701
2706
                fk = dt_fkeys.itemAt(i);
2706
2711
                                /* To avoid deadlock we do not hold more than
2707
2712
                                 * one lock at a time!
2708
2713
                                 */
2709
 
                                freer_(); // xt_recurrwlock_unxlock(&dt_ref_lock);
 
2714
                                freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2710
2715
        
2711
2716
                                tab->removeReference(self, fk);
2712
2717
                                xt_heap_release(self, tab->dt_table); /* We referenced the table, not the index! */
2713
2718
        
2714
 
                                xt_recurrwlock_xlock(self, &dt_ref_lock);
2715
 
                                pushr_(xt_recurrwlock_unxlock, &dt_ref_lock);
 
2719
                                xt_xlock_rwlock(self, &dt_ref_lock);
 
2720
                                pushr_(xt_unlock_rwlock, &dt_ref_lock);
2716
2721
                        }
2717
2722
                }
2718
2723
        }
2720
2725
        while (dt_trefs) {
2721
2726
                tr = dt_trefs;
2722
2727
                dt_trefs = tr->tr_next;
2723
 
                freer_(); // xt_recurrwlock_unxlock(&dt_ref_lock);
 
2728
                freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2724
2729
                tr->release(self);
2725
 
                xt_recurrwlock_xlock(self, &dt_ref_lock);
2726
 
                pushr_(xt_recurrwlock_unxlock, &dt_ref_lock);
 
2730
                xt_xlock_rwlock(self, &dt_ref_lock);
 
2731
                pushr_(xt_unlock_rwlock, &dt_ref_lock);
2727
2732
        }
2728
2733
 
2729
 
        freer_(); // xt_recurrwlock_unxlock(&dt_ref_lock);
 
2734
        freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2730
2735
}
2731
2736
 
2732
2737
void XTDDTable::checkForeignKeys(XTThreadPtr self, bool temp_table)
2875
2880
                return false;
2876
2881
        rec_ptr = rec_buf.ib_db.db_data;
2877
2882
 
2878
 
        xt_recurrwlock_slock_ns(&dt_ref_lock);
 
2883
        xt_slock_rwlock_ns(&dt_ref_lock);
2879
2884
        tr = dt_trefs;
2880
2885
        while (tr) {
2881
2886
                if (!tr->checkReference(rec_ptr, ot->ot_thread)) {
2884
2889
                }
2885
2890
                tr = tr->tr_next;
2886
2891
        }
2887
 
        xt_recurrwlock_unslock_ns(&dt_ref_lock);
 
2892
        xt_unlock_rwlock_ns(&dt_ref_lock);
2888
2893
        xt_ib_free(NULL, &rec_buf);
2889
2894
        return ok;
2890
2895
}
2905
2910
                rec_ptr = rec_buf.ib_db.db_data;
2906
2911
                
2907
2912
        }
2908
 
        xt_recurrwlock_slock_ns(&dt_ref_lock);
 
2913
        xt_slock_rwlock_ns(&dt_ref_lock);
2909
2914
        tr = dt_trefs;
2910
2915
        while (tr) {
2911
2916
                if (!tr->modifyRow(ot, rec_ptr, NULL, ot->ot_thread)) {
2914
2919
                }
2915
2920
                tr = tr->tr_next;
2916
2921
        }
2917
 
        xt_recurrwlock_unslock_ns(&dt_ref_lock);
 
2922
        xt_unlock_rwlock_ns(&dt_ref_lock);
2918
2923
        xt_ib_free(NULL, &rec_buf);
2919
2924
        return ok;
2920
2925
}
2923
2928
{
2924
2929
        XTDDTableRef    *tr;
2925
2930
 
2926
 
        xt_recurrwlock_slock(self, &dt_ref_lock);
2927
 
        pushr_(xt_recurrwlock_unslock, &dt_ref_lock);
 
2931
        xt_slock_rwlock(self, &dt_ref_lock);
 
2932
        pushr_(xt_unlock_rwlock, &dt_ref_lock);
2928
2933
 
2929
2934
        tr = dt_trefs;
2930
2935
        while (tr) {
2932
2937
                tr = tr->tr_next;
2933
2938
        }
2934
2939
 
2935
 
        freer_(); // xt_recurrwlock_unslock(&dt_ref_lock);
 
2940
        freer_(); // xt_unlock_rwlock(&dt_ref_lock);
2936
2941
}
2937
2942
 
2938
2943
bool XTDDTable::updateRow(XTOpenTablePtr ot, xtWord1 *before, xtWord1 *after)
2962
2967
        ok = true;
2963
2968
        before_buf.ib_free = FALSE;
2964
2969
 
2965
 
        xt_recurrwlock_slock_ns(&dt_ref_lock);
 
2970
        xt_slock_rwlock_ns(&dt_ref_lock);
2966
2971
        if ((tr = dt_trefs)) {
2967
2972
                if (!before) {
2968
2973
                        if (!xt_tab_load_record(ot, ot->ot_curr_rec_id, &before_buf))
2978
2983
                        tr = tr->tr_next;
2979
2984
                }
2980
2985
        }
2981
 
        xt_recurrwlock_unslock_ns(&dt_ref_lock);
 
2986
        xt_unlock_rwlock_ns(&dt_ref_lock);
2982
2987
        
2983
2988
        xt_ib_free(NULL, &before_buf);
2984
2989
        return ok;